diff --git a/lib/domain/model/room/room_extension.dart b/lib/domain/model/room/room_extension.dart index 9212292fbd..6a80eabb46 100644 --- a/lib/domain/model/room/room_extension.dart +++ b/lib/domain/model/room/room_extension.dart @@ -46,6 +46,10 @@ extension RoomExtension on Room { await setPushRuleState(PushRuleState.notify); } + bool get isMuted { + return pushRuleState != PushRuleState.notify; + } + String storePlaceholderFileInMem({ required FileInfo fileInfo, String? txid, diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index f58f615644..434130a8ad 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -284,7 +284,7 @@ class ChatListController extends State ); } - Future toggleMuted() async { + Future toggleMutedSelections() async { await TwakeDialog.showFutureLoadingDialogFullScreen( future: () async { for (final conversation in conversationSelectionNotifier.value) { @@ -517,7 +517,7 @@ class ChatListController extends State await actionWithToggleSelectMode(toggleUnreadSelections); return; case ChatListSelectionActions.mute: - await actionWithToggleSelectMode(toggleMuted); + await actionWithToggleSelectMode(toggleMutedSelections); return; case ChatListSelectionActions.pin: await actionWithToggleSelectMode(toggleFavouriteRoom); @@ -582,15 +582,7 @@ class ChatListController extends State await togglePin(room); return; case ChatListSelectionActions.mute: - await TwakeDialog.showFutureLoadingDialogFullScreen( - future: () async { - await client.getRoomById(room.id)!.setPushRuleState( - room.pushRuleState == PushRuleState.notify - ? PushRuleState.mentionsOnly - : PushRuleState.notify, - ); - }, - ); + await toggleMuteRoom(room); return; case ChatListSelectionActions.more: return; @@ -621,6 +613,18 @@ class ChatListController extends State ); } + Future toggleMuteRoom(Room room) async { + await TwakeDialog.showFutureLoadingDialogFullScreen( + future: () async { + if (room.isMuted) { + await room.unmute(); + } else { + await room.mute(); + } + }, + ); + } + List _getNavigationDestinations() { return [ ChatListSelectionActions.read, diff --git a/lib/pages/chat_list/chat_list_item_title.dart b/lib/pages/chat_list/chat_list_item_title.dart index d136f5fbbc..0fa59464df 100644 --- a/lib/pages/chat_list/chat_list_item_title.dart +++ b/lib/pages/chat_list/chat_list_item_title.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/domain/model/room/room_extension.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item_title_style.dart'; import 'package:fluffychat/presentation/decorators/chat_list/title_text_style_decorator/title_text_style_view.dart'; import 'package:fluffychat/presentation/mixins/chat_list_item_mixin.dart'; @@ -31,7 +32,6 @@ class ChatListItemTitle extends StatelessWidget with ChatListItemMixin { final displayName = room.getLocalizedDisplayname( MatrixLocals(L10n.of(context)!), ); - final isMuted = room.pushRuleState != PushRuleState.notify; return Row( children: [ Expanded( @@ -69,7 +69,7 @@ class ChatListItemTitle extends StatelessWidget with ChatListItemMixin { color: ChatListItemStyle.pinnedIconColor, ), ), - if (isMuted) + if (room.isMuted) Padding( padding: ChatListItemTitleStyle.paddingLeftIcon, child: Icon( diff --git a/lib/pages/chat_list/chat_list_view_builder.dart b/lib/pages/chat_list/chat_list_view_builder.dart index 4b87c6ae38..69ecf66f4c 100644 --- a/lib/pages/chat_list/chat_list_view_builder.dart +++ b/lib/pages/chat_list/chat_list_view_builder.dart @@ -54,7 +54,7 @@ class ChatListViewBuilder extends StatelessWidget { List _getSlidables(BuildContext context, Room room) { return [ - if (!room.isInvitation) ...[ + if (!room.isInvitation) _ChatCustomSlidableAction( label: room.isUnread ? L10n.of(context)!.read : L10n.of(context)!.unread, @@ -68,6 +68,19 @@ class ChatListViewBuilder extends StatelessWidget { foregroundColor: Theme.of(context).colorScheme.onPrimary, backgroundColor: ChatListViewStyle.readSlidableColor(room.isUnread)!, ), + _ChatCustomSlidableAction( + label: room.isMuted ? L10n.of(context)!.unmute : L10n.of(context)!.mute, + icon: Icon( + room.isMuted + ? Icons.notifications_off_outlined + : Icons.notifications_on_outlined, + size: ChatListViewStyle.slidableIconSize, + ), + onPressed: (_) => controller.toggleMuteRoom(room), + foregroundColor: Theme.of(context).colorScheme.onPrimary, + backgroundColor: ChatListViewStyle.muteSlidableColor(room.isMuted)!, + ), + if (!room.isInvitation) _ChatCustomSlidableAction( label: room.isFavourite ? L10n.of(context)!.unpin @@ -90,7 +103,6 @@ class ChatListViewBuilder extends StatelessWidget { backgroundColor: ChatListViewStyle.pinSlidableColor(room.isFavourite)!, ), - ], ]; } } @@ -129,6 +141,7 @@ class _ChatCustomSlidableAction extends StatelessWidget { style: Theme.of(context).textTheme.labelMedium?.copyWith( color: foregroundColor, ), + overflow: TextOverflow.ellipsis, ), ], ), diff --git a/lib/pages/chat_list/chat_list_view_style.dart b/lib/pages/chat_list/chat_list_view_style.dart index cd6c8b5f49..a104a66b7b 100644 --- a/lib/pages/chat_list/chat_list_view_style.dart +++ b/lib/pages/chat_list/chat_list_view_style.dart @@ -32,4 +32,10 @@ class ChatListViewStyle { ? LinagoraRefColors.material().neutral[70] : LinagoraRefColors.material().primary[40]; } + + static Color? muteSlidableColor(bool isMuted) { + return isMuted + ? LinagoraRefColors.material().primary[20] + : Colors.amber[700]; + } } diff --git a/lib/presentation/decorators/chat_list/subtitle_text_style_decorator/subtitle_text_style_decorator.dart b/lib/presentation/decorators/chat_list/subtitle_text_style_decorator/subtitle_text_style_decorator.dart index 66a2e827a9..c8ffb4fd67 100644 --- a/lib/presentation/decorators/chat_list/subtitle_text_style_decorator/subtitle_text_style_decorator.dart +++ b/lib/presentation/decorators/chat_list/subtitle_text_style_decorator/subtitle_text_style_decorator.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/domain/model/room/room_extension.dart'; import 'package:fluffychat/presentation/decorators/chat_list/subtitle_text_style_decorator/subtitle_text_style_component.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -69,8 +70,7 @@ class MuteChatListSubtitleTextStyleDecorator @override TextStyle textStyle(Room room) { - final isMuted = room.pushRuleState != PushRuleState.notify; - if (isMuted) { + if (room.isMuted) { return _interfaceTextStyleComponent.textStyle(room).copyWith( color: LinagoraRefColors.material().tertiary[20], ); diff --git a/lib/presentation/enum/chat_list/chat_list_enum.dart b/lib/presentation/enum/chat_list/chat_list_enum.dart index 5420004565..b2bbb73ae3 100644 --- a/lib/presentation/enum/chat_list/chat_list_enum.dart +++ b/lib/presentation/enum/chat_list/chat_list_enum.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/domain/model/room/room_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -68,7 +69,7 @@ enum ChatListSelectionActions { return Icons.mark_chat_unread; } case ChatListSelectionActions.mute: - if (room.pushRuleState == PushRuleState.notify) { + if (room.isMuted) { return Icons.volume_off; } else { return Icons.volume_up; @@ -97,10 +98,10 @@ enum ChatListSelectionActions { return L10n.of(context)!.markThisChatAsUnRead; } case ChatListSelectionActions.mute: - if (room.pushRuleState == PushRuleState.notify) { - return L10n.of(context)!.muteThisChat; - } else { + if (room.isMuted) { return L10n.of(context)!.unmuteThisChat; + } else { + return L10n.of(context)!.muteThisChat; } case ChatListSelectionActions.pin: if (room.isFavourite) { diff --git a/lib/widgets/chat_settings_popup_menu.dart b/lib/widgets/chat_settings_popup_menu.dart index f10ce30a14..24edaff9f5 100644 --- a/lib/widgets/chat_settings_popup_menu.dart +++ b/lib/widgets/chat_settings_popup_menu.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:fluffychat/domain/model/room/room_extension.dart'; import 'package:fluffychat/utils/dialog/twake_dialog.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -159,14 +160,12 @@ class ChatSettingsPopupMenuState extends State { break; case 'mute': await TwakeDialog.showFutureLoadingDialogFullScreen( - future: () => - widget.room.setPushRuleState(PushRuleState.mentionsOnly), + future: () => widget.room.mute(), ); break; case 'unmute': await TwakeDialog.showFutureLoadingDialogFullScreen( - future: () => - widget.room.setPushRuleState(PushRuleState.notify), + future: () => widget.room.unmute(), ); break; case 'details':