Ai和用户类型分组验证
This commit is contained in:
@@ -115,7 +115,7 @@ fun MineAgent() {
|
||||
val agentItem = agentList[idx]
|
||||
AgentCard(agentEntity = agentItem,
|
||||
onClick = {
|
||||
//model.createSingleChat(agentItem.openId)
|
||||
model.createSingleChat(agentItem.openId)
|
||||
model.goToChatAi(agentItem.openId,navController)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -14,6 +14,13 @@ import com.aiosman.ravenow.entity.AgentEntity
|
||||
import com.aiosman.ravenow.ui.index.tabs.message.Conversation
|
||||
import com.aiosman.ravenow.ui.index.tabs.message.MessageListViewModel.userService
|
||||
import com.aiosman.ravenow.ui.navigateToChat
|
||||
import com.aiosman.ravenow.ui.navigateToChatAi
|
||||
import com.tencent.imsdk.v2.V2TIMConversation
|
||||
import com.tencent.imsdk.v2.V2TIMConversationListFilter
|
||||
import com.tencent.imsdk.v2.V2TIMConversationOperationResult
|
||||
import com.tencent.imsdk.v2.V2TIMConversationResult
|
||||
import com.tencent.imsdk.v2.V2TIMManager
|
||||
import com.tencent.imsdk.v2.V2TIMValueCallback
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
@@ -96,12 +103,60 @@ object MineAgentViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun createSingleChat(
|
||||
fun createGroup2ChatAi(
|
||||
trtcUserId: String,
|
||||
groupName: String
|
||||
) {
|
||||
val conversationIDList = listOf("c2c_${trtcUserId}")
|
||||
|
||||
V2TIMManager.getConversationManager().createConversationGroup(
|
||||
groupName,
|
||||
conversationIDList,
|
||||
object : V2TIMValueCallback<List<V2TIMConversationOperationResult>> {
|
||||
override fun onSuccess(v2TIMConversationOperationResults: List<V2TIMConversationOperationResult>) {
|
||||
// 创建会话分组成功
|
||||
}
|
||||
|
||||
override fun onError(code: Int, desc: String) {
|
||||
// 创建会话分组失败
|
||||
}
|
||||
}
|
||||
)
|
||||
V2TIMManager.getConversationManager().getConversationGroupList(object : V2TIMValueCallback<List<String>> {
|
||||
override fun onSuccess(v2TIMConversationOperationResults: List<String>) {
|
||||
// 获取会话分组列表成功
|
||||
}
|
||||
|
||||
override fun onError(code: Int, desc: String?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
})
|
||||
val filter = V2TIMConversationListFilter()
|
||||
filter.conversationGroup = "ai_group"
|
||||
|
||||
V2TIMManager.getConversationManager().getConversationListByFilter(
|
||||
filter,
|
||||
1000,
|
||||
10000,
|
||||
object : V2TIMValueCallback<V2TIMConversationResult> {
|
||||
override fun onSuccess(v2TIMConversationResult: V2TIMConversationResult) {
|
||||
// 获取会话列表成功
|
||||
}
|
||||
|
||||
override fun onError(code: Int, desc: String) {
|
||||
// 获取会话列表失败
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fun createSingleChat(
|
||||
openId: String,
|
||||
): String {
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val response = ApiClient.api.createSingleChat(SingleChatRequestBody(generateText = openId))
|
||||
val body = response.body()?.data ?: throw ServiceException("Failed to create single chat")
|
||||
return body.toString()
|
||||
}
|
||||
|
||||
}
|
||||
fun goToChatAi(
|
||||
@@ -110,7 +165,8 @@ object MineAgentViewModel : ViewModel() {
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val profile = userService.getUserProfileByOpenId(openId)
|
||||
navController.navigateToChat(profile.id.toString())
|
||||
createGroup2ChatAi(profile.trtcUserId,"ai_group")
|
||||
navController.navigateToChatAi(profile.id.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user