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 committed Jan 25, 2024
1 parent 3491eba commit fd6f468
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 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
17 changes: 15 additions & 2 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/first_column_inner_routes.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/model/recovery_words/recovery_words.dart';
import 'package:fluffychat/domain/model/room/room_extension.dart';
import 'package:fluffychat/domain/usecase/recovery/get_recovery_words_interactor.dart';
import 'package:fluffychat/pages/bootstrap/bootstrap_dialog.dart';
import 'package:fluffychat/pages/bootstrap/tom_bootstrap_dialog.dart';
Expand Down Expand Up @@ -282,7 +283,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 @@ -507,7 +508,7 @@ class ChatListController extends State<ChatList>
await actionWithToggleSelectMode(toggleUnread);
return;
case ChatListSelectionActions.mute:
await actionWithToggleSelectMode(toggleMuted);
await actionWithToggleSelectMode(toggleMutedSelections);
return;
case ChatListSelectionActions.pin:
await actionWithToggleSelectMode(toggleFavouriteRoom);
Expand Down Expand Up @@ -599,6 +600,18 @@ class ChatListController extends State<ChatList>
);
}

Future<void> toggleMutedRoom(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
14 changes: 14 additions & 0 deletions lib/pages/chat_list/chat_list_view_builder.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.dart';
import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
import 'package:collection/collection.dart';
Expand Down Expand Up @@ -116,6 +117,19 @@ class _SlidableChatListItem extends StatelessWidget {
motion: const ScrollMotion(),
extentRatio: ChatListViewStyle.slidableExtentRatio,
children: [
SlidableAction(
autoClose: true,
label: room.isMuted
? L10n.of(context)!.unmute
: L10n.of(context)!.mute,
icon: room.isMuted
? Icons.notifications_off_outlined
: Icons.notifications_on_outlined,
onPressed: (_) => controller.toggleMutedRoom(room),
foregroundColor: ChatListViewStyle.slidableForegroundColorDefault,
backgroundColor:
Colors.amber[700] ?? ChatListViewStyle.muteSlidableColorRaw,
),
SlidableAction(
autoClose: true,
label: room.isFavourite
Expand Down
1 change: 1 addition & 0 deletions lib/pages/chat_list/chat_list_view_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ class ChatListViewStyle {
static const double slidableExtentRatio = 0.25;
static const Color slidableForegroundColorDefault = Colors.white;
static const Color pinSlidableColorRaw = Color(0xFF00C853);
static const Color muteSlidableColorRaw = Color(0xFFFFA000);
}
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
4 changes: 2 additions & 2 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 @@ -165,8 +166,7 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
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 fd6f468

Please sign in to comment.