新增对话
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package com.aiosman.riderpro
|
||||
|
||||
import android.content.Context
|
||||
import android.icu.util.Calendar
|
||||
import android.icu.util.TimeZone
|
||||
import android.util.Log
|
||||
import com.aiosman.riderpro.data.AccountService
|
||||
import com.aiosman.riderpro.data.AccountServiceImpl
|
||||
import com.aiosman.riderpro.ui.favourite.FavouriteListViewModel
|
||||
import com.aiosman.riderpro.ui.favourite.FavouriteNoticeViewModel
|
||||
import com.aiosman.riderpro.ui.follower.FollowerNoticeViewModel
|
||||
@@ -11,10 +17,68 @@ import com.aiosman.riderpro.ui.index.tabs.profile.MyProfileViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.search.DiscoverViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.search.SearchViewModel
|
||||
import com.aiosman.riderpro.ui.like.LikeNoticeViewModel
|
||||
import com.aiosman.riderpro.utils.Utils
|
||||
import com.tencent.imsdk.v2.V2TIMCallback
|
||||
import com.tencent.imsdk.v2.V2TIMLogListener
|
||||
import com.tencent.imsdk.v2.V2TIMManager
|
||||
import com.tencent.imsdk.v2.V2TIMSDKConfig
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
object AppState {
|
||||
var UserId: Int? = null
|
||||
|
||||
suspend fun initWithAccount(scope: CoroutineScope, context: Context) {
|
||||
val accountService: AccountService = AccountServiceImpl()
|
||||
// 获取用户认证信息
|
||||
val resp = accountService.getMyAccount()
|
||||
// 更新必要的用户信息
|
||||
val calendar: Calendar = Calendar.getInstance()
|
||||
val tz: TimeZone = calendar.timeZone
|
||||
val offsetInMillis: Int = tz.rawOffset
|
||||
accountService.updateUserExtra(
|
||||
Utils.getCurrentLanguage(),
|
||||
// 时区偏移量单位是秒
|
||||
offsetInMillis / 1000,
|
||||
tz.displayName
|
||||
)
|
||||
// 设置当前登录用户 ID
|
||||
UserId = resp.id
|
||||
|
||||
// 注册 JPush
|
||||
Messaging.RegistDevice(scope, context)
|
||||
// 注册 Trtc
|
||||
val config = V2TIMSDKConfig()
|
||||
|
||||
config.logLevel = V2TIMSDKConfig.V2TIM_LOG_INFO
|
||||
|
||||
config.logListener = object : V2TIMLogListener() {
|
||||
override fun onLog(logLevel: Int, logContent: String) {
|
||||
Log.d("V2TIMLogListener", logContent)
|
||||
}
|
||||
}
|
||||
val appConfig = accountService.getAppConfig()
|
||||
V2TIMManager.getInstance().initSDK(context, appConfig.trtcAppId, config)
|
||||
try {
|
||||
val sign = accountService.getMyTrtcSign()
|
||||
V2TIMManager.getInstance().login(
|
||||
sign.userId,
|
||||
sign.sig,
|
||||
object : V2TIMCallback {
|
||||
override fun onError(code: Int, desc: String?) {
|
||||
Log.e("V2TIMManager", "login failed: $code, $desc")
|
||||
}
|
||||
|
||||
override fun onSuccess() {
|
||||
Log.d("V2TIMManager", "login success")
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun ReloadAppState() {
|
||||
// 重置动态列表页面
|
||||
MomentViewModel.ResetModel()
|
||||
|
||||
Reference in New Issue
Block a user