imsdk 调通

This commit is contained in:
2025-09-09 19:05:07 +08:00
parent e00deb5661
commit ce6ee7bf82
6 changed files with 28 additions and 15 deletions

View File

@@ -67,8 +67,13 @@ object AppState {
)
// 设置当前登录用户 ID
UserId = resp.id
var profileResult = accountService.getMyAccountProfile()
profile = profileResult
try {
var profileResult = accountService.getMyAccountProfile()
profile = profileResult
} catch (e:Exception) {
Log.e("AppState", "getMyAccountProfile Error:"+ e.message )
}
// 获取当前用户资料
// 注册 JPush

View File

@@ -430,9 +430,17 @@ interface AccountService {
class AccountServiceImpl : AccountService {
override suspend fun getMyAccountProfile(): AccountProfileEntity {
// 如果已有缓存,直接返回缓存结果
AppState.profile?.let { return it }
// 第一次调用,获取数据并缓存
val resp = ApiClient.api.getMyAccount()
val body = resp.body() ?: throw ServiceException("Failed to get account")
return body.data.toAccountProfileEntity()
val profile = body.data.toAccountProfileEntity()
// 缓存结果到共享状态
AppState.profile = profile
return profile
}
override suspend fun getMyAccount(): UserAuth {

View File

@@ -174,7 +174,7 @@ class ChatAiViewModel(
}
val textMessage = OpenIMClient.getInstance().messageManager.createTextMessage(message)
val conversationID = "single_${userProfile?.trtcUserId!!}"
OpenIMClient.getInstance().messageManager.sendMessage(
object : OnMsgSendCallback {
override fun onProgress(progress: Long) {
@@ -199,9 +199,9 @@ class ChatAiViewModel(
}
},
textMessage,
userProfile?.trtcUserId!!, // recvID
userProfile!!.trtcUserId,
null, // groupID
null // offlinePushInfo
OfflinePushInfo() // offlinePushInfo
)
}
fun createGroup2ChatAi(
@@ -242,7 +242,7 @@ class ChatAiViewModel(
imageMessage,
userProfile?.trtcUserId!!, // recvID
null, // groupID
null // offlinePushInfo
OfflinePushInfo() // offlinePushInfo
)
}
}
@@ -304,7 +304,7 @@ class ChatAiViewModel(
Log.e("ChatAiViewModel", "fetch history message error: $error")
}
},
conversationID,
userProfile!!.trtcUserId,
lastMessage,
20,
ViewType.History

View File

@@ -164,7 +164,7 @@ class ChatViewModel(
android.util.Log.w("ChatViewModel", "OpenIM 未登录,无法发送消息")
return
}
val textMessage = OpenIMClient.getInstance().messageManager.createTextMessage(message)
OpenIMClient.getInstance().messageManager.sendMessage(
@@ -191,7 +191,7 @@ class ChatViewModel(
textMessage,
userProfile?.trtcUserId!!, // recvID
null, // groupID
null // offlinePushInfo
OfflinePushInfo() // offlinePushInfo
)
}
@@ -225,7 +225,7 @@ class ChatViewModel(
imageMessage,
userProfile?.trtcUserId!!, // recvID
null, // groupID
null // offlinePushInfo
OfflinePushInfo() // offlinePushInfo
)
}
}

View File

@@ -203,7 +203,7 @@ class GroupChatViewModel(
textMessage,
null, // recvID (群聊为 null)
groupId, // groupID
null // offlinePushInfo
OfflinePushInfo() // offlinePushInfo
)
}
@@ -248,7 +248,7 @@ class GroupChatViewModel(
imageMessage,
null, // recvID (群聊为 null)
groupId, // groupID
null // offlinePushInfo
OfflinePushInfo() // offlinePushInfo
)
}
}