Skip to content

Commit

Permalink
fix: 修复好友申请未读数更新逻辑,修复好友申请被同意的时候收到对方发送的消息无法显示。
Browse files Browse the repository at this point in the history
  • Loading branch information
Evansy committed Oct 29, 2023
1 parent 21aa075 commit 6f1e429
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ declare module '@vue/runtime-core' {
ElAvatar: typeof import('element-plus/es')['ElAvatar']
ElBadge: typeof import('element-plus/es')['ElBadge']
ElButton: typeof import('element-plus/es')['ElButton']
ElCollapse: typeof import('element-plus/es')['ElCollapse']
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElDivider: typeof import('element-plus/es')['ElDivider']
ElDrawer: typeof import('element-plus/es')['ElDrawer']
Expand Down
2 changes: 2 additions & 0 deletions src/services/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export default {
putRequest(urls.sendAddFriendRequest, params),
/** 同意好友申请 */
deleteFriend: (params: { targetUid: number }) => deleteRequest(urls.deleteFriend, params),
/** 好友申请未读数 */
newFriendCount: () => getRequest<{ unReadCount: number }>(urls.newFriendCount),
/** 会话列表 */
getSessionList: (params?: any) =>
getRequest<ListResponse<SessionItem>>(urls.getSessionList, params),
Expand Down
1 change: 1 addition & 0 deletions src/services/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
requestFriendList: `${prefix}/capi/user/friend/apply/page`, // 好友申请列表
sendAddFriendRequest: `${prefix}/capi/user/friend/apply`, // 申请好友
deleteFriend: `${prefix}/capi/user/friend`, // 删除好友
newFriendCount: `${prefix}/capi/user/friend/apply/unread`, // 申请未读数

// -------------- 聊天室相关 ---------------
getSessionList: `${prefix}/capi/chat/public/contact/page`, // 会话列表
Expand Down
16 changes: 8 additions & 8 deletions src/stores/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ref, reactive, computed, watch } from 'vue'
import { defineStore } from 'pinia'
import cloneDeep from 'lodash/cloneDeep'
import { useRoute } from 'vue-router'
import Router from '@/router'
// import Router from '@/router'
import apis from '@/services/apis'
import type { MessageType, MarkItemType, RevokedMsgType, SessionItem } from '@/services/types'
import { MarkEnum, RoomTypeEnum } from '@/enums'
Expand Down Expand Up @@ -280,14 +280,14 @@ export const useChatStore = defineStore('chat', () => {
if (globalStore.currentSession && globalStore.currentSession.roomId !== msg.message.roomId) {
let result = undefined
// 如果当前路由不是聊天,就开始拿会话详情,并手动新增一条会话记录
if (route?.path && route?.path !== '/') {
globalStore.currentSession.roomId = msg.message.roomId
globalStore.currentSession.type = RoomTypeEnum.Single
if (!current) {
result = await apis.sessionDetail({ id: msg.message.roomId }).send()
}
Router.push('/')
// if (route?.path && route?.path !== '/') {
// globalStore.currentSession.roomId = msg.message.roomId
// globalStore.currentSession.type = RoomTypeEnum.Single
if (!current) {
result = await apis.sessionDetail({ id: msg.message.roomId }).send()
}
// Router.push('/')
// }
updateSessionLastActiveTime(msg.message.roomId, result)
}

Expand Down
15 changes: 15 additions & 0 deletions src/stores/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ export const useContactStore = defineStore('contact', () => {
contactsOptions.isLoading = false
}

/** 好友申请未读数 */
const getNewFriendCount = async () => {
const data = await apis
.newFriendCount()
.send()
.catch(() => {
//
})
if (typeof data?.unReadCount === 'number') {
globalStore.unReadMark.newFriendUnreadCount = data.unReadCount
}
}

const getRequestFriendsList = async (isFresh = false) => {
if (!isFresh) {
if (requestFriendsOptions.isLast || requestFriendsOptions.isLoading) return
Expand All @@ -53,6 +66,8 @@ export const useContactStore = defineStore('contact', () => {
.catch(() => {
requestFriendsOptions.isLoading = false
})
// 每次加载完新的好友邀请列表都要更新申请未读数
getNewFriendCount()
if (!data) return
isFresh
? requestFriendsList.splice(0, requestFriendsList.length, ...data.list)
Expand Down

0 comments on commit 6f1e429

Please sign in to comment.