Skip to content

Commit

Permalink
feat: add mute and unmute button in chat details
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Sep 29, 2023
1 parent df63b3d commit 8dc4274
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
29 changes: 25 additions & 4 deletions lib/pages/chat_details/chat_details.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/model/room/room_extension.dart';
import 'package:fluffychat/pages/chat_details/chat_details_actions_enum.dart';
import 'package:fluffychat/pages/chat_details/chat_details_page_view/chat_details_members_page.dart';
import 'package:fluffychat/pages/chat_details/chat_details_page_view/chat_details_page_enum.dart';
Expand Down Expand Up @@ -55,12 +56,18 @@ class ChatDetailsController extends State<ChatDetails>

final actionsWebAndDesktopKey = const Key('ActionsWebAndDesktopKey');

Room? room;

final responsive = getIt.get<ResponsiveUtils>();

PageController pageController = PageController();

final ValueNotifier<int> currentPage = ValueNotifier(0);

final muteNotifier = ValueNotifier<PushRuleState>(
PushRuleState.notify,
);

List<User>? members;

bool displaySettings = false;
Expand All @@ -70,8 +77,6 @@ class ChatDetailsController extends State<ChatDetails>
bool get isMobileAndTablet =>
responsive.isMobile(context) || responsive.isTablet(context);

Room? get room => Matrix.of(context).client.getRoomById(roomId!);

Timeline? _timeline;

Future<Timeline> getTimeline() async {
Expand All @@ -83,6 +88,13 @@ class ChatDetailsController extends State<ChatDetails>

int get actualMembersCount => room!.summary.actualMembersCount;

@override
void initState() {
super.initState();
room = Matrix.of(context).client.getRoomById(roomId!);
muteNotifier.value = room?.pushRuleState ?? PushRuleState.notify;
}

void toggleDisplaySettings() =>
setState(() => displaySettings = !displaySettings);

Expand Down Expand Up @@ -434,7 +446,9 @@ class ChatDetailsController extends State<ChatDetails>

List<ChatDetailsActions> chatDetailsActionsButton() => [
if (responsive.isDesktop(context)) ChatDetailsActions.addMembers,
// ChatDetailsActions.mute,
muteNotifier.value != PushRuleState.notify
? ChatDetailsActions.unmute
: ChatDetailsActions.mute,
ChatDetailsActions.search,
// ChatDetailsActions.more,
];
Expand Down Expand Up @@ -482,17 +496,24 @@ class ChatDetailsController extends State<ChatDetails>
);
}

void onTapActionsButton(ChatDetailsActions action) {
void onTapActionsButton(ChatDetailsActions action) async {
switch (action) {
case ChatDetailsActions.addMembers:
openDialogInvite();
break;
case ChatDetailsActions.mute:
await room?.mute();
muteNotifier.value = PushRuleState.mentionsOnly;
break;
case ChatDetailsActions.search:
context.pop(ChatDetailsActions.search);
break;
case ChatDetailsActions.more:
break;
case ChatDetailsActions.unmute:
await room?.unmute();
muteNotifier.value = PushRuleState.notify;
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/pages/chat_details/chat_details_actions_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum ChatDetailsActions {
addMembers,
mute,
search,
unmute,
more;

String getTitle(BuildContext context) {
Expand All @@ -13,6 +14,8 @@ enum ChatDetailsActions {
return L10n.of(context)!.addMembers;
case ChatDetailsActions.mute:
return L10n.of(context)!.mute;
case ChatDetailsActions.unmute:
return L10n.of(context)!.unmute;
case ChatDetailsActions.search:
return L10n.of(context)!.search;
case ChatDetailsActions.more:
Expand All @@ -30,6 +33,8 @@ enum ChatDetailsActions {
return Icons.search;
case ChatDetailsActions.more:
return Icons.more_horiz;
case ChatDetailsActions.unmute:
return Icons.notifications_off;
}
}
}
37 changes: 22 additions & 15 deletions lib/pages/chat_details/chat_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,28 @@ class ChatDetailsView extends StatelessWidget {
context: context,
room: controller.room!,
),
ActionsHeaderBuilder(
actions: controller.chatDetailsActionsButton(),
width: ChatDetailViewStyle.actionsHeaderWidth(context),
buttonColor: !controller.isMobileAndTablet
? LinagoraRefColors.material().primary[100]
: null,
borderSide: BorderSide(
width: 1,
color: controller.isMobileAndTablet
? LinagoraRefColors.material().neutral[90]!
: Colors.transparent,
),
onTap: (actions) => controller.onTapActionsButton(
actions,
),
ValueListenableBuilder(
valueListenable: controller.muteNotifier,
builder: (context, pushRuleState, child) {
final buttons = controller.chatDetailsActionsButton();

return ActionsHeaderBuilder(
actions: buttons,
width: ChatDetailViewStyle.actionsHeaderWidth(context),
buttonColor: !controller.isMobileAndTablet
? LinagoraRefColors.material().primary[100]
: null,
borderSide: BorderSide(
width: 1,
color: controller.isMobileAndTablet
? LinagoraRefColors.material().neutral[90]!
: Colors.transparent,
),
onTap: (actions) => controller.onTapActionsButton(
actions,
),
);
},
),
Expanded(
child: ClipRRect(
Expand Down

0 comments on commit 8dc4274

Please sign in to comment.