新增聊天消息提醒
This commit is contained in:
40
app/src/main/java/com/aiosman/riderpro/ChatState.kt
Normal file
40
app/src/main/java/com/aiosman/riderpro/ChatState.kt
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user