Ai和用户类型分组验证

This commit is contained in:
weber
2025-08-08 18:53:10 +08:00
parent 1bb0adeb90
commit 54ca1d3f1c
6 changed files with 95 additions and 30 deletions

View File

@@ -43,6 +43,16 @@ data class SingleChatRequestBody(
val generateText: String,
)
data class SendChatAiRequestBody(
@SerializedName("fromTrtcUserId")
val fromTrtcUserId: String,
@SerializedName("toTrtcUserId")
val toTrtcUserId: String,
@SerializedName("message")
val message: String,
)
data class LoginUserRequestBody(
@SerializedName("username")
val username: String? = null,
@@ -512,6 +522,9 @@ interface RaveNowAPI {
@POST("outside/rooms/create-single-chat")
suspend fun createSingleChat(@Body body: SingleChatRequestBody): Response<DataContainer<Unit>>
@POST("outside/rooms/message")
suspend fun sendChatAiMessage(@Body body: SendChatAiRequestBody): Response<DataContainer<Unit>>

View File

@@ -472,9 +472,9 @@ fun NavHostController.navigateToChat(id: String) {
)
}
fun NavHostController.navigateToChatnavigateToChatAi(id: String) {
fun NavHostController.navigateToChatAi(id: String) {
navigate(
route = NavigationRoute.Chat.route
route = NavigationRoute.ChatAi.route
.replace("{id}", id)
)
}

View File

@@ -93,10 +93,10 @@ fun ChatAiScreen(userId: String) {
val AppColors = LocalAppTheme.current
var goToNewCount by remember { mutableStateOf(0) }
val viewModel = viewModel<ChatAiViewModel>(
key = "ChatViewModel_$userId",
key = "ChatAiViewModel_$userId",
factory = object : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return ChatViewModel(userId) as T
return ChatAiViewModel(userId) as T
}
}
)
@@ -254,7 +254,7 @@ fun ChatAiScreen(userId: String) {
AppColors.decentBackground)
)
Spacer(modifier = Modifier.height(8.dp))
ChatInput(
ChatAiInput(
onSendImage = {
it?.let {
viewModel.sendImageMessage(it, context)
@@ -298,7 +298,7 @@ fun ChatAiScreen(userId: String) {
)
}
ChatItem(item = item, viewModel.myProfile?.trtcUserId!!)
ChatAiItem(item = item, viewModel.myProfile?.trtcUserId!!)
}
@@ -593,24 +593,6 @@ fun ChatAiInput(
)
)
}
Spacer(modifier = Modifier.width(16.dp))
Icon(
painter = painterResource(id = R.drawable.rider_pro_camera),
contentDescription = "Emoji",
modifier = Modifier
.size(30.dp)
.noRippleClickable {
imagePickUpLauncher.launch(
Intent.createChooser(
Intent(Intent.ACTION_GET_CONTENT).apply {
type = "image/*"
},
"Select Image"
)
)
},
tint = appColors.chatActionColor
)
Spacer(modifier = Modifier.width(8.dp))
Crossfade(
targetState = text.isNotEmpty(), animationSpec = tween(500),

View File

@@ -15,6 +15,9 @@ import com.aiosman.ravenow.data.AccountService
import com.aiosman.ravenow.data.AccountServiceImpl
import com.aiosman.ravenow.data.UserService
import com.aiosman.ravenow.data.UserServiceImpl
import com.aiosman.ravenow.data.api.ApiClient
import com.aiosman.ravenow.data.api.SendChatAiRequestBody
import com.aiosman.ravenow.data.api.SingleChatRequestBody
import com.aiosman.ravenow.entity.AccountProfileEntity
import com.aiosman.ravenow.entity.ChatItem
import com.aiosman.ravenow.entity.ChatNotification
@@ -147,6 +150,7 @@ class ChatAiViewModel(
override fun onSuccess(p0: V2TIMMessage?) {
Log.d("ChatViewModel", "send message success")
sendChatAiMessage(myProfile?.trtcUserId!!,userProfile?.trtcUserId!!, message)
val chatItem = ChatItem.convertToChatItem(p0!!, context, avatar = myProfile?.avatar)
chatItem?.let {
chatData = listOf(it) + chatData
@@ -250,6 +254,16 @@ class ChatAiViewModel(
}
)
}
fun sendChatAiMessage(
fromTrtcUserId: String,
toTrtcUserId: String,
message: String,
) {
viewModelScope.launch {
val response = ApiClient.api.sendChatAiMessage(SendChatAiRequestBody(fromTrtcUserId = fromTrtcUserId,toTrtcUserId = toTrtcUserId,message = message))
}
}
fun getDisplayChatList(): List<ChatItem> {
val list = chatData

View File

@@ -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)
})
}

View File

@@ -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())
}
}
}