From 467d103c2f540ece1ed13c7d912cd5e73a9ac490 Mon Sep 17 00:00:00 2001 From: Krille Date: Tue, 16 Jul 2024 07:31:43 +0200 Subject: [PATCH] chore: Follow up chat context menu --- lib/pages/chat_list/chat_list.dart | 90 +++++++++++++++++------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index d4f6067ed..50237a569 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -620,6 +620,10 @@ class ChatListController extends State BuildContext posContext, [ Room? space, ]) async { + if (room.membership == Membership.invite) { + return onChatTap(room); + } + final overlay = Overlay.of(posContext).context.findRenderObject() as RenderBox; @@ -644,7 +648,7 @@ class ChatListController extends State position: position, items: [ PopupMenuItem( - enabled: false, + value: ChatContextAction.open, child: Row( mainAxisSize: MainAxisSize.min, children: [ @@ -754,46 +758,51 @@ class ChatListController extends State if (action == null) return; if (!mounted) return; - if (action == ChatContextAction.goToSpace) { - setActiveSpace(space!.id); - return; - } - - if (action == ChatContextAction.leave) { - final confirmed = await showOkCancelAlertDialog( - useRootNavigator: false, - context: context, - title: L10n.of(context)!.areYouSure, - okLabel: L10n.of(context)!.leave, - cancelLabel: L10n.of(context)!.no, - message: L10n.of(context)!.archiveRoomDescription, - isDestructiveAction: true, - ); - if (confirmed == OkCancelResult.cancel) return; - } - if (!mounted) return; - - await showFutureLoadingDialog( - context: context, - future: () async { - switch (action) { - case ChatContextAction.goToSpace: - return; - case ChatContextAction.favorite: - return room.setFavourite(!room.isFavourite); - case ChatContextAction.markUnread: - return room.markUnread(!room.markedUnread); - case ChatContextAction.mute: - return room.setPushRuleState( - room.pushRuleState == PushRuleState.notify - ? PushRuleState.mentionsOnly - : PushRuleState.notify, - ); - case ChatContextAction.leave: - return room.leave(); + switch (action) { + case ChatContextAction.open: + onChatTap(room); + return; + case ChatContextAction.goToSpace: + setActiveSpace(space!.id); + return; + case ChatContextAction.favorite: + await showFutureLoadingDialog( + context: context, + future: () => room.setFavourite(!room.isFavourite), + ); + return; + case ChatContextAction.markUnread: + await showFutureLoadingDialog( + context: context, + future: () => room.markUnread(!room.markedUnread), + ); + return; + case ChatContextAction.mute: + await showFutureLoadingDialog( + context: context, + future: () => room.setPushRuleState( + room.pushRuleState == PushRuleState.notify + ? PushRuleState.mentionsOnly + : PushRuleState.notify, + ), + ); + return; + case ChatContextAction.leave: + final confirmed = await showOkCancelAlertDialog( + useRootNavigator: false, + context: context, + title: L10n.of(context)!.areYouSure, + okLabel: L10n.of(context)!.leave, + cancelLabel: L10n.of(context)!.no, + message: L10n.of(context)!.archiveRoomDescription, + isDestructiveAction: true, + ); + if (confirmed == OkCancelResult.cancel) return; + if (!mounted) { + await showFutureLoadingDialog(context: context, future: room.leave); } - }, - ); + return; + } } void dismissStatusList() async { @@ -993,6 +1002,7 @@ enum InviteActions { enum AddRoomType { chat, subspace } enum ChatContextAction { + open, goToSpace, favorite, markUnread,