Skip to content

Commit

Permalink
TW-1394: Add Slidable Chat List Item - Mute/Unmute
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE authored and hoangdat committed Feb 15, 2024
1 parent f10d47f commit 4cd6c2d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
4 changes: 4 additions & 0 deletions lib/domain/model/room/room_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 15 additions & 11 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class ChatListController extends State<ChatList>
);
}

Future<void> toggleMuted() async {
Future<void> toggleMutedSelections() async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
for (final conversation in conversationSelectionNotifier.value) {
Expand Down Expand Up @@ -517,7 +517,7 @@ class ChatListController extends State<ChatList>
await actionWithToggleSelectMode(toggleUnreadSelections);
return;
case ChatListSelectionActions.mute:
await actionWithToggleSelectMode(toggleMuted);
await actionWithToggleSelectMode(toggleMutedSelections);
return;
case ChatListSelectionActions.pin:
await actionWithToggleSelectMode(toggleFavouriteRoom);
Expand Down Expand Up @@ -582,15 +582,7 @@ class ChatListController extends State<ChatList>
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;
Expand Down Expand Up @@ -621,6 +613,18 @@ class ChatListController extends State<ChatList>
);
}

Future<void> toggleMuteRoom(Room room) async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
if (room.isMuted) {
await room.unmute();
} else {
await room.mute();
}
},
);
}

List<ChatListSelectionActions> _getNavigationDestinations() {
return [
ChatListSelectionActions.read,
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/chat_list/chat_list_item_title.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: <Widget>[
Expanded(
Expand Down Expand Up @@ -69,7 +69,7 @@ class ChatListItemTitle extends StatelessWidget with ChatListItemMixin {
color: ChatListItemStyle.pinnedIconColor,
),
),
if (isMuted)
if (room.isMuted)
Padding(
padding: ChatListItemTitleStyle.paddingLeftIcon,
child: Icon(
Expand Down
17 changes: 15 additions & 2 deletions lib/pages/chat_list/chat_list_view_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ChatListViewBuilder extends StatelessWidget {

List<Widget> _getSlidables(BuildContext context, Room room) {
return [
if (!room.isInvitation) ...[
if (!room.isInvitation)
_ChatCustomSlidableAction(
label:
room.isUnread ? L10n.of(context)!.read : L10n.of(context)!.unread,
Expand All @@ -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
Expand All @@ -90,7 +103,6 @@ class ChatListViewBuilder extends StatelessWidget {
backgroundColor:
ChatListViewStyle.pinSlidableColor(room.isFavourite)!,
),
],
];
}
}
Expand Down Expand Up @@ -129,6 +141,7 @@ class _ChatCustomSlidableAction extends StatelessWidget {
style: Theme.of(context).textTheme.labelMedium?.copyWith(
color: foregroundColor,
),
overflow: TextOverflow.ellipsis,
),
],
),
Expand Down
6 changes: 6 additions & 0 deletions lib/pages/chat_list/chat_list_view_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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],
);
Expand Down
9 changes: 5 additions & 4 deletions lib/presentation/enum/chat_list/chat_list_enum.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand 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) {
Expand Down
7 changes: 3 additions & 4 deletions lib/widgets/chat_settings_popup_menu.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -159,14 +160,12 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
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':
Expand Down

0 comments on commit 4cd6c2d

Please sign in to comment.