Bladeren bron

feat: 修改好友备注接口

wutiaorong 1 jaar geleden
bovenliggende
commit
c2a3e69dbf

+ 3 - 2
app/src/main/java/com/adealink/weparty/im/IMConfig.kt

@@ -11,6 +11,7 @@ import com.adealink.frame.util.AppUtil
 import com.adealink.weparty.App
 import com.adealink.weparty.commonui.ext.onSuccess
 import com.adealink.weparty.module.profile.ProfileModule
+import com.adealink.weparty.module.profile.view.UserNameTextView.Companion.getDisplayName
 import com.adealink.weparty.module.webview.Web
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.launch
@@ -41,7 +42,7 @@ class IMConfig: IIMConfig {
                         userInfoRlt.onSuccess {
                             App.instance.imService.refreshUserInfo(IMUserInfo(
                                 id = it.uid.toString(),
-                                name = it.name,
+                                name = getDisplayName(it.uid, it.name),
                                 avatarUrl = it.url
                             ))
                         }
@@ -50,7 +51,7 @@ class IMConfig: IIMConfig {
                 }
                 return IMUserInfo(
                     id = userInfo.uid.toString(),
-                    name = userInfo.name,
+                    name = getDisplayName(userInfo.uid, userInfo.name),
                     avatarUrl = userInfo.url
                 )
             }

+ 3 - 1
app/src/main/java/com/adealink/weparty/module/profile/data/ProfileConstants.kt

@@ -11,4 +11,6 @@ const val TAB_INDEX_MOMENT = 2
 const val TAB_INDEX_RELATION = 3
 
 
-const val TAB_NAME_CP = "cp"
+const val TAB_NAME_CP = "cp"
+
+const val QUERY_NOTE_PAGE_SIZE = 3000

+ 16 - 1
app/src/main/java/com/adealink/weparty/module/profile/data/ProfileData2.kt

@@ -829,7 +829,6 @@ data class UserRelationShipReq(
     @SerializedName("extraParam") val extraParam: String? = null,
 )
 
