|
|
@@ -1,14 +1,10 @@
|
|
|
package com.adealink.weparty.room.chat.viewmodel
|
|
|
|
|
|
import android.text.Editable
|
|
|
-import android.text.SpannableStringBuilder
|
|
|
import androidx.lifecycle.LiveData
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
-import com.adealink.frame.aab.util.getCompatString
|
|
|
import com.adealink.frame.base.Rlt
|
|
|
-import com.adealink.frame.data.json.froJsonErrorNull
|
|
|
import com.adealink.frame.data.json.toJsonErrorNull
|
|
|
-import com.adealink.frame.locale.language.languageManager
|
|
|
import com.adealink.frame.log.Log
|
|
|
import com.adealink.frame.mvvm.livedata.ExtLiveData
|
|
|
import com.adealink.frame.mvvm.livedata.ExtMutableLiveData
|
|
|
@@ -18,12 +14,7 @@ import com.adealink.frame.network.ISocketNotify
|
|
|
import com.adealink.frame.network.data.Res
|
|
|
import com.adealink.frame.oss.data.UploadFile
|
|
|
import com.adealink.weparty.App
|
|
|
-import com.adealink.weparty.commonui.text.DataBindingSpanHelper
|
|
|
-import com.adealink.weparty.commonui.text.span.AtUserDataBindingSpan
|
|
|
import com.adealink.weparty.config.GlobalConfigType
|
|
|
-import com.adealink.weparty.config.IGlobalConfigListener
|
|
|
-import com.adealink.weparty.config.globalConfigManager
|
|
|
-import com.adealink.weparty.module.gift.GiftModule
|
|
|
import com.adealink.weparty.module.operation.OperationModule
|
|
|
import com.adealink.weparty.module.profile.ProfileModule
|
|
|
import com.adealink.weparty.module.room.RoomModule
|
|
|
@@ -31,19 +22,13 @@ import com.adealink.weparty.module.room.chat.data.ChatOperate
|
|
|
import com.adealink.weparty.module.room.chat.data.ChatOperateReq
|
|
|
import com.adealink.weparty.module.room.chat.data.ChatOperateRes
|
|
|
import com.adealink.weparty.module.room.chat.data.ChatStatusNotify
|
|
|
-import com.adealink.weparty.module.room.chat.data.EnterNotificationMsgContent
|
|
|
import com.adealink.weparty.module.room.chat.data.Message
|
|
|
-import com.adealink.weparty.module.room.chat.data.MessageType
|
|
|
import com.adealink.weparty.module.room.chat.data.PictureCheckReq
|
|
|
-import com.adealink.weparty.module.room.chat.data.SayHiConfig
|
|
|
-import com.adealink.weparty.module.room.chat.data.SayHiMessageData
|
|
|
-import com.adealink.weparty.module.room.chat.data.TextMsgContent
|
|
|
import com.adealink.weparty.module.room.data.AdminPermissionSettingMap
|
|
|
import com.adealink.weparty.module.room.data.AtMeMessage
|
|
|
import com.adealink.weparty.module.room.data.TAG_BELL_INVITED
|
|
|
import com.adealink.weparty.module.room.viewmodel.IChatMessageViewModel
|
|
|
import com.adealink.weparty.module.room.viewmodel.chat.IAdminPermissionViewModel
|
|
|
-import com.adealink.weparty.room.R
|
|
|
import com.adealink.weparty.room.chat.data.MessageContentCompetitiveWordsError
|
|
|
import com.adealink.weparty.room.chat.data.MessageContentInvalidError
|
|
|
import com.adealink.weparty.room.chat.data.TAG_ROOM_CHAT
|
|
|
@@ -65,7 +50,6 @@ import kotlinx.coroutines.launch
|
|
|
*/
|
|
|
class ChatMessageViewModel : BaseViewModel(),
|
|
|
IChatMessageViewModel,
|
|
|
- IGlobalConfigListener,
|
|
|
IAdminPermissionViewModel {
|
|
|
|
|
|
override val messagesLD: LiveData<List<Message>> = MutableLiveData()
|
|
|
@@ -83,7 +67,6 @@ class ChatMessageViewModel : BaseViewModel(),
|
|
|
val atMeMsgLD = ExtMutableLiveData<AtMeMessage?>()
|
|
|
val historyInputLD = MutableLiveData<Editable?>()
|
|
|
var luckNumberStatusLD: LiveData<String> = MutableLiveData()
|
|
|
- var sayHiConfig: SayHiConfig? = null
|
|
|
|
|
|
private val roomSocketService by lazy {
|
|
|
App.instance.networkService.getSocketService(RoomSocketService::class.java)
|
|
|
@@ -140,7 +123,6 @@ class ChatMessageViewModel : BaseViewModel(),
|
|
|
App.instance.networkService.subscribeNotify(adminRoomPrivilegeNotify)
|
|
|
chatMessageManager.onRoomIn(joinController.getJoinedRoomId())
|
|
|
chatMessageManager.addListener(this)
|
|
|
- globalConfigManager.addListener(GlobalConfigType.GLOBAL_WELCOME_NEW_SAY_HI, this)
|
|
|
}
|
|
|
|
|
|
override fun sendChatMessage(message: Message): LiveData<Rlt<Any>> {
|
|
|
@@ -349,7 +331,6 @@ class ChatMessageViewModel : BaseViewModel(),
|
|
|
App.instance.networkService.unSubscribeNotify(roomClearRoomChatDataNotify)
|
|
|
App.instance.networkService.unSubscribeNotify(adminRoomPrivilegeNotify)
|
|
|
chatMessageManager.removeListener(this)
|
|
|
- globalConfigManager.removeListener(GlobalConfigType.GLOBAL_WELCOME_NEW_SAY_HI, this)
|
|
|
}
|
|
|
|
|
|
override fun onMessageChanged(messages: List<Message>) {
|
|
|
@@ -380,12 +361,6 @@ class ChatMessageViewModel : BaseViewModel(),
|
|
|
return chatMessageManager.getLastAtMeMessage()
|
|
|
}
|
|
|
|
|
|
- fun loadSayHiConfig(forceNet: Boolean) {
|
|
|
- viewModelScope.launch {
|
|
|
- globalConfigManager.getGlobalConfig(forceNet, GlobalConfigType.GLOBAL_WELCOME_NEW_SAY_HI)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
fun loadLuckNumberConfig() {
|
|
|
viewModelScope.launch {
|
|
|
val roomId = RoomModule.getJoinedRoomId() ?: return@launch
|
|
|
@@ -413,71 +388,6 @@ class ChatMessageViewModel : BaseViewModel(),
|
|
|
luckNumberStatusLD.send(luckNumberState)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- fun sayHi(toUid: Long, message: Message) {
|
|
|
- //更新sayHi Message状态
|
|
|
- (message.content as? EnterNotificationMsgContent)?.let { content ->
|
|
|
- content.clickSayHi = true
|
|
|
- chatMessageManager.updateMessage(message)
|
|
|
- }
|
|
|
- //发送sayHi消息
|
|
|
- if (toUid == 0L) {
|
|
|
- Log.d(TAG_ROOM_CHAT, "sayHi return, for toUid is 0")
|
|
|
- return
|
|
|
- }
|
|
|
- viewModelScope.launch {
|
|
|
- val toUserInfo = (ProfileModule.getUserInfoByUid(toUid) as? Rlt.Success)?.data
|
|
|
- if (toUserInfo == null) {
|
|
|
- Log.d(TAG_ROOM_CHAT, "sayHi return, for toUserInfo is null")
|
|
|
- return@launch
|
|
|
- }
|
|
|
- val config = sayHiConfig
|
|
|
- val ssb = SpannableStringBuilder()
|
|
|
- //添加@信息
|
|
|
- ssb.append(
|
|
|
- DataBindingSpanHelper.newSpannable(
|
|
|
- AtUserDataBindingSpan(toUid, toUserInfo.name)
|
|
|
- )
|
|
|
- )
|
|
|
- //添加欢迎语
|
|
|
- ssb.append(
|
|
|
- config?.getContentBy(languageManager?.getLanguageCode()) ?: getCompatString(R.string.room_chat_message_say_hi)
|
|
|
- )
|
|
|
- //添加礼物
|
|
|
- val msgContent = TextMsgContent(ssb.toString()).apply {
|
|
|
- var giftId: Long? = null
|
|
|
- if (!toUserInfo.region.isNullOrEmpty()) {
|
|
|
- giftId = config?.regionGifts?.get(toUserInfo.region)?.randomOrNull()
|
|
|
- }
|
|
|
- if (giftId != null) {
|
|
|
- (GiftModule.getGift(giftId) as? Rlt.Success)?.let {
|
|
|
- it.data?.let { info ->
|
|
|
- sayHiGifts = listOf(SayHiMessageData(toUid, giftId, info.iconUrl))
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //检查是否有数据绑定的Span信息
|
|
|
- msgContent.fillDataBindingSpansBy(ssb)
|
|
|
- sendChatMessage(
|
|
|
- Message.crateMessage(
|
|
|
- MessageType.TEXT,
|
|
|
- msgContent
|
|
|
- )
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onConfigGet(configType: GlobalConfigType, config: List<String>) {
|
|
|
- if (configType == GlobalConfigType.GLOBAL_WELCOME_NEW_SAY_HI) {
|
|
|
- val configJson = config.firstOrNull()
|
|
|
- if (!configJson.isNullOrEmpty()) {
|
|
|
- sayHiConfig = froJsonErrorNull(configJson, SayHiConfig::class.java)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
override fun clearRoomChat(): LiveData<Rlt<Boolean>> {
|
|
|
val liveData = OnceMutableLiveData<Rlt<Boolean>>()
|
|
|
viewModelScope.launch {
|