Skip to content

Commit

Permalink
Merge pull request #538 from 100mslive/dev
Browse files Browse the repository at this point in the history
Dev to release
  • Loading branch information
PratimMallick authored Dec 1, 2023
2 parents c8a6454 + cacd1ca commit 671be7f
Show file tree
Hide file tree
Showing 66 changed files with 3,308 additions and 546 deletions.
27 changes: 22 additions & 5 deletions app/src/main/java/live/hms/app2/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package live.hms.app2.ui.home

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
Expand All @@ -9,14 +10,12 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.core.content.edit
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.navigation.fragment.findNavController
import live.hms.app2.R
import live.hms.app2.databinding.FragmentHomeBinding
Expand All @@ -32,13 +31,14 @@ import live.hms.roomkit.ui.meeting.DeviceStatsBottomSheet
import live.hms.roomkit.ui.meeting.LEAVE_INFORMATION_PERSON
import live.hms.roomkit.ui.meeting.LEAVE_INFORMATION_REASON
import live.hms.roomkit.ui.meeting.LEAVE_INFROMATION_WAS_END_ROOM
import live.hms.roomkit.ui.settings.SettingsFragment
import live.hms.roomkit.ui.settings.SettingsMode
import live.hms.roomkit.ui.settings.SettingsStore
import live.hms.roomkit.util.EmailUtils
import live.hms.roomkit.util.NameUtils.isValidUserName
import live.hms.roomkit.util.contextSafe
import java.util.UUID

const val SAVED_USER_ID_FOR_BLOCK_LIST = "saved_user_id_blocklist"
const val SETTINGS_FRAGMENT_TAG = "settings"
class HomeFragment : Fragment() {

Expand Down Expand Up @@ -147,11 +147,28 @@ class HomeFragment : Fragment() {
}
}

/**
* This should be a user id that has meaning for your app.
* It might be the userid for your logged in users.
* It should be different per user and always the same for the same user.
* This affects who remains blocked from chat, if this user was blocked.
*/
private fun getConsistentUserIdOverSessions(): String {
val sharedPreferences = requireContext().getSharedPreferences(
"your-activity-preference", Context.MODE_PRIVATE
)
if(sharedPreferences.getString(SAVED_USER_ID_FOR_BLOCK_LIST, null) == null) {
sharedPreferences.edit { putString(SAVED_USER_ID_FOR_BLOCK_LIST, UUID.randomUUID().toString()) }
}
return sharedPreferences.getString(SAVED_USER_ID_FOR_BLOCK_LIST, null)!!
}
private fun launchPrebuilt(code: String) {
contextSafe { _, activity ->

val consistentUserId = getConsistentUserIdOverSessions()

HMSRoomKit.launchPrebuilt(
code, activity, HMSPrebuiltOptions(userName = getUsername(), userId = "random-user-id", debugInfo = settings.inPreBuiltDebugMode,
code, activity, HMSPrebuiltOptions(userName = getUsername(), userId = consistentUserId, debugInfo = settings.inPreBuiltDebugMode,
endPoints = hashMapOf<String, String>().apply {
if (settings.environment.contains("prod").not()) {
put("token", "https://auth-nonprod.100ms.live")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ kotlin.code.style=official
100MS_APP_VERSION_CODE=643
100MS_APP_VERSION_NAME=5.8.872
hmsRoomKitGroup=live.100ms
HMS_ROOM_KIT_VERSION=1.1.4
HMS_ROOM_KIT_VERSION=1.1.5
android.suppressUnsupportedCompileSdk=33
2 changes: 1 addition & 1 deletion room-kit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.percentlayout:percentlayout:1.0.0'

def hmsVersion = "2.8.1"
def hmsVersion = "2.8.2"
// To add dependencies of specific module
implementation "live.100ms:android-sdk:$hmsVersion"
implementation "live.100ms:video-view:$hmsVersion"
Expand Down
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() {

}

})
}

}
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() {

}

})
}

}
Loading

0 comments on commit 671be7f

Please sign in to comment.