更新个人资料同时更新聊天个人信息

This commit is contained in:
2024-11-30 22:24:28 +08:00
parent 3a68a51f3c
commit 6c19f83cfb
5 changed files with 35 additions and 3 deletions

View File

@@ -103,7 +103,7 @@ object AppState {
val profile = accountService.getMyAccountProfile() val profile = accountService.getMyAccountProfile()
val info = V2TIMUserFullInfo() val info = V2TIMUserFullInfo()
info.setNickname(profile.nickName) info.setNickname(profile.nickName)
info.faceUrl = profile.avatar info.faceUrl = profile.rawAvatar
info.selfSignature = profile.bio info.selfSignature = profile.bio
return suspendCoroutine { continuation -> return suspendCoroutine { continuation ->
V2TIMManager.getInstance().setSelfInfo(info, object : V2TIMCallback { V2TIMManager.getInstance().setSelfInfo(info, object : V2TIMCallback {

View File

@@ -72,7 +72,8 @@ data class AccountProfile(
} }
null null
}, },
trtcUserId = trtcUserId trtcUserId = trtcUserId,
rawAvatar = avatar
) )
} }
} }

View File

@@ -61,6 +61,7 @@ data class AccountProfileEntity(
val banner: String?, val banner: String?,
// trtcUserId // trtcUserId
val trtcUserId: String, val trtcUserId: String,
val rawAvatar: String
) )
/** /**

View File

@@ -12,6 +12,7 @@ import com.aiosman.ravenow.data.AccountServiceImpl
import com.aiosman.ravenow.data.UploadImage import com.aiosman.ravenow.data.UploadImage
import com.aiosman.ravenow.entity.AccountProfileEntity import com.aiosman.ravenow.entity.AccountProfileEntity
import com.aiosman.ravenow.ui.index.tabs.profile.MyProfileViewModel import com.aiosman.ravenow.ui.index.tabs.profile.MyProfileViewModel
import com.aiosman.ravenow.utils.TrtcHelper
import java.io.File import java.io.File
object AccountEditViewModel : ViewModel() { object AccountEditViewModel : ViewModel() {
@@ -22,13 +23,20 @@ object AccountEditViewModel : ViewModel() {
var profile by mutableStateOf<AccountProfileEntity?>(null) var profile by mutableStateOf<AccountProfileEntity?>(null)
var croppedBitmap by mutableStateOf<Bitmap?>(null) var croppedBitmap by mutableStateOf<Bitmap?>(null)
var isUpdating by mutableStateOf(false) var isUpdating by mutableStateOf(false)
suspend fun reloadProfile() { suspend fun reloadProfile(updateTrtcProfile:Boolean = false) {
accountService.getMyAccountProfile().let { accountService.getMyAccountProfile().let {
profile = it profile = it
name = it.nickName name = it.nickName
bio = it.bio bio = it.bio
if (updateTrtcProfile) {
TrtcHelper.updateTrtcProfile(
it.nickName,
it.rawAvatar
)
} }
} }
}
suspend fun updateUserProfile(context: Context) { suspend fun updateUserProfile(context: Context) {
val newAvatar = croppedBitmap?.let { val newAvatar = croppedBitmap?.let {

View File

@@ -1,6 +1,8 @@
package com.aiosman.ravenow.utils package com.aiosman.ravenow.utils
import com.tencent.imsdk.v2.V2TIMCallback
import com.tencent.imsdk.v2.V2TIMManager import com.tencent.imsdk.v2.V2TIMManager
import com.tencent.imsdk.v2.V2TIMUserFullInfo
import com.tencent.imsdk.v2.V2TIMValueCallback import com.tencent.imsdk.v2.V2TIMValueCallback
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
@@ -19,4 +21,24 @@ object TrtcHelper {
}); });
} }
} }
suspend fun updateTrtcProfile(
avatar: String?,
nickName: String?
) {
val info = V2TIMUserFullInfo()
nickName?.let { info.setNickname(it) }
avatar?.let { info.faceUrl = it }
return suspendCoroutine { continuation ->
V2TIMManager.getInstance().setSelfInfo(info, object : V2TIMCallback {
override fun onError(code: Int, desc: String?) {
continuation.resumeWith(Result.failure(Exception("Error $code: $desc")))
}
override fun onSuccess() {
continuation.resumeWith(Result.success(Unit))
}
})
}
}
} }