Skip to content

Commit

Permalink
Added option to block peer from chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Dec 26, 2023
1 parent 0470f01 commit 940a995
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 680 deletions.
8 changes: 8 additions & 0 deletions packages/hms_room_kit/lib/src/assets/icons/block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions packages/hms_room_kit/lib/src/enums/session_store_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ enum SessionStoreKey {
chatState,
chatPeerBlacklist,
chatMessageBlacklist,
pinnedMessages,
unknown
}

extension SessionStoreKeyValues on SessionStoreKey {
static String getNameFromMethod(SessionStoreKey method) {
switch (method) {
case SessionStoreKey.pinnedMessageSessionKey:
return "pinnedMessage";
return "pinnedMessages";
case SessionStoreKey.spotlight:
return "spotlight";
case SessionStoreKey.chatState:
Expand All @@ -24,16 +23,14 @@ extension SessionStoreKeyValues on SessionStoreKey {
return "chatPeerBlacklist";
case SessionStoreKey.chatMessageBlacklist:
return "chatMessageBlacklist";
case SessionStoreKey.pinnedMessages:
return "pinnedMessages";
default:
return "";
}
}

static SessionStoreKey getMethodFromName(String key) {
switch (key) {
case "pinnedMessage":
case "pinnedMessages":
return SessionStoreKey.pinnedMessageSessionKey;
case "spotlight":
return SessionStoreKey.spotlight;
Expand All @@ -43,8 +40,6 @@ extension SessionStoreKeyValues on SessionStoreKey {
return SessionStoreKey.chatPeerBlacklist;
case "chatMessageBlacklist":
return SessionStoreKey.chatMessageBlacklist;
case "pinnedMessages":
return SessionStoreKey.pinnedMessages;
default:
return SessionStoreKey.unknown;
}
Expand Down
395 changes: 0 additions & 395 deletions packages/hms_room_kit/lib/src/hls_viewer/hls_chat.dart

This file was deleted.

42 changes: 37 additions & 5 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ class MeetingStore extends ChangeNotifier

bool retryHLS = true;

String? sessionMetadata;
///[pinnedMessages] is the list of pinned messages
List<dynamic> pinnedMessages = [];

///[blackListedUserIds] is the list of user ids which are blacklisted from chat
List<String> blackListedUserIds = [];

bool isPipActive = false;

Expand Down Expand Up @@ -1748,7 +1752,17 @@ class MeetingStore extends ChangeNotifier
SessionStoreKey keyType = SessionStoreKeyValues.getMethodFromName(key);
switch (keyType) {
case SessionStoreKey.pinnedMessageSessionKey:
sessionMetadata = value;
pinnedMessages.clear();
if (value != null) {
var data = jsonDecode(value ?? "");
if (data != null && data.isNotEmpty) {
data.forEach((element) => pinnedMessages.add({
"id": element["id"],
"text": element["text"],
}));
}
}
notifyListeners();
break;
case SessionStoreKey.spotlight:
setPeerToSpotlight(value);
Expand All @@ -1766,11 +1780,19 @@ class MeetingStore extends ChangeNotifier

break;
case SessionStoreKey.chatPeerBlacklist:
blackListedUserIds.clear();
if (value != null) {
var data = jsonDecode(value);
if (data != null && data.isNotEmpty) {
data.forEach((element) {
blackListedUserIds.add(element);
});
}
notifyListeners();
}
break;
case SessionStoreKey.chatMessageBlacklist:
break;
case SessionStoreKey.pinnedMessages:
break;
case SessionStoreKey.unknown:
break;
}
Expand Down Expand Up @@ -1929,6 +1951,16 @@ class MeetingStore extends ChangeNotifier
key: key, data: metadata, hmsActionResultListener: this);
}

void togglePeerBlock({required String peerId, bool isBlocked = false}) {
if (!isBlocked) {
blackListedUserIds.add(peerId);
}
setSessionMetadataForKey(
key: SessionStoreKeyValues.getNameFromMethod(
SessionStoreKey.chatPeerBlacklist),
metadata: isBlocked ? null : blackListedUserIds);
}

void getSessionMetadata(String key) async {
dynamic result = await _hmsSessionStore?.getSessionMetadataForKey(key: key);
if (result is HMSException) {
Expand All @@ -1938,7 +1970,7 @@ class MeetingStore extends ChangeNotifier
return;
}
if (result != null) {
sessionMetadata = result as String;
log(result);
}
notifyListeners();
}
Expand Down
Loading

0 comments on commit 940a995

Please sign in to comment.