From a89a2e4090e10415e80f6e77fcf8c7a45c0ceec9 Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Thu, 11 Jan 2024 19:27:41 +0530 Subject: [PATCH] Added hide message functionality --- .../lib/src/assets/icons/hide.svg | 5 ++++ .../hls_viewer/overlay_chat_component.dart | 10 ++++---- .../lib/src/meeting/meeting_store.dart | 23 ++++++++++++++++++ .../bottom_sheets/chat_bottom_sheet.dart | 2 +- .../chat_utilities_bottom_sheet.dart | 24 +++++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 packages/hms_room_kit/lib/src/assets/icons/hide.svg diff --git a/packages/hms_room_kit/lib/src/assets/icons/hide.svg b/packages/hms_room_kit/lib/src/assets/icons/hide.svg new file mode 100644 index 000000000..d87fb4946 --- /dev/null +++ b/packages/hms_room_kit/lib/src/assets/icons/hide.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/packages/hms_room_kit/lib/src/hls_viewer/overlay_chat_component.dart b/packages/hms_room_kit/lib/src/hls_viewer/overlay_chat_component.dart index 86da8d2e7..3b56051e8 100644 --- a/packages/hms_room_kit/lib/src/hls_viewer/overlay_chat_component.dart +++ b/packages/hms_room_kit/lib/src/hls_viewer/overlay_chat_component.dart @@ -58,10 +58,12 @@ class _OverlayChatComponentState extends State { ///This function scrolls to the end of the list void _scrollToEnd() { - WidgetsBinding.instance.addPostFrameCallback((_) => - _scrollController.animateTo(_scrollController.position.maxScrollExtent, - duration: const Duration(milliseconds: 200), - curve: Curves.easeInOut)); + if (_scrollController.hasClients) { + WidgetsBinding.instance.addPostFrameCallback((_) => _scrollController + .animateTo(_scrollController.position.maxScrollExtent, + duration: const Duration(milliseconds: 200), + curve: Curves.easeInOut)); + } } ///This function updates the selected value diff --git a/packages/hms_room_kit/lib/src/meeting/meeting_store.dart b/packages/hms_room_kit/lib/src/meeting/meeting_store.dart index 5024fa1f0..5944727a4 100644 --- a/packages/hms_room_kit/lib/src/meeting/meeting_store.dart +++ b/packages/hms_room_kit/lib/src/meeting/meeting_store.dart @@ -182,6 +182,9 @@ class MeetingStore extends ChangeNotifier ///[pinnedMessages] is the list of pinned messages List pinnedMessages = []; + ///[hiddenMessages] is the list of hidden messages + List hiddenMessages = []; + ///[blackListedUserIds] is the list of user ids which are blacklisted from chat List blackListedUserIds = []; @@ -1812,6 +1815,16 @@ class MeetingStore extends ChangeNotifier } break; case SessionStoreKey.chatMessageBlacklist: + hiddenMessages.clear(); + if (value != null) { + var data = jsonDecode(value); + if (data != null && data.isNotEmpty) { + data.forEach((element) { + hiddenMessages.add(element); + messages.removeWhere((message) => message.messageId == element); + }); + } + } break; case SessionStoreKey.unknown: break; @@ -2011,6 +2024,16 @@ class MeetingStore extends ChangeNotifier metadata: data); } + void hideMessage(HMSMessage message) { + hiddenMessages.add(message.messageId); + unpinMessage(message.messageId); + setSessionMetadataForKey( + key: SessionStoreKeyValues.getNameFromMethod( + SessionStoreKey.chatMessageBlacklist), + metadata: hiddenMessages); + notifyListeners(); + } + ///[setReipientSelectorValue] method is used to set the value of recipient selector void setRecipientSelectorValue() { if (HMSRoomLayout.chatData?.isPublicChatEnabled ?? false) { diff --git a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_bottom_sheet.dart b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_bottom_sheet.dart index 1eaee59ba..03c6f222a 100644 --- a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_bottom_sheet.dart +++ b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_bottom_sheet.dart @@ -41,7 +41,7 @@ class _ChatBottomSheetState extends State { } void _scrollToEnd() { - if (_scrollController.positions.isNotEmpty) { + if (_scrollController.hasClients) { WidgetsBinding.instance.addPostFrameCallback((_) => _scrollController .animateTo(_scrollController.position.maxScrollExtent, duration: const Duration(milliseconds: 200), diff --git a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_utilities_bottom_sheet.dart b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_utilities_bottom_sheet.dart index fc2783795..f492e66bd 100644 --- a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_utilities_bottom_sheet.dart +++ b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/chat_utilities_bottom_sheet.dart @@ -122,6 +122,30 @@ class _ChatUtilitiesBottomSheetState extends State { fontWeight: FontWeight.w600, textColor: HMSThemeColors.onSurfaceHighEmphasis)), + if ((HMSRoomLayout.chatData?.realTimeControls?.canHideMessage ?? + false) && + (widget.message.sender?.isLocal ?? false)) + ListTile( + horizontalTitleGap: 2, + onTap: () async { + Navigator.pop(context); + context.read().hideMessage(widget.message); + }, + contentPadding: EdgeInsets.zero, + leading: SvgPicture.asset( + "packages/hms_room_kit/lib/src/assets/icons/hide.svg", + semanticsLabel: "fl_copy_message_icon", + height: 20, + width: 20, + colorFilter: ColorFilter.mode( + HMSThemeColors.onSurfaceHighEmphasis, BlendMode.srcIn), + ), + title: HMSSubheadingText( + text: "Hide for Everyone", + letterSpacing: 0.1, + fontWeight: FontWeight.w600, + textColor: HMSThemeColors.onSurfaceHighEmphasis)), + if (HMSRoomLayout.chatData?.realTimeControls?.canBlockUser ?? false) ListTile( horizontalTitleGap: 2,