From e08c00aa0160f732b1a2a3d925d4d3b7f7b1e3e8 Mon Sep 17 00:00:00 2001 From: Pushpam <93931528+Decoder07@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:18:38 +0530 Subject: [PATCH] feat: Hand Raise sorting based on Time (#1812) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Hand Raise sorting based on Time * 🤖 Automated Format and Fix --------- Co-authored-by: Decoder07 --- .../lib/src/meeting/meeting_store.dart | 33 ++++++++++++ .../participants_bottom_sheet.dart | 50 +++++++++++-------- 2 files changed, 63 insertions(+), 20 deletions(-) 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 a3730dd64..bebe8531d 100644 --- a/packages/hms_room_kit/lib/src/meeting/meeting_store.dart +++ b/packages/hms_room_kit/lib/src/meeting/meeting_store.dart @@ -666,16 +666,45 @@ class MeetingStore extends ChangeNotifier void toggleLocalPeerHandRaise() { if (isRaisedHand) { _hmsSDKInteractor.lowerLocalPeerHand(hmsActionResultListener: this); + resetTimestampWhenHandDown(); } else { _hmsSDKInteractor.raiseLocalPeerHand(hmsActionResultListener: this); + setTimestampWhenHandRaise(); } } + void setTimestampWhenHandRaise() { + int currentTime = DateTime.now().millisecondsSinceEpoch; + log("Vkohli Setting timestamp for hand raise $currentTime"); + _hmsSDKInteractor.changeMetadata( + metadata: + "{\"isBRBOn\":false,\"prevRole\":\"$previousRole\",\"handRaisedAt\":${currentTime}}", + hmsActionResultListener: this); + } + + void resetTimestampWhenHandDown() { + _hmsSDKInteractor.changeMetadata( + metadata: "{\"isBRBOn\":false,\"prevRole\":\"$previousRole\"}", + hmsActionResultListener: this); + } + void lowerRemotePeerHand(HMSPeer forPeer) { _hmsSDKInteractor.lowerRemotePeerHand( forPeer: forPeer, hmsActionResultListener: this); } + int _getTimestampFromPeerMetadata(String? metadata) { + if (metadata == null) { + return 0; + } + try { + Map metadataMap = jsonDecode(metadata); + return metadataMap["handRaisedAt"]; + } catch (e) { + return 0; + } + } + bool isBRB = false; void changeMetadataBRB() { @@ -1604,6 +1633,10 @@ class MeetingStore extends ChangeNotifier (handDownPeer) => handDownPeer.peer.peerId == peer.peerId); participantsInMeetingMap[peer.role.name]?[index].updatePeer(peer); } + participantsInMeetingMap["Hand Raised"]?.sort((a, b) { + return _getTimestampFromPeerMetadata(a.peer.metadata) + .compareTo(_getTimestampFromPeerMetadata(b.peer.metadata)); + }); notifyListeners(); } else if (peerUpdate == HMSPeerUpdate.metadataChanged) { participantsInMeetingMap[peer.role.name]?[index].updatePeer(peer); diff --git a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/participants_bottom_sheet.dart b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/participants_bottom_sheet.dart index 34cbf292d..a1ac8375a 100644 --- a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/participants_bottom_sheet.dart +++ b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/participants_bottom_sheet.dart @@ -69,6 +69,10 @@ class _ParticipantsBottomSheetState extends State { ); } + bool isHandRaisedRow(String role) { + return role == "Hand Raised"; + } + Widget _kebabMenu(HMSPeer peer) { final meetingStore = context.read(); PeerTrackNode? peerTrackNode; @@ -410,12 +414,13 @@ class _ParticipantsBottomSheetState extends State { .keys .elementAt(index); return Selector?>>( - selector: (_, meetingStore) => Tuple2( + Tuple3?, String>>( + selector: (_, meetingStore) => Tuple3( meetingStore .participantsInMeetingMap[role]?.length ?? 0, - meetingStore.participantsInMeetingMap[role]), + meetingStore.participantsInMeetingMap[role], + role), builder: (_, participantsPerRole, __) { return (participantsPerRole.item2?.isNotEmpty ?? false) @@ -458,7 +463,9 @@ class _ParticipantsBottomSheetState extends State { null ? 0 : (participantsPerRole.item1) * - 54, + (isHandRaisedRow(role) + ? 60 + : 54), child: Center( child: ListView.builder( physics: @@ -538,15 +545,18 @@ class _ParticipantsBottomSheetState extends State { isSIPPeer, __) { return isSIPPeer - ? CircleAvatar( - radius: 16, - backgroundColor: HMSThemeColors.surfaceBright, - child: SvgPicture.asset( - "packages/hms_room_kit/lib/src/assets/icons/sip_call.svg", - height: 12, - width: 12, - colorFilter: ColorFilter.mode(HMSThemeColors.onSurfaceHighEmphasis, BlendMode.srcIn), - )) + ? Padding( + padding: const EdgeInsets.only(right: 4.0), + child: CircleAvatar( + radius: 12, + backgroundColor: HMSThemeColors.surfaceDefault, + child: SvgPicture.asset( + "packages/hms_room_kit/lib/src/assets/icons/sip_call.svg", + height: 12, + width: 12, + colorFilter: ColorFilter.mode(HMSThemeColors.onSurfaceHighEmphasis, BlendMode.srcIn), + )), + ) : const SizedBox(); }, selector: (_, participantsStore) => @@ -562,14 +572,14 @@ class _ParticipantsBottomSheetState extends State { builder: (_, participantData, __) { return participantData.item1 != -1 && participantData.item1 < 3 && participantData.item2 ? Padding( - padding: const EdgeInsets.only(right: 16.0), + padding: const EdgeInsets.only(right: 4.0), child: CircleAvatar( - radius: 16, + radius: 12, backgroundColor: HMSThemeColors.surfaceDefault, child: SvgPicture.asset( "packages/hms_room_kit/lib/src/assets/icons/network_${participantData.item1}.svg", - height: 16, - width: 16, + height: 12, + width: 12, ), ), ) @@ -588,12 +598,12 @@ class _ParticipantsBottomSheetState extends State { ? Padding( padding: const EdgeInsets.only(right: 16.0), child: CircleAvatar( - radius: 16, + radius: 12, backgroundColor: HMSThemeColors.surfaceDefault, child: SvgPicture.asset( "packages/hms_room_kit/lib/src/assets/icons/hand_outline.svg", - height: 16, - width: 16, + height: 12, + width: 12, colorFilter: ColorFilter.mode(HMSThemeColors.onSurfaceHighEmphasis, BlendMode.srcIn), ), ),