Skip to content

Commit 74e52b8

Browse files
committed
feat: implement room and avatar management commands and UI enhancements (#135)
1 parent 4cfc58a commit 74e52b8

17 files changed

Lines changed: 504 additions & 340 deletions
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_it/flutter_it.dart';
3+
4+
import '../../chat_room/create_or_edit/edit_room_manager.dart';
5+
import '../../l10n/l10n.dart';
6+
import 'chat_clear_archive_progress_bar.dart';
7+
8+
mixin ChatEditRoomMixin {
9+
void registerGlobalLeaveCommand() {
10+
registerHandler(
11+
select: (EditRoomManager m) => m.globalLeaveRoomCommand.results,
12+
handler: (context, newValue, cancel) {
13+
if (newValue.isRunning) {
14+
_showIndeterminateSpinnerSnackbar(
15+
context,
16+
'${context.l10n.leave} ${newValue.paramData?.getLocalizedDisplayname() ?? ''}',
17+
);
18+
} else if (newValue.hasError) {
19+
_showErrorSnackbar(
20+
context,
21+
'${context.l10n.oopsSomethingWentWrong} ${newValue.paramData?.getLocalizedDisplayname() ?? ''}: ${newValue.error}',
22+
);
23+
} else if (newValue.hasData && newValue.data != null) {
24+
ScaffoldMessenger.of(context)
25+
..clearSnackBars()
26+
..showSnackBar(
27+
SnackBar(
28+
duration: const Duration(seconds: 3),
29+
content: Text(
30+
'Left: ${newValue.data?.getLocalizedDisplayname() ?? ''}',
31+
),
32+
action: SnackBarAction(
33+
label: context.l10n.delete,
34+
onPressed: () => di<EditRoomManager>().globalForgetRoomCommand
35+
.run(newValue.data),
36+
),
37+
),
38+
);
39+
}
40+
},
41+
);
42+
}
43+
44+
void registerGlobalForgetRoomCommand() {
45+
registerHandler(
46+
select: (EditRoomManager m) => m.globalForgetRoomCommand.results,
47+
handler: (context, newValue, cancel) {
48+
if (newValue.isRunning) {
49+
_showIndeterminateSpinnerSnackbar(
50+
context,
51+
'Deleting room ${newValue.paramData?.getLocalizedDisplayname() ?? ''}',
52+
);
53+
} else if (newValue.hasError) {
54+
_showErrorSnackbar(
55+
context,
56+
'${context.l10n.oopsSomethingWentWrong} ${newValue.paramData?.getLocalizedDisplayname() ?? ''}: ${newValue.error}',
57+
);
58+
} else if (newValue.hasData && newValue.data != null) {
59+
ScaffoldMessenger.of(context)
60+
..clearSnackBars()
61+
..showSnackBar(
62+
SnackBar(
63+
duration: const Duration(seconds: 3),
64+
content: Text(
65+
'Deleted: ${newValue.data?.getLocalizedDisplayname() ?? ''}',
66+
),
67+
),
68+
);
69+
}
70+
},
71+
);
72+
}
73+
74+
void registerForgetAllRoomsCommand() {
75+
registerHandler(
76+
select: (EditRoomManager m) => m.forgetAllRoomsCommand.results,
77+
handler: (context, newValue, cancel) {
78+
if (newValue.isRunning) {
79+
ScaffoldMessenger.of(context)
80+
..clearSnackBars()
81+
..showSnackBar(
82+
const SnackBar(
83+
duration: Duration(seconds: 3000),
84+
content: ChatClearArchiveProgressBar(),
85+
),
86+
);
87+
} else if (newValue.hasError) {
88+
_showErrorSnackbar(
89+
context,
90+
'${context.l10n.oopsSomethingWentWrong}: ${newValue.error}',
91+
);
92+
} else if (newValue.hasData) {
93+
ScaffoldMessenger.of(context)
94+
..clearSnackBars()
95+
..showSnackBar(
96+
const SnackBar(
97+
duration: Duration(seconds: 3),
98+
content: Text('Deleted all archived rooms'),
99+
),
100+
);
101+
}
102+
},
103+
);
104+
}
105+
106+
void _showIndeterminateSpinnerSnackbar(BuildContext context, String text) {
107+
ScaffoldMessenger.of(context)
108+
..clearSnackBars()
109+
..showSnackBar(
110+
SnackBar(
111+
duration: const Duration(seconds: 100),
112+
content: Row(
113+
children: [
114+
const SizedBox(
115+
width: 20,
116+
height: 20,
117+
child: CircularProgressIndicator(strokeWidth: 2),
118+
),
119+
const SizedBox(width: 16),
120+
Text(text),
121+
],
122+
),
123+
),
124+
);
125+
}
126+
127+
void _showErrorSnackbar(BuildContext context, String message) {
128+
ScaffoldMessenger.of(context)
129+
..clearSnackBars()
130+
..showSnackBar(SnackBar(content: Text(message)));
131+
}
132+
}

lib/chat_master/view/chat_master_detail_page.dart

Lines changed: 6 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -7,134 +7,30 @@ import '../../authentication/view/chat_login_page.dart';
77
import '../../authentication/view/uia_request_handler.dart';
88
import '../../chat_room/common/view/chat_no_selected_room_page.dart';
99
import '../../chat_room/common/view/chat_room_page.dart';
10-
import '../../chat_room/create_or_edit/edit_room_manager.dart';
1110
import '../../common/chat_manager.dart';
1211
import '../../common/platforms.dart';
1312
import '../../common/view/build_context_x.dart';
1413
import '../../common/view/ui_constants.dart';
1514
import '../../encryption/encryption_manager.dart';
1615
import '../../encryption/view/key_verification_dialog.dart';
17-
import '../../l10n/l10n.dart';
1816
import '../../notification/chat_notification_handler.dart';
1917
import '../../player/view/player_view.dart';
20-
import 'chat_clear_archive_progress_bar.dart';
18+
import 'chat_edit_room_mixin.dart';
2119
import 'chat_master_panel.dart';
2220

2321
final 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
}

lib/chat_master/view/chat_master_new_chat_popup_menu_button.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ChatMasterNewChatPopupMenuButton extends StatelessWidget {
3232
PopupMenuItem(
3333
onTap: () => showDialog(
3434
context: context,
35+
barrierDismissible: false,
3536
builder: (context) => const CreateOrEditRoomDialog(),
3637
),
3738
child: Row(
@@ -42,6 +43,7 @@ class ChatMasterNewChatPopupMenuButton extends StatelessWidget {
4243
PopupMenuItem(
4344
onTap: () => showDialog(
4445
context: context,
46+
barrierDismissible: false,
4547
builder: (context) => const CreateOrEditRoomDialog(space: true),
4648
),
4749
child: Row(

0 commit comments

Comments
 (0)