-
 @Parcelize
 @JsonAdapter(ExtReflectiveTypeAdapterFactory::class)
 data class InspectingMapData(
@@ -837,4 +836,20 @@ data class InspectingMapData(
     @SerializedName("voiceIntroduction") val voiceIntroduction: String,
 ) : Parcelable
 
+@JsonAdapter(ExtReflectiveTypeAdapterFactory::class)
+data class BatchGetRemarkReq(
+    @SerializedName("pageNum") val pageNum: Int,
+    @SerializedName("pageSize") val pageSize: Int,
+)
 
+@JsonAdapter(ExtReflectiveTypeAdapterFactory::class)
+data class BatchGetRemarkRes(
+    @SerializedName("uid2RemarkMap") val uid2RemarkMap: Map<Long, String>,
+)
+
+@JsonAdapter(ExtReflectiveTypeAdapterFactory::class)
+data class AddRemarkAndDescReq(
+    @SerializedName("desc") val desc: String? = null,
+    @SerializedName("remark") val remark: String? = null,
+    @SerializedName("uid") val peerUid: Long
+)

+ 2 - 0
app/src/main/java/com/adealink/weparty/module/profile/viewmodel/IProfileViewModel.kt

@@ -71,4 +71,6 @@ interface IProfileViewModel {
     suspend fun getUserCoverList(userInfo: UserInfo?): List<String>
 
     fun updateUserNoteName(uid: Long, note: String): LiveData<Rlt<Any>>
+
+    fun updateUserDesc(uid: Long, desc: String): LiveData<Rlt<Any>>
 }

+ 18 - 6
frame/imkit/src/main/java/com/adealink/frame/imkit/conversation/messagelist/provider/RichContentMessageItemProvider.kt

@@ -2,6 +2,7 @@ package com.adealink.frame.imkit.conversation.messagelist.provider
 
 import android.text.Spannable
 import android.text.SpannableString
+import android.text.TextUtils
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
@@ -12,8 +13,6 @@ import com.adealink.frame.imkit.model.UiMessage
 import com.adealink.frame.imkit.widget.adapter.IViewProviderListener
 import com.adealink.frame.imkit.widget.adapter.ViewHolder
 import com.adealink.frame.imkit.R
-import com.adealink.frame.imkit.model.TAG_IM_MSG_PROVIDER
-import com.adealink.frame.imkit.utils.LogUtil
 import io.rong.imlib.model.MessageContent
 import io.rong.message.RichContentMessage
 
@@ -39,13 +38,14 @@ class RichContentMessageItemProvider : BaseMessageItemProvider<RichContentMessag
         listener: IViewProviderListener<UiMessage>
     ) {
         val img = holder.getView<NetworkImageView>(R.id.im_img)
-        if (!checkViewsValid(img)) {
-            LogUtil.e(TAG_IM_MSG_PROVIDER, "checkViewsValid error," + uiMessage.objectName)
-            return
+        if (richContentMessage.imgUrl.isNullOrEmpty()) {
+            img?.visibility = View.GONE
+        } else {
+            img?.visibility = View.VISIBLE
+            img?.setImageUrl(richContentMessage.imgUrl)
         }
         holder.setText(R.id.im_title, richContentMessage.title)
         holder.setText(R.id.im_content, richContentMessage.content)
-        img?.setImageUrl(richContentMessage.imgUrl)
     }
 
     override fun onItemClick(
@@ -67,6 +67,18 @@ class RichContentMessageItemProvider : BaseMessageItemProvider<RichContentMessag
     override fun getSummarySpannable(
         richContentMessage: RichContentMessage
     ): Spannable {
+        if (richContentMessage.imgUrl.isNullOrEmpty()) {
+            if (!TextUtils.isEmpty(richContentMessage.content)) {
+                var content = richContentMessage.content
+                content = content.replace("\n", " ")
+                if (content.length > 100) {
+                    content = content.substring(0, 100)
+                }
+                return SpannableString(content)
+            } else {
+                return SpannableString("")
+            }
+        }
         return SpannableString(
             getCompatString(R.string.rc_conversation_summary_content_rich_text)
         )

+ 5 - 0
frame/imkit/src/main/java/com/adealink/frame/imkit/conversationlist/provider/BaseConversationProvider.kt

@@ -143,6 +143,11 @@ open class BaseConversationProvider : IViewProvider<BaseUiConversation> {
             listener?.onViewClick(ConversationClickType.PIN_CLICK, uiConversation)
         }
         //已读按钮
+        if (uiConversation.conversation.receivedStatus.isRead) {
+            holder.setVisible(R.id.im_read_btn, false)
+        } else {
+            holder.setVisible(R.id.im_read_btn, true)
+        }
         holder.setOnClickListener(R.id.im_read_btn) {
             listener?.onViewClick(ConversationClickType.READ_CLICK, uiConversation)
         }

+ 27 - 0
frame/imkit/src/main/java/com/adealink/frame/imkit/conversationlist/viewmodel/ConversationListViewModel.kt

@@ -36,6 +36,7 @@ import io.rong.imlib.IRongCoreCallback
 import io.rong.imlib.IRongCoreEnum
 import io.rong.imlib.RongIMClient
 import io.rong.imlib.model.Conversation
+import io.rong.imlib.model.ConversationIdentifier
 import io.rong.imlib.model.ConversationStatus
 import io.rong.imlib.model.Message
 import io.rong.message.ReadReceiptMessage
@@ -592,6 +593,14 @@ open class ConversationListViewModel : BaseViewModel(),
     }
 
     fun deleteConversation(data: BaseUiConversation) {
+        //删除会话同时要取消置顶
+        val cId = data.conversationIdentifier?: return
+        IMService.innerService
+            .setConversationToTop(
+                cId,
+                false,
+                null
+            )
         IMService.innerService
             .removeConversation(
                 data.conversation.conversationType,
@@ -703,6 +712,24 @@ open class ConversationListViewModel : BaseViewModel(),
         }
     }
 
+    fun readAllUnreadConversation() {
+        IMService.innerService.getUnreadConversationList(
+            object : IRongCoreCallback.ResultCallback<List<Conversation>>() {
+                override fun onSuccess(conversations: List<Conversation>) {
+                    for (conversation in conversations) {
+                        IMService.innerService.clearMessagesUnreadStatus(conversation.conversationType, conversation.targetId, null)
+                    }
+                }
+
+                override fun onError(e: IRongCoreEnum.CoreErrorCode?) {
+
+                }
+
+            },
+            *IMConfigCenter.conversationListConfig.getDataProcessor().supportedTypes()
+        )
+    }
+
     private inner class GetConversationListRunnable(
         private val viewModel: ConversationListViewModel,
         val loadMore: Boolean,

+ 1 - 1
frame/imkit/src/main/res/layout/im_item_rich_content_message.xml

@@ -12,6 +12,7 @@
         android:layout_width="match_parent"
         android:layout_height="120dp"
         android:scaleType="fitXY"
+        android:visibility="gone"
         app:layout_constraintTop_toTopOf="parent" />
 
     <TextView
@@ -41,7 +42,6 @@
         android:background="@android:color/transparent"
         android:ellipsize="end"
         android:gravity="start"
-        android:lines="3"
         android:paddingBottom="12dp"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"

+ 13 - 15
module/message/src/main/java/com/adealink/weparty/message/MessageHomeFragment.kt

@@ -2,6 +2,8 @@ package com.adealink.weparty.message
 
 import androidx.core.view.updateLayoutParams
 import androidx.fragment.app.Fragment
+import androidx.fragment.app.activityViewModels
+import androidx.fragment.app.viewModels
 import com.adealink.frame.aab.util.getCompatString
 import com.adealink.frame.mvvm.view.viewBinding
 import com.adealink.frame.router.annotation.RouterUri
@@ -11,6 +13,7 @@ import com.adealink.weparty.commonui.BaseFragment
 import com.adealink.weparty.commonui.recycleview.adapter.BaseTabFragmentStateAdapter
 import com.adealink.weparty.commonui.widget.CommonDialog
 import com.adealink.weparty.commonui.widget.EmptyFragment
+import com.adealink.weparty.message.conversationlist.viewmodel.WeConversationListViewModel
 import com.adealink.weparty.message.databinding.FragmentMessageHomeBinding
 import com.adealink.weparty.message.data.MessageHomeTabType
 import com.adealink.weparty.message.datasource.remote.MessageLocalService
@@ -19,8 +22,8 @@ import com.adealink.weparty.R as APP_R
 
 @RouterUri(path = [Message.Home.PATH], desc = "消息首页")
 class MessageHomeFragment : BaseFragment(R.layout.fragment_message_home) {
-
     private val binding by viewBinding(FragmentMessageHomeBinding::bind)
+    private val conversationListViewModel by activityViewModels<WeConversationListViewModel>()
 
     override fun initViews() {
         super.initViews()
@@ -39,20 +42,15 @@ class MessageHomeFragment : BaseFragment(R.layout.fragment_message_home) {
 
         //增加一键已读二次提醒弹窗(仅在首次操作时出现)
         binding.btnClearUnreadMsg.onClick(5000) {
-            if (MessageLocalService.showClearMessageAllTips) {
-                MessageLocalService.showClearMessageAllTips = false
-                CommonDialog.Builder()
-                    .message(getCompatString(R.string.message_clear_all_tips))
-                    .onPositive {
-                        //TODO wtr 一键已读
-                    }
-                    .positiveText(getCompatString(APP_R.string.common_yes))
-                    .negativeText(getCompatString(APP_R.string.common_no))
-                    .build()
-                    .show(childFragmentManager)
-            } else {
-
-            }
+            CommonDialog.Builder()
+                .message(getCompatString(R.string.message_clear_all_tips))
+                .onPositive {
+                    conversationListViewModel.readAllUnreadConversation()
+                }
+                .positiveText(getCompatString(APP_R.string.common_yes))
+                .negativeText(getCompatString(APP_R.string.common_no))
+                .build()
+                .show(childFragmentManager)
         }
     }
 

+ 1 - 5
module/message/src/main/java/com/adealink/weparty/message/datasource/remote/MessageLocalService.kt

@@ -3,7 +3,6 @@ package com.adealink.weparty.message.datasource.remote
 import android.content.Context
 import com.adealink.frame.storage.sp.TypeDelegationPrefs
 import com.adealink.frame.util.AppUtil
-import com.adealink.weparty.module.level.data.SVIP_CHAT_DEFAULT_BG_DEFAULT
 import com.adealink.weparty.module.profile.ProfileModule
 
 /**
@@ -19,8 +18,5 @@ object MessageLocalService : TypeDelegationPrefs(
         ProfileModule.getMyUid().toString()
     }
 ) {
-    var showClearMessageAllTips: Boolean by PrefUserKey(
-        "key_show_clear_message_all_tips",
-        true
-    ) // 是否显示清空消息提示
+
 }

+ 23 - 8
module/profile/src/main/java/com/adealink/weparty/profile/datasource/ProfileHttpService.kt

@@ -4,6 +4,9 @@ import com.adealink.frame.base.AppBaseInfo
 import com.adealink.frame.base.Rlt
 import com.adealink.frame.network.data.Res
 import com.adealink.frame.util.PackageUtil
+import com.adealink.weparty.module.profile.data.AddRemarkAndDescReq
+import com.adealink.weparty.module.profile.data.BatchGetRemarkReq
+import com.adealink.weparty.module.profile.data.BatchGetRemarkRes
 import com.adealink.weparty.module.profile.data.BatchGetUserRelationShipReq
 import com.adealink.weparty.module.profile.data.CheckLadyPrivilegeRes
 import com.adealink.weparty.module.profile.data.GetCountryConfigReq
@@ -124,7 +127,10 @@ interface ProfileHttpService {
     suspend fun likePhoto(@Body req: LikePhotoReq): Rlt<Res<Any>>
 
     @GET("user/getUserLikePhotoList")
-    suspend fun likeYouList(@Query("currentPage") page: Long, @Query("pageSize") size: Long): Rlt<Res<LikePhotoRecordRes>>
+    suspend fun likeYouList(
+        @Query("currentPage") page: Long,
+        @Query("pageSize") size: Long
+    ): Rlt<Res<LikePhotoRecordRes>>
 
     //拉取未读点赞数和点赞总数
     @GET("user/getLikePhotoInfo")
@@ -154,15 +160,13 @@ interface ProfileHttpService {
     @GET("config/getUserPrivilege")
     suspend fun getUserPrivilegeForChangeRoomCover(): Rlt<Res<UserPrivilegeInfo>>
 
-    /**
-     *  获取用户备注名数据
-     */
     @POST("user/getRelationShipInfoListByUid")
-    suspend fun getRelationShipInfoListByUid(@Body req: BatchGetUserRelationShipReq = BatchGetUserRelationShipReq(RelationshipType.NOTE_NAME.type)): Rlt<Res<List<UserRelationShipInfo>>>
+    suspend fun getRelationShipInfoListByUid(
+        @Body req: BatchGetUserRelationShipReq = BatchGetUserRelationShipReq(
+            RelationshipType.NOTE_NAME.type
+        )
+    ): Rlt<Res<List<UserRelationShipInfo>>>
 
-    /**
-     *  添加用户备注名
-     */
     @POST("user/buildRelationShip")
     suspend fun buildRelationShip(@Body req: UserRelationShipReq): Rlt<Res<Any>>
 
@@ -172,4 +176,15 @@ interface ProfileHttpService {
     @GET("config/job_tree")
     suspend fun getJobTree(): Rlt<Res<List<JobInfo>>>
 
+    /**
+     *  分页获取用户备注名数据
+     */
+    @POST("user/remark/page_query")
+    suspend fun queryUserRemark(@Body req: BatchGetRemarkReq): Rlt<Res<BatchGetRemarkRes>>
+
+    /**
+     *  添加备注和描述
+     */
+    @POST("user/remark/add")
+    suspend fun addUserRemark(@Body req: AddRemarkAndDescReq): Rlt<Res<Any>>
 }

+ 2 - 0
module/profile/src/main/java/com/adealink/weparty/profile/manager/IProfileManager.kt

@@ -72,5 +72,7 @@ interface IProfileManager : IBaseFrame<IProfileListener> {
 
     suspend fun updateUserNoteName(uid: Long, note: String): Rlt<Any>
 
+    suspend fun updateUserDesc(uid: Long, desc: String): Rlt<Any>
+
     suspend fun getJobTree(): Rlt<List<JobInfo>>
 }

+ 44 - 19
module/profile/src/main/java/com/adealink/weparty/profile/manager/ProfileManager.kt

@@ -27,10 +27,13 @@ import com.adealink.weparty.module.account.AccountModule
 import com.adealink.weparty.module.account.util.isUidValid
 import com.adealink.weparty.module.network.data.ServerCode
 import com.adealink.weparty.module.profile.Profile
+import com.adealink.weparty.module.profile.data.AddRemarkAndDescReq
+import com.adealink.weparty.module.profile.data.BatchGetRemarkReq
 import com.adealink.weparty.module.profile.data.CheckLadyPrivilegeRes
 import com.adealink.weparty.module.profile.data.LadyPrivilegeRewardNotify
 import com.adealink.weparty.module.profile.data.LadyPrivilegeRewardReason
 import com.adealink.weparty.module.profile.data.LadyPrivilegeRewardType
+import com.adealink.weparty.module.profile.data.QUERY_NOTE_PAGE_SIZE
 import com.adealink.weparty.module.profile.data.RegionUserRes
 import com.adealink.weparty.module.profile.data.RelationshipType
 import com.adealink.weparty.module.profile.data.UserConfigType
@@ -548,29 +551,48 @@ class ProfileManager : BaseFrame<IProfileListener>(), IProfileManager {
         launch {
             val mUid = getMyUid()
             userNoteNameMap.clear()
+            // 先从本地数据库加载已有的数据(如果有)
             noteNameDao.queryNoteName(mUid)?.forEach {
                 userNoteNameMap[it.peerUid] = it.noteName
             }
             notifyAllUserNoteNameChanged(userNoteNameMap)
-            when (val rlt = profileHttpService.getRelationShipInfoListByUid()) {
-                is Rlt.Failed -> {
 
-                }
+            var offset = 0
+            val limit = QUERY_NOTE_PAGE_SIZE
+            var hasMore = true
 
-                is Rlt.Success -> {
-                    val data = rlt.data.data ?: return@launch
-                    data.forEach {
-                        userNoteNameMap[it.peerUid] = it.extraConfig.note
-                        noteNameDao.insertNoteName(
-                            NoteNameEntity(
-                                "${mUid}_${it.peerUid}",
-                                mUid,
-                                it.peerUid,
-                                it.extraConfig.note
-                            )
-                        )
+            while (hasMore) {
+                when (val rlt = profileHttpService.queryUserRemark(BatchGetRemarkReq(offset, limit))) {
+                    is Rlt.Failed -> {
+                        hasMore = false
+                    }
+                    is Rlt.Success -> {
+                        // 如果返回的数据为空,说明没有更多数据
+                        val uid2RemarkMap = rlt.data.data?.uid2RemarkMap ?: emptyMap()
+                        if (uid2RemarkMap.isEmpty()) {
+                            hasMore = false
+                        } else {
+                            uid2RemarkMap.forEach { (peerUid, note) ->
+                                userNoteNameMap[peerUid] = note
+                                noteNameDao.insertNoteName(
+                                    NoteNameEntity(
+                                        "${mUid}_${peerUid}",
+                                        mUid,
+                                        peerUid,
+                                        note
+                                    )
+                                )
+                            }
+                            notifyAllUserNoteNameChanged(userNoteNameMap)
+
+                            // 如果当前页数量不足 limit,则说明已经全部加载完
+                            if (uid2RemarkMap.size < limit) {
+                                hasMore = false
+                            } else {
+                                offset += limit
+                            }
+                        }
                     }
-                    notifyAllUserNoteNameChanged(userNoteNameMap)
                 }
             }
         }
@@ -581,10 +603,9 @@ class ProfileManager : BaseFrame<IProfileListener>(), IProfileManager {
     }
 
     override suspend fun updateUserNoteName(uid: Long, note: String): Rlt<Any> {
-        val buildBatchGetUserRelationShipReq =
-            UserRelationShipReq(RelationshipType.NOTE_NAME.type, uid, note)
+        val updateReq = AddRemarkAndDescReq(remark = note, peerUid = uid)
         return when (val rlt =
-            profileHttpService.buildRelationShip(buildBatchGetUserRelationShipReq)) {
+            profileHttpService.addUserRemark(updateReq)) {
             is Rlt.Failed -> {
                 rlt
             }
@@ -612,6 +633,10 @@ class ProfileManager : BaseFrame<IProfileListener>(), IProfileManager {
         }
     }
 
+    override suspend fun updateUserDesc(uid: Long, desc: String): Rlt<Any> {
+        return profileHttpService.addUserRemark(AddRemarkAndDescReq(desc = desc, peerUid = uid))
+    }
+
     private fun notifyAllUserNoteNameChanged(notifyMap: Map<Long, String>) {
         dispatch {
             it.onAllUserNoteNameChanged(notifyMap)

+ 10 - 0
module/profile/src/main/java/com/adealink/weparty/profile/viewmodel/ProfileViewModel.kt

@@ -740,4 +740,14 @@ class ProfileViewModel : BaseViewModel(), IProfileViewModel, IProfileListener,
         }
         return liveData
     }
+
+    override fun updateUserDesc(uid: Long, desc: String): LiveData<Rlt<Any>> {
+        val liveData = MutableLiveData<Rlt<Any>>()
+        viewModelScope.launch {
+            liveData.send(
+                profileManager.updateUserDesc(uid, desc)
+            )
+        }
+        return liveData
+    }
 }