diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index d6e6b908..42a8e2b5 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -13,6 +13,8 @@ import '../l10n/l10n.dart'; import '../utils/beautify_string_extension.dart'; import '../utils/famedlysdk_store.dart'; import 'avatar.dart'; +import '../views/key_verification.dart'; +import '../utils/app_route.dart'; class Matrix extends StatefulWidget { static const String callNamespace = 'chat.fluffy.jitsi_call'; @@ -96,6 +98,7 @@ class MatrixState extends State { }; StreamSubscription onRoomKeyRequestSub; + StreamSubscription onKeyVerificationRequestSub; StreamSubscription onJitsiCallSub; void onJitsiCall(EventUpdate eventUpdate) { @@ -180,6 +183,22 @@ class MatrixState extends State { await request.forwardKey(); } }); + onKeyVerificationRequestSub ??= client.onKeyVerificationRequest.stream.listen((KeyVerification request) async { + if (await SimpleDialogs(context).askConfirmation( + titleText: 'New verification request from ${request.userId} and device ${request.deviceId}', + contentText: 'Start verification?', + )) { + await request.acceptVerification(); + await Navigator.of(context).push( + AppRoute.defaultRoute( + context, + KeyVerificationView(request: request), + ), + ); + } else { + await request.rejectVerification(); + } + }); _initWithStore(); } else { client = widget.client; diff --git a/lib/views/chat_encryption_settings.dart b/lib/views/chat_encryption_settings.dart index 366d4ecd..48ff0984 100644 --- a/lib/views/chat_encryption_settings.dart +++ b/lib/views/chat_encryption_settings.dart @@ -6,6 +6,8 @@ import 'package:fluffychat/utils/beautify_string_extension.dart'; import 'package:fluffychat/l10n/l10n.dart'; import 'package:fluffychat/views/chat_list.dart'; import 'package:flutter/material.dart'; +import 'key_verification.dart'; +import '../utils/app_route.dart'; class ChatEncryptionSettingsView extends StatelessWidget { final String id; @@ -109,8 +111,13 @@ class _ChatEncryptionSettingsState extends State { deviceKeys[i] .setBlocked(false, Matrix.of(context).client); } - deviceKeys[i] - .setVerified(true, Matrix.of(context).client); + final req = deviceKeys[i].startVerification(Matrix.of(context).client); + Navigator.of(context).push( + AppRoute.defaultRoute( + context, + KeyVerificationView(request: req), + ), + ); } else { if (deviceKeys[i].verified) { deviceKeys[i].setVerified( diff --git a/lib/views/homeserver_picker.dart b/lib/views/homeserver_picker.dart index 8f6dbeca..8826cc14 100644 --- a/lib/views/homeserver_picker.dart +++ b/lib/views/homeserver_picker.dart @@ -18,9 +18,9 @@ class HomeserverPicker extends StatelessWidget { } void _checkHomeserverAction(String homeserver, BuildContext context) async { - if (!homeserver.startsWith('https://')) { - homeserver = 'https://$homeserver'; - } +// if (!homeserver.startsWith('https://')) { +// homeserver = 'https://$homeserver'; +// } final success = await SimpleDialogs(context).tryRequestWithLoadingDialog( Matrix.of(context).client.checkServer(homeserver)); if (success != false) { diff --git a/lib/views/key_verification.dart b/lib/views/key_verification.dart new file mode 100644 index 00000000..93b25c65 --- /dev/null +++ b/lib/views/key_verification.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:famedlysdk/famedlysdk.dart'; +import 'chat_list.dart'; +import '../components/adaptive_page_layout.dart'; + +class KeyVerificationView extends StatelessWidget { + final KeyVerification request; + + KeyVerificationView({this.request}); + + @override + Widget build(BuildContext context) { + return AdaptivePageLayout( + primaryPage: FocusPage.SECOND, + firstScaffold: ChatList(), + secondScaffold: KeyVerificationPage(request: request), + ); + } +} + +class KeyVerificationPage extends StatefulWidget { + final KeyVerification request; + + KeyVerificationPage({this.request}); + + @override + _KeyVerificationPageState createState() => _KeyVerificationPageState(); +} + +class _KeyVerificationPageState extends State { + @override + void initState() { + widget.request.onUpdate = () => setState(() => null); + super.initState(); + } + + @override + Widget build(BuildContext context) { + switch (widget.request.state) { + case KeyVerificationState.askAccept: + return Text('Accept this request? (you should never see this)'); + case KeyVerificationState.waitingAccept: + return Text('Waiting for partner to accept the request...'); + case KeyVerificationState.askSas: + final emojis = widget.request.sasEmojis; + final emojiWidgets = emojis.map((e) => Text(e.emoji, style: TextStyle(fontSize: 20))).toList(); + return Column( + children: [ + Row( + children: emojiWidgets, + ), + FlatButton( + child: Text('Match'), + onPressed: () => widget.request.acceptSas(), + ), + FlatButton( + child: Text('Reject'), + onPressed: () => widget.request.rejectSas(), + ) + ], + ); + case KeyVerificationState.waitingSas: + return Text('Waiting for partner to accept the emoji...'); + case KeyVerificationState.done: + return Text('Verification done!'); + case KeyVerificationState.error: + return Text('Error ${widget.request.canceledCode}: ${widget.request.canceledReason}'); + } + return Text('Unknown state'); + } +} diff --git a/pubspec.lock b/pubspec.lock index 253b3557..a12355d2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -71,13 +71,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.3" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" collection: dependency: transitive description: @@ -136,21 +129,12 @@ packages: url: "https://github.com/simolus3/moor.git" source: git version: "1.0.0" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" famedlysdk: dependency: "direct main" description: - path: "." - ref: bb690a22daab54a53a8df8e2dffb87da8a374bb1 - resolved-ref: bb690a22daab54a53a8df8e2dffb87da8a374bb1 - url: "https://gitlab.com/famedly/famedlysdk.git" - source: git + path: "/home/sorunome/repos/famedly/famedlysdk" + relative: false + source: path version: "0.0.1" ffi: dependency: transitive @@ -399,11 +383,9 @@ packages: matrix_file_e2ee: dependency: transitive description: - path: "." - ref: "1.x.y" - resolved-ref: "32edeff765369a7a77a0822f4b19302ca24a017b" - url: "https://gitlab.com/famedly/libraries/matrix_file_e2ee.git" - source: git + path: "/home/sorunome/repos/famedly/matrix_file_e2ee" + relative: false + source: path version: "1.0.3" meta: dependency: transitive @@ -465,8 +447,8 @@ packages: dependency: transitive description: path: "." - ref: "1.x.y" - resolved-ref: "79868b06b3ea156f90b73abafb3bbf3ac4114cc6" + ref: "2ef8828859e0c4f6064038e45d89be3e46f8013c" + resolved-ref: "2ef8828859e0c4f6064038e45d89be3e46f8013c" url: "https://gitlab.com/famedly/libraries/dart-olm.git" source: git version: "1.0.0" @@ -497,7 +479,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.6.4" path_drawing: dependency: transitive description: @@ -575,6 +557,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.2" + quiver: + dependency: transitive + description: + name: quiver + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" random_string: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 4fc397a4..bf47ce3d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,9 +25,10 @@ dependencies: cupertino_icons: ^0.1.2 famedlysdk: - git: - url: https://gitlab.com/famedly/famedlysdk.git - ref: bb690a22daab54a53a8df8e2dffb87da8a374bb1 + path: /home/sorunome/repos/famedly/famedlysdk +# git: +# url: https://gitlab.com/famedly/famedlysdk.git +# ref: bb690a22daab54a53a8df8e2dffb87da8a374bb1 localstorage: ^3.0.1+4 bubble: ^1.1.9+1