Skip to content

Commit d0b1b0a

Browse files
authored
chore: extract last event (#80)
1 parent 40e8341 commit d0b1b0a

File tree

5 files changed

+65
-53
lines changed

5 files changed

+65
-53
lines changed

lib/chat_master/view/chat_master_detail_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class _ChatMasterDetailPageState extends State<ChatMasterDetailPage> {
5151

5252
registerStreamHandler(
5353
select: (AuthenticationModel m) => m.onUiaRequestStream,
54-
handler: (context, newValue, cancel) {
54+
handler: (context, newValue, cancel) async {
5555
if (newValue.hasData) {
56-
uiaRequestHandler(
56+
await uiaRequestHandler(
5757
uiaRequest: newValue.data!,
5858
context: context,
5959
rootNavigator: true,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:matrix/matrix.dart';
3+
4+
import '../../common/event_x.dart';
5+
import '../../l10n/l10n.dart';
6+
7+
class ChatRoomLastEvent extends StatelessWidget {
8+
const ChatRoomLastEvent({required this.lastEvent, super.key});
9+
10+
final Event? lastEvent;
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
return FutureBuilder<String>(
15+
key: ValueKey(
16+
'${lastEvent?.eventId}_${lastEvent?.type}_${lastEvent?.redacted}}',
17+
),
18+
future: lastEvent?.calcLocalizedBody(
19+
const MatrixDefaultLocalizations(),
20+
hideReply: true,
21+
plaintextBody: true,
22+
withSenderNamePrefix: true,
23+
),
24+
initialData: lastEvent?.calcLocalizedBodyFallback(
25+
const MatrixDefaultLocalizations(),
26+
hideReply: true,
27+
plaintextBody: true,
28+
withSenderNamePrefix: true,
29+
),
30+
builder: (context, snapshot) {
31+
if (snapshot.hasError) {
32+
return const Text('?', maxLines: 1);
33+
}
34+
if (lastEvent != null) {
35+
if (lastEvent!.hideInTimeline(
36+
showAvatarChanges: false,
37+
showDisplayNameChanges: false,
38+
)) {
39+
return const Text('...', maxLines: 1);
40+
}
41+
if (snapshot.hasData) {
42+
return Text(snapshot.data!, maxLines: 1);
43+
}
44+
}
45+
46+
return Text(context.l10n.emptyChat, maxLines: 1);
47+
},
48+
);
49+
}
50+
}

lib/chat_master/view/chat_room_master_tile_subtitle.dart

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import 'package:matrix/matrix.dart';
33
import 'package:watch_it/watch_it.dart';
44

55
import '../../common/chat_model.dart';
6-
import '../../common/event_x.dart';
76
import '../../common/view/build_context_x.dart';
87
import '../../l10n/l10n.dart';
8+
import 'chat_room_last_event.dart';
99

1010
class ChatRoomMasterTileSubTitle extends StatelessWidget with WatchItMixin {
1111
const ChatRoomMasterTileSubTitle({super.key, required this.room});
@@ -41,46 +41,3 @@ class ChatRoomMasterTileSubTitle extends StatelessWidget with WatchItMixin {
4141
);
4242
}
4343
}
44-
45-
class ChatRoomLastEvent extends StatelessWidget {
46-
const ChatRoomLastEvent({required this.lastEvent, super.key});
47-
48-
final Event? lastEvent;
49-
50-
@override
51-
Widget build(BuildContext context) {
52-
return FutureBuilder<String>(
53-
key: ValueKey(
54-
'${lastEvent?.eventId}_${lastEvent?.type}_${lastEvent?.redacted}}',
55-
),
56-
future: lastEvent?.calcLocalizedBody(
57-
const MatrixDefaultLocalizations(),
58-
hideReply: true,
59-
plaintextBody: true,
60-
withSenderNamePrefix: true,
61-
),
62-
initialData: lastEvent?.calcLocalizedBodyFallback(
63-
const MatrixDefaultLocalizations(),
64-
hideReply: true,
65-
plaintextBody: true,
66-
withSenderNamePrefix: true,
67-
),
68-
builder: (context, snapshot) {
69-
if (snapshot.hasError) {
70-
return const Text('?', maxLines: 1);
71-
}
72-
if (lastEvent!.hideInTimeline(
73-
showAvatarChanges: false,
74-
showDisplayNameChanges: false,
75-
)) {
76-
return const Text('...', maxLines: 1);
77-
}
78-
if (snapshot.hasData && lastEvent != null) {
79-
return Text(snapshot.data!, maxLines: 1);
80-
}
81-
82-
return Text(context.l10n.emptyChat, maxLines: 1);
83-
},
84-
);
85-
}
86-
}

lib/encryption/view/key_verification_dialog.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,14 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
335335
child: Text(l10n.close),
336336
onPressed: () {
337337
Navigator.of(context, rootNavigator: false).pop();
338-
Navigator.of(context).pushAndRemoveUntil(
339-
MaterialPageRoute(
340-
builder: (_) => const CheckEncryptionSetupPage(),
341-
),
342-
(route) => false,
343-
);
338+
if (!widget.verifyOther) {
339+
Navigator.of(context).pushAndRemoveUntil(
340+
MaterialPageRoute(
341+
builder: (_) => const CheckEncryptionSetupPage(),
342+
),
343+
(route) => false,
344+
);
345+
}
344346
},
345347
),
346348
);

lib/settings/settings_model.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ class SettingsModel extends SafeChangeNotifier {
125125
}
126126
};
127127
if (!context.mounted) return;
128-
await KeyVerificationDialog(request: keyVerification).show(context);
128+
await KeyVerificationDialog(
129+
request: keyVerification,
130+
verifyOther: true,
131+
).show(context);
129132
}
130133

131134
bool _attachingAvatar = false;

0 commit comments

Comments
 (0)