新增聊天消息提醒

This commit is contained in:
2024-10-11 16:51:51 +08:00
parent 36739b1615
commit 81f90db1b1
15 changed files with 414 additions and 105 deletions

View File

@@ -0,0 +1,40 @@
package com.aiosman.riderpro
import com.aiosman.riderpro.data.ChatService
import com.aiosman.riderpro.data.ChatServiceImpl
import com.aiosman.riderpro.entity.ChatNotification
/**
* 保存一些关于聊天的状态
*/
object ChatState {
val chatService: ChatService = ChatServiceImpl()
var chatNotificationList = mutableListOf<ChatNotification>()
suspend fun getStrategyByTargetTrtcId(targetTrtcId: String): ChatNotification? {
// 先从缓存中查找
if (chatNotificationList.isNotEmpty()) {
chatNotificationList.forEach {
if (it.targetTrtcId == targetTrtcId) {
return it
}
}
}
// 缓存中没有再从网络获取
chatService.getChatNotifications(targetTrtcId)?.let {
chatNotificationList.add(it)
return it
}
// 存在未设置策略的情况
return null
}
suspend fun updateChatNotification(targetUserId: Int, strategy: String): ChatNotification {
val updatedData = chatService.updateChatNotification(targetUserId, strategy)
chatNotificationList = chatNotificationList.filter {
it.targetUserId != targetUserId
}.toMutableList().apply {
add(updatedData)
}
return updatedData
}
}