Skip to content

Commit 502a5e5

Browse files
authored
feat: bootstrapping from nebuchadnezzar of other devices (#13)
1 parent f492929 commit 502a5e5

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

.github/workflows/snap.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Snap
22

33
on:
4-
push: {}
5-
pull_request: {}
6-
workflow_dispatch: {}
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
77

88
jobs:
99
build:

lib/chat/bootstrap/view/key_verification_dialog.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import 'dart:convert';
22
import 'dart:ui';
33

4+
import 'package:adaptive_dialog/adaptive_dialog.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter/services.dart';
6-
7-
import 'package:adaptive_dialog/adaptive_dialog.dart';
87
import 'package:future_loading_dialog/future_loading_dialog.dart';
98
import 'package:matrix/encryption.dart';
109
import 'package:matrix/matrix.dart';
1110

11+
import '../../../common/view/build_context_x.dart';
1212
import '../../../l10n/l10n.dart';
1313
import '../../view/chat_avatar.dart';
1414

@@ -21,10 +21,14 @@ class KeyVerificationDialog extends StatefulWidget {
2121
);
2222

2323
final KeyVerification request;
24+
final Function()? onCancel;
25+
final Function()? onDone;
2426

2527
const KeyVerificationDialog({
2628
super.key,
2729
required this.request,
30+
this.onCancel,
31+
this.onDone,
2832
});
2933

3034
@override
@@ -95,7 +99,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
9599

96100
@override
97101
Widget build(BuildContext context) {
98-
final theme = Theme.of(context);
102+
final theme = context.theme;
99103
final l10n = context.l10n;
100104

101105
User? user;
@@ -321,7 +325,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
321325
l10n.close,
322326
),
323327
onPressed: () {
324-
Navigator.of(context, rootNavigator: false).pop();
328+
widget.onDone?.call();
325329
if (context.mounted) {
326330
Navigator.of(
327331
context,

lib/chat/chat_model.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:collection/collection.dart';
2+
import 'package:matrix/encryption/utils/key_verification.dart';
23
import 'package:matrix/matrix.dart';
34
import 'package:safe_change_notifier/safe_change_notifier.dart';
45

@@ -17,6 +18,8 @@ class ChatModel extends SafeChangeNotifier {
1718
bool isUserEvent(Event event) => myUserId == event.senderId;
1819
bool get isLogged => _client.isLogged();
1920
bool get encryptionEnabled => _client.encryptionEnabled;
21+
Stream<KeyVerification> get onKeyVerificationRequest =>
22+
_client.onKeyVerificationRequest.stream;
2023

2124
// Room management
2225
/// The list of all rooms the user is participating or invited.

lib/chat/remote_image_service.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import 'dart:async';
22

33
import 'package:matrix/matrix.dart';
44

5+
import '../common/logging.dart';
6+
57
class RemoteImageService {
68
RemoteImageService({required Client client}) : _client = client;
79
final Client _client;
@@ -19,16 +21,21 @@ class RemoteImageService {
1921
ThumbnailMethod? method = ThumbnailMethod.scale,
2022
bool? animated = false,
2123
}) async {
22-
final albumArtUrl = put(
23-
key: uri,
24-
url: await uri.getThumbnailUri(
25-
_client,
26-
animated: animated,
27-
height: height,
28-
width: width,
29-
method: method,
30-
),
31-
);
24+
Uri? albumArtUrl;
25+
try {
26+
albumArtUrl = put(
27+
key: uri,
28+
url: await uri.getThumbnailUri(
29+
_client,
30+
animated: animated,
31+
height: height,
32+
width: width,
33+
method: method,
34+
),
35+
);
36+
} on Exception catch (_) {
37+
printMessageInDebugMode('Could not find profile (anymore)');
38+
}
3239
_propertiesChangedController.add(true);
3340

3441
return albumArtUrl;

lib/chat/view/chat_master/chat_master_detail_page.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../../../common/view/common_widgets.dart';
88
import '../../../common/view/ui_constants.dart';
99
import '../../bootstrap/bootstrap_model.dart';
1010
import '../../bootstrap/view/bootstrap_page.dart';
11+
import '../../bootstrap/view/key_verification_dialog.dart';
1112
import '../../chat_model.dart';
1213
import '../chat_room/chat_room_page.dart';
1314
import '../no_selected_room_page.dart';
@@ -49,6 +50,19 @@ class _ChatMasterDetailPageState extends State<ChatMasterDetailPage> {
4950

5051
@override
5152
Widget build(BuildContext context) {
53+
registerStreamHandler(
54+
select: (ChatModel m) => m.onKeyVerificationRequest,
55+
handler: (context, newValue, cancel) {
56+
if (newValue.hasData) {
57+
showDialog(
58+
context: context,
59+
builder: (context) =>
60+
KeyVerificationDialog(request: newValue.data!),
61+
);
62+
}
63+
},
64+
);
65+
5266
final selectedRoom = watchPropertyValue((ChatModel m) => m.selectedRoom);
5367
final isArchivedRoom =
5468
watchPropertyValue((ChatModel m) => m.selectedRoom?.isArchived == true);

0 commit comments

Comments
 (0)