@@ -7,134 +7,30 @@ import '../../authentication/view/chat_login_page.dart';
77import '../../authentication/view/uia_request_handler.dart' ;
88import '../../chat_room/common/view/chat_no_selected_room_page.dart' ;
99import '../../chat_room/common/view/chat_room_page.dart' ;
10- import '../../chat_room/create_or_edit/edit_room_manager.dart' ;
1110import '../../common/chat_manager.dart' ;
1211import '../../common/platforms.dart' ;
1312import '../../common/view/build_context_x.dart' ;
1413import '../../common/view/ui_constants.dart' ;
1514import '../../encryption/encryption_manager.dart' ;
1615import '../../encryption/view/key_verification_dialog.dart' ;
17- import '../../l10n/l10n.dart' ;
1816import '../../notification/chat_notification_handler.dart' ;
1917import '../../player/view/player_view.dart' ;
20- import 'chat_clear_archive_progress_bar .dart' ;
18+ import 'chat_edit_room_mixin .dart' ;
2119import 'chat_master_panel.dart' ;
2220
2321final GlobalKey <ScaffoldState > masterScaffoldKey = GlobalKey ();
2422
25- class ChatMasterDetailPage extends StatelessWidget with WatchItMixin {
23+ class ChatMasterDetailPage extends StatelessWidget
24+ with WatchItMixin , ChatEditRoomMixin {
2625 const ChatMasterDetailPage ({super .key});
2726
2827 @override
2928 Widget build (BuildContext context) {
30- registerHandler (
31- select: (EditRoomManager m) => m.forgetAllRoomsCommand.results,
32- handler: (context, newValue, cancel) {
33- if (newValue.isRunning) {
34- ScaffoldMessenger .of (context)
35- ..clearSnackBars ()
36- ..showSnackBar (
37- const SnackBar (
38- duration: Duration (seconds: 3000 ),
39- content: ChatClearArchiveProgressBar (),
40- ),
41- );
42- } else if (newValue.hasData) {
43- ScaffoldMessenger .of (context)
44- ..clearSnackBars ()
45- ..showSnackBar (const SnackBar (content: Text ('Deleted all rooms' )));
46- } else if (newValue.hasError) {
47- ScaffoldMessenger .of (context)
48- ..clearSnackBars ()
49- ..showSnackBar (
50- SnackBar (
51- content: Text (
52- '${context .l10n .oopsSomethingWentWrong }: ${newValue .error }' ,
53- ),
54- ),
55- );
56- } else {
57- _commandDoneCleanupSnackbars (context);
58- }
59- },
60- );
29+ registerGlobalLeaveCommand ();
6130
62- registerHandler (
63- select: (EditRoomManager m) => m.globalLeaveRoomCommand.results,
64- handler: (context, newValue, cancel) {
65- if (newValue.isRunning) {
66- _showInifniteSpinnerSnackbar (
67- context,
68- '${context .l10n .leave } ${newValue .data ?.getLocalizedDisplayname () ?? '' }' ,
69- );
70- } else if (newValue.hasData && newValue.data != null ) {
71- ScaffoldMessenger .of (context)
72- ..clearSnackBars ()
73- ..showSnackBar (
74- SnackBar (
75- duration: const Duration (seconds: 5 ),
76- content: Text (
77- 'Left: ${newValue .data ?.getLocalizedDisplayname () ?? '' }' ,
78- ),
79- action: SnackBarAction (
80- label: context.l10n.delete,
81- onPressed: () {
82- di <EditRoomManager >().globalForgetRoomCommand.run (
83- newValue.data! ,
84- );
85- },
86- ),
87- ),
88- );
89- } else if (newValue.hasError) {
90- ScaffoldMessenger .of (context)
91- ..clearSnackBars ()
92- ..showSnackBar (
93- SnackBar (
94- content: Text (
95- '${context .l10n .oopsSomethingWentWrong } ${newValue .data ?.getLocalizedDisplayname () ?? '' }: ${newValue .error }' ,
96- ),
97- ),
98- );
99- } else {
100- _commandDoneCleanupSnackbars (context);
101- }
102- },
103- );
31+ registerGlobalForgetRoomCommand ();
10432
105- registerHandler (
106- select: (EditRoomManager m) => m.globalForgetRoomCommand.results,
107- handler: (context, newValue, cancel) {
108- if (newValue.isRunning) {
109- _showInifniteSpinnerSnackbar (
110- context,
111- '${context .l10n .delete } ${newValue .data ?.getLocalizedDisplayname () ?? '' }' ,
112- );
113- } else if (newValue.hasData && newValue.data != null ) {
114- ScaffoldMessenger .of (context)
115- ..clearSnackBars ()
116- ..showSnackBar (
117- SnackBar (
118- content: Text (
119- 'Deleted: ${newValue .data ?.getLocalizedDisplayname () ?? '' }' ,
120- ),
121- ),
122- );
123- } else if (newValue.hasError) {
124- ScaffoldMessenger .of (context)
125- ..clearSnackBars ()
126- ..showSnackBar (
127- SnackBar (
128- content: Text (
129- '${context .l10n .oopsSomethingWentWrong } ${newValue .data ?.getLocalizedDisplayname () ?? '' }: ${newValue .error }' ,
130- ),
131- ),
132- );
133- } else {
134- _commandDoneCleanupSnackbars (context);
135- }
136- },
137- );
33+ registerForgetAllRoomsCommand ();
13834
13935 registerStreamHandler (
14036 select: (EncryptionManager m) => m.onKeyVerificationRequest,
@@ -178,12 +74,6 @@ class ChatMasterDetailPage extends StatelessWidget with WatchItMixin {
17874 handler: chatNotificationHandler,
17975 );
18076
181- // TODO: #6
182- // registerStreamHandler(
183- // select: (Client m) => m.onCallEvents.stream,
184- // handler: callHandler,
185- // );
186-
18777 final selectedRoom = watchPropertyValue ((ChatManager m) => m.selectedRoom);
18878 final isArchivedRoom = watchPropertyValue (
18979 (ChatManager m) => m.selectedRoom? .isArchived == true ,
@@ -218,31 +108,4 @@ class ChatMasterDetailPage extends StatelessWidget with WatchItMixin {
218108 bottomNavigationBar: const PlayerView (),
219109 );
220110 }
221-
222- void _showInifniteSpinnerSnackbar (BuildContext context, String text) {
223- ScaffoldMessenger .of (context).showSnackBar (
224- SnackBar (
225- duration: const Duration (seconds: 5 ),
226- content: Row (
227- children: [
228- const SizedBox (
229- width: 20 ,
230- height: 20 ,
231- child: CircularProgressIndicator (strokeWidth: 2 ),
232- ),
233- const SizedBox (width: 16 ),
234- Text (text),
235- ],
236- ),
237- ),
238- );
239- }
240-
241- void _commandDoneCleanupSnackbars (BuildContext context) {
242- Future .delayed (const Duration (seconds: 2 ), () {
243- if (context.mounted) {
244- ScaffoldMessenger .of (context).clearSnackBars ();
245- }
246- });
247- }
248111}
0 commit comments