Skip to content

Commit

Permalink
feat: Hand Raise sorting based on Time (#1812)
Browse files Browse the repository at this point in the history
* feat: Hand Raise sorting based on Time

* 🤖 Automated Format and Fix

---------

Co-authored-by: Decoder07 <[email protected]>
  • Loading branch information
Decoder07 and Decoder07 authored Aug 29, 2024
1 parent 927f7ec commit e08c00a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 20 deletions.
33 changes: 33 additions & 0 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> metadataMap = jsonDecode(metadata);
return metadataMap["handRaisedAt"];
} catch (e) {
return 0;
}
}

bool isBRB = false;

void changeMetadataBRB() {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class _ParticipantsBottomSheetState extends State<ParticipantsBottomSheet> {
);
}

bool isHandRaisedRow(String role) {
return role == "Hand Raised";
}

Widget _kebabMenu(HMSPeer peer) {
final meetingStore = context.read<MeetingStore>();
PeerTrackNode? peerTrackNode;
Expand Down Expand Up @@ -410,12 +414,13 @@ class _ParticipantsBottomSheetState extends State<ParticipantsBottomSheet> {
.keys
.elementAt(index);
return Selector<MeetingStore,
Tuple2<int, List<ParticipantsStore>?>>(
selector: (_, meetingStore) => Tuple2(
Tuple3<int, List<ParticipantsStore>?, String>>(
selector: (_, meetingStore) => Tuple3(
meetingStore
.participantsInMeetingMap[role]?.length ??
0,
meetingStore.participantsInMeetingMap[role]),
meetingStore.participantsInMeetingMap[role],
role),
builder: (_, participantsPerRole, __) {
return (participantsPerRole.item2?.isNotEmpty ??
false)
Expand Down Expand Up @@ -458,7 +463,9 @@ class _ParticipantsBottomSheetState extends State<ParticipantsBottomSheet> {
null
? 0
: (participantsPerRole.item1) *
54,
(isHandRaisedRow(role)
? 60
: 54),
child: Center(
child: ListView.builder(
physics:
Expand Down Expand Up @@ -538,15 +545,18 @@ class _ParticipantsBottomSheetState extends State<ParticipantsBottomSheet> {
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) =>
Expand All @@ -562,14 +572,14 @@ class _ParticipantsBottomSheetState extends State<ParticipantsBottomSheet> {
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,
),
),
)
Expand All @@ -588,12 +598,12 @@ class _ParticipantsBottomSheetState extends State<ParticipantsBottomSheet> {
? 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),
),
),
Expand Down

0 comments on commit e08c00a

Please sign in to comment.