From 4b45988a9d95a51614274a08b823fd0fdab44be3 Mon Sep 17 00:00:00 2001 From: Feichtmeier Date: Fri, 10 Jan 2025 23:33:59 +0100 Subject: [PATCH] feat: bootstrapping from nebuchadnezzar of other devices Ref #3 --- .../view/key_verification_dialog.dart | 12 ++++++--- lib/chat/chat_model.dart | 3 +++ lib/chat/remote_image_service.dart | 27 ++++++++++++------- .../chat_master/chat_master_detail_page.dart | 14 ++++++++++ 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/lib/chat/bootstrap/view/key_verification_dialog.dart b/lib/chat/bootstrap/view/key_verification_dialog.dart index d94670b..2681e81 100644 --- a/lib/chat/bootstrap/view/key_verification_dialog.dart +++ b/lib/chat/bootstrap/view/key_verification_dialog.dart @@ -1,14 +1,14 @@ import 'dart:convert'; import 'dart:ui'; +import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; - -import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:matrix/encryption.dart'; import 'package:matrix/matrix.dart'; +import '../../../common/view/build_context_x.dart'; import '../../../l10n/l10n.dart'; import '../../view/chat_avatar.dart'; @@ -21,10 +21,14 @@ class KeyVerificationDialog extends StatefulWidget { ); final KeyVerification request; + final Function()? onCancel; + final Function()? onDone; const KeyVerificationDialog({ super.key, required this.request, + this.onCancel, + this.onDone, }); @override @@ -95,7 +99,7 @@ class KeyVerificationPageState extends State { @override Widget build(BuildContext context) { - final theme = Theme.of(context); + final theme = context.theme; final l10n = context.l10n; User? user; @@ -321,7 +325,7 @@ class KeyVerificationPageState extends State { l10n.close, ), onPressed: () { - Navigator.of(context, rootNavigator: false).pop(); + widget.onDone?.call(); if (context.mounted) { Navigator.of( context, diff --git a/lib/chat/chat_model.dart b/lib/chat/chat_model.dart index 484df74..75e7c92 100644 --- a/lib/chat/chat_model.dart +++ b/lib/chat/chat_model.dart @@ -1,4 +1,5 @@ import 'package:collection/collection.dart'; +import 'package:matrix/encryption/utils/key_verification.dart'; import 'package:matrix/matrix.dart'; import 'package:safe_change_notifier/safe_change_notifier.dart'; @@ -17,6 +18,8 @@ class ChatModel extends SafeChangeNotifier { bool isUserEvent(Event event) => myUserId == event.senderId; bool get isLogged => _client.isLogged(); bool get encryptionEnabled => _client.encryptionEnabled; + Stream get onKeyVerificationRequest => + _client.onKeyVerificationRequest.stream; // Room management /// The list of all rooms the user is participating or invited. diff --git a/lib/chat/remote_image_service.dart b/lib/chat/remote_image_service.dart index a17dd10..fae2987 100644 --- a/lib/chat/remote_image_service.dart +++ b/lib/chat/remote_image_service.dart @@ -2,6 +2,8 @@ import 'dart:async'; import 'package:matrix/matrix.dart'; +import '../common/logging.dart'; + class RemoteImageService { RemoteImageService({required Client client}) : _client = client; final Client _client; @@ -19,16 +21,21 @@ class RemoteImageService { ThumbnailMethod? method = ThumbnailMethod.scale, bool? animated = false, }) async { - final albumArtUrl = put( - key: uri, - url: await uri.getThumbnailUri( - _client, - animated: animated, - height: height, - width: width, - method: method, - ), - ); + Uri? albumArtUrl; + try { + albumArtUrl = put( + key: uri, + url: await uri.getThumbnailUri( + _client, + animated: animated, + height: height, + width: width, + method: method, + ), + ); + } on Exception catch (_) { + printMessageInDebugMode('Could not find profile (anymore)'); + } _propertiesChangedController.add(true); return albumArtUrl; diff --git a/lib/chat/view/chat_master/chat_master_detail_page.dart b/lib/chat/view/chat_master/chat_master_detail_page.dart index f766e81..21bad7e 100644 --- a/lib/chat/view/chat_master/chat_master_detail_page.dart +++ b/lib/chat/view/chat_master/chat_master_detail_page.dart @@ -8,6 +8,7 @@ import '../../../common/view/common_widgets.dart'; import '../../../common/view/ui_constants.dart'; import '../../bootstrap/bootstrap_model.dart'; import '../../bootstrap/view/bootstrap_page.dart'; +import '../../bootstrap/view/key_verification_dialog.dart'; import '../../chat_model.dart'; import '../chat_room/chat_room_page.dart'; import '../no_selected_room_page.dart'; @@ -49,6 +50,19 @@ class _ChatMasterDetailPageState extends State { @override Widget build(BuildContext context) { + registerStreamHandler( + select: (ChatModel m) => m.onKeyVerificationRequest, + handler: (context, newValue, cancel) { + if (newValue.hasData) { + showDialog( + context: context, + builder: (context) => + KeyVerificationDialog(request: newValue.data!), + ); + } + }, + ); + final selectedRoom = watchPropertyValue((ChatModel m) => m.selectedRoom); final isArchivedRoom = watchPropertyValue((ChatModel m) => m.selectedRoom?.isArchived == true);