11import 'package:flutter/material.dart' ;
2+ import 'package:future_loading_dialog/future_loading_dialog.dart' ;
23import 'package:matrix/matrix.dart' ;
4+ import 'package:watch_it/watch_it.dart' ;
5+ import 'package:yaru/yaru.dart' ;
36
4- import '../../chat_room/titlebar/chat_room_pin_button.dart' ;
7+ import '../../chat_room/create_or_edit/create_or_edit_room_model.dart' ;
8+ import '../../chat_room/info_drawer/chat_room_join_or_leave_button.dart' ;
9+ import '../../chat_room/titlebar/chat_room_notification_button.dart' ;
10+ import '../../common/chat_model.dart' ;
11+ import '../../common/view/build_context_x.dart' ;
12+ import '../../common/view/confirm.dart' ;
13+ import '../../common/view/snackbars.dart' ;
14+ import '../../l10n/l10n.dart' ;
515
616class ChatMasterTileMenu extends StatefulWidget {
717 const ChatMasterTileMenu ({
818 super .key,
9- required this .child,
1019 required this .room,
20+ required this .child,
1121 });
1222
13- final Widget child;
1423 final Room room;
24+ final Widget child;
1525
1626 @override
1727 State <ChatMasterTileMenu > createState () => _ChatMasterTileMenuState ();
@@ -22,14 +32,64 @@ class _ChatMasterTileMenuState extends State<ChatMasterTileMenu> {
2232
2333 @override
2434 Widget build (BuildContext context) {
35+ void onTap () =>
36+ _controller.isOpen ? _controller.close () : _controller.open ();
2537 return GestureDetector (
26- onSecondaryTap: () =>
27- _controller.isOpen ? _controller.close () : _controller.open (),
38+ onSecondaryTap: onTap,
39+ onLongPress: onTap,
40+
2841 child: MenuAnchor (
29- alignmentOffset: const Offset (20 , - 80 ),
3042 controller: _controller,
31- consumeOutsideTap: true ,
32- menuChildren: [ChatRoomPinButton .menuEntry (room: widget.room)],
43+ alignmentOffset: const Offset (100 , - 10 ),
44+ menuChildren: [
45+ MenuItemButton (
46+ onPressed: () => showFutureLoadingDialog (
47+ context: context,
48+ future: () =>
49+ di <CreateOrEditRoomModel >().toggleFavorite (widget.room),
50+ ),
51+ leadingIcon: const Icon (YaruIcons .pin),
52+ child: Text (
53+ context.l10n.toggleFavorite,
54+ style: context.textTheme.bodyMedium,
55+ ),
56+ ),
57+ MenuItemButton (
58+ onPressed: () => showDialog (
59+ context: context,
60+ builder: (_) => ChatRoomNotificationsDialog (room: widget.room),
61+ ),
62+ leadingIcon: const Icon (YaruIcons .notification),
63+ child: Text (
64+ context.l10n.notifications,
65+ style: context.textTheme.bodyMedium,
66+ ),
67+ ),
68+ MenuItemButton (
69+ onPressed: () => ConfirmationDialog .show (
70+ context: context,
71+ title: Text (
72+ '${context .l10n .leave } ${widget .room .getLocalizedDisplayname ()}' ,
73+ ),
74+ content: const ForgetCheckBox (),
75+ onConfirm: () async {
76+ void onFail (error) =>
77+ showSnackBar (context, content: Text (error));
78+ await di <ChatModel >().leaveRoom (
79+ room: widget.room,
80+ onFail: onFail,
81+ forget: di <ChatModel >().forget,
82+ );
83+ },
84+ ),
85+ leadingIcon: const Icon (YaruIcons .log_out),
86+
87+ child: Text (
88+ context.l10n.leave,
89+ style: context.textTheme.bodyMedium,
90+ ),
91+ ),
92+ ],
3393 child: widget.child,
3494 ),
3595 );
0 commit comments