-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from 100mslive/dev
Dev to release
- Loading branch information
Showing
66 changed files
with
3,308 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
room-kit/src/main/java/live/hms/roomkit/ui/meeting/BlockUserUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package live.hms.roomkit.ui.meeting | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import com.google.gson.JsonElement | ||
import live.hms.roomkit.ui.meeting.chat.ChatMessage | ||
import live.hms.video.error.HMSException | ||
import live.hms.video.sdk.HMSActionResultListener | ||
import live.hms.video.sessionstore.HMSKeyChangeListener | ||
import live.hms.video.sessionstore.HmsSessionStore | ||
import live.hms.video.utils.GsonUtils.gson | ||
|
||
class BlockUserUseCase: AutoCloseable { | ||
private lateinit var hmsSessionStore: HmsSessionStore | ||
val TAG = "BlockUserUseCase" | ||
private val BLOCK_PEER_KEY = "chatPeerBlacklist" | ||
val currentBlockList: MutableLiveData<Set<String>> = MutableLiveData(emptySet()) | ||
private val keyChangeListener = object : HMSKeyChangeListener { | ||
override fun onKeyChanged(key: String, value: JsonElement?) { | ||
if (key == BLOCK_PEER_KEY) { | ||
// If the value was null, turn it empty. Only stringify if it isn't. | ||
val newList: Set<String> = if (value == null) { | ||
setOf() | ||
} else { | ||
gson.fromJson(value.asJsonArray, Array<String>::class.java).toSet() | ||
} | ||
currentBlockList.postValue(newList) | ||
} | ||
} | ||
} | ||
fun setSessionStore(hmsSessionStore : HmsSessionStore) { | ||
this.hmsSessionStore = hmsSessionStore | ||
} | ||
fun blockUser(chatMessage: ChatMessage, hmsActionResultListener: HMSActionResultListener) { | ||
if(!::hmsSessionStore.isInitialized ) { | ||
Log.e(TAG,"Tried to block user without session store inited") | ||
return | ||
} | ||
if (chatMessage.userIdForBlockList != null) { | ||
// the user is no longer present | ||
// This is a list and will be updated. | ||
val newValue = currentBlockList.value | ||
// Add the peer id or create a new list if null | ||
?.plus(chatMessage.userIdForBlockList) ?: setOf(chatMessage.userIdForBlockList) | ||
hmsSessionStore.set(newValue, | ||
BLOCK_PEER_KEY,hmsActionResultListener) | ||
} | ||
} | ||
|
||
fun addKeyChangeListener() { | ||
hmsSessionStore.addKeyChangeListener( | ||
listOf(BLOCK_PEER_KEY), | ||
keyChangeListener, | ||
object : HMSActionResultListener { | ||
override fun onError(error: HMSException) { | ||
Log.e(TAG, "Error $error") | ||
} | ||
|
||
override fun onSuccess() { | ||
Log.d(TAG, "Added block peer key") | ||
} | ||
|
||
}) | ||
} | ||
|
||
override fun close() { | ||
if(!::hmsSessionStore.isInitialized) | ||
return | ||
// remove the key change listeners for this. | ||
hmsSessionStore.removeKeyChangeListener( | ||
keyChangeListener, | ||
object : HMSActionResultListener { | ||
override fun onError(error: HMSException) { | ||
} | ||
|
||
override fun onSuccess() { | ||
|
||
} | ||
|
||
}) | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
room-kit/src/main/java/live/hms/roomkit/ui/meeting/HideMessageUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package live.hms.roomkit.ui.meeting | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import com.google.gson.JsonElement | ||
import live.hms.roomkit.ui.meeting.chat.ChatMessage | ||
import live.hms.video.error.HMSException | ||
import live.hms.video.sdk.HMSActionResultListener | ||
import live.hms.video.sessionstore.HMSKeyChangeListener | ||
import live.hms.video.sessionstore.HmsSessionStore | ||
import live.hms.video.utils.GsonUtils | ||
|
||
class HideMessageUseCase: AutoCloseable { | ||
private lateinit var hmsSessionStore: HmsSessionStore | ||
val TAG = "HideMesssageUseCase" | ||
private val HIDE_MESSAGE_KEY = "chatMessageBlacklist" | ||
val messageIdsToHide: MutableLiveData<Set<String>> = MutableLiveData(setOf()) | ||
private val keyChangeListener = object : HMSKeyChangeListener { | ||
override fun onKeyChanged(key: String, value: JsonElement?) { | ||
if (key == HIDE_MESSAGE_KEY) { | ||
// If the value was null, turn it empty. Only stringify if it isn't. | ||
val newList: List<String> = if (value == null) { | ||
emptyList() | ||
} else { | ||
GsonUtils.gson.fromJson(value.asJsonArray, Array<String>::class.java).toList() | ||
} | ||
messageIdsToHide.postValue(newList.toSet()) | ||
} | ||
} | ||
} | ||
fun setSessionStore(hmsSessionStore : HmsSessionStore) { | ||
this.hmsSessionStore = hmsSessionStore | ||
} | ||
fun hideMessage(chatMessage: ChatMessage, resultListener: HMSActionResultListener) { | ||
if(!::hmsSessionStore.isInitialized ) { | ||
Log.e(TAG,"Tried to hide message without session store inited") | ||
return | ||
} | ||
if (chatMessage.messageId != null) { | ||
// the user is no longer present | ||
// This is a list and will be updated. | ||
val newValue = messageIdsToHide.value | ||
// Add the peer id or create a new list if null | ||
?.plus(chatMessage.messageId) ?: listOf(chatMessage.messageId) | ||
hmsSessionStore.set(newValue, | ||
HIDE_MESSAGE_KEY, | ||
resultListener) | ||
} | ||
} | ||
|
||
fun addKeyChangeListener() { | ||
hmsSessionStore.addKeyChangeListener( | ||
listOf(HIDE_MESSAGE_KEY), | ||
keyChangeListener, | ||
object : HMSActionResultListener { | ||
override fun onError(error: HMSException) { | ||
Log.e(TAG, "Error $error") | ||
} | ||
|
||
override fun onSuccess() { | ||
Log.d(TAG, "Added hide message key") | ||
} | ||
|
||
}) | ||
} | ||
|
||
override fun close() { | ||
if(!::hmsSessionStore.isInitialized) | ||
return | ||
// remove the key change listeners for this. | ||
hmsSessionStore.removeKeyChangeListener( | ||
keyChangeListener, | ||
object : HMSActionResultListener { | ||
override fun onError(error: HMSException) { | ||
} | ||
|
||
override fun onSuccess() { | ||
|
||
} | ||
|
||
}) | ||
} | ||
|
||
} |
Oops, something went wrong.