Skip to content

Commit

Permalink
feat: bootstrapping from nebuchadnezzar of other devices (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Jan 10, 2025
1 parent f492929 commit 502a5e5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/snap.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Snap

on:
push: {}
pull_request: {}
workflow_dispatch: {}
push:
branches: [main]
workflow_dispatch:

jobs:
build:
Expand Down
12 changes: 8 additions & 4 deletions lib/chat/bootstrap/view/key_verification_dialog.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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
Expand Down Expand Up @@ -95,7 +99,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final theme = context.theme;
final l10n = context.l10n;

User? user;
Expand Down Expand Up @@ -321,7 +325,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
l10n.close,
),
onPressed: () {
Navigator.of(context, rootNavigator: false).pop();
widget.onDone?.call();
if (context.mounted) {
Navigator.of(
context,
Expand Down
3 changes: 3 additions & 0 deletions lib/chat/chat_model.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<KeyVerification> get onKeyVerificationRequest =>
_client.onKeyVerificationRequest.stream;

// Room management
/// The list of all rooms the user is participating or invited.
Expand Down
27 changes: 17 additions & 10 deletions lib/chat/remote_image_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions lib/chat/view/chat_master/chat_master_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -49,6 +50,19 @@ class _ChatMasterDetailPageState extends State<ChatMasterDetailPage> {

@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);
Expand Down

0 comments on commit 502a5e5

Please sign in to comment.