添加Chat处理逻辑

This commit is contained in:
2024-12-06 10:57:31 +08:00
parent cc7a65e016
commit 76e7bbb84a
6 changed files with 85 additions and 44 deletions

View File

@@ -10,6 +10,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.aiosman.ravenow.data.AccountService
import com.aiosman.ravenow.data.AccountServiceImpl
import com.aiosman.ravenow.data.DictService
import com.aiosman.ravenow.data.DictServiceImpl
import com.aiosman.ravenow.entity.AccountProfileEntity
import com.aiosman.ravenow.ui.favourite.FavouriteListViewModel
import com.aiosman.ravenow.ui.favourite.FavouriteNoticeViewModel
@@ -40,6 +42,7 @@ object AppState {
var appTheme by mutableStateOf<AppThemeData>(LightThemeColors())
var googleClientId: String? = null
var enableGoogleLogin: Boolean = false
var enableChat = false
suspend fun initWithAccount(scope: CoroutineScope, context: Context) {
val accountService: AccountService = AccountServiceImpl()
// 获取用户认证信息
@@ -62,6 +65,19 @@ object AppState {
// 注册 JPush
Messaging.registerDevice(scope, context)
initChat(context)
}
private suspend fun initChat(context: Context){
val dictService :DictService = DictServiceImpl()
val enableItem = dictService.getDictByKey(ConstVars.DICT_KEY_ENABLE_TRTC)
val isEnableTrtc = enableItem.value as? Boolean
if (isEnableTrtc != true) {
enableChat = false
return
}
val accountService: AccountService = AccountServiceImpl()
// 注册 Trtc
val config = V2TIMSDKConfig()
@@ -82,8 +98,10 @@ object AppState {
context.startService(
Intent(context, TrtcService::class.java)
)
enableChat = true
} catch (e: Exception) {
e.printStackTrace()
enableChat = false
}
}
@@ -93,7 +111,6 @@ object AppState {
override fun onError(code: Int, desc: String?) {
continuation.resumeWith(Result.failure(Exception("Login failed: $code, $desc")))
}
override fun onSuccess() {
continuation.resumeWith(Result.success(true))
}