Skip to content

Commit

Permalink
fix: 修复消息撤回显示问题,修复 props uid 获取报错问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
Evansy committed Jul 15, 2023
1 parent 262a5db commit afbe64e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/RenderMessage/text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const fragments = computed(() => {
const openUrl = (url: string) => {
if (!url) return
// 当没有协议时,自动添加协议
window.open(url.startsWith("http") ? url : '//' + url, '_blank')
window.open(url.startsWith('http') ? url : '//' + url, '_blank')
}
</script>

Expand Down
20 changes: 12 additions & 8 deletions src/stores/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,18 @@ export const useChatStore = defineStore('chat', () => {
if (message) {
message.message.type = MsgEnum.RECALL

// 如果消息是被管理员撤回,需要显示 管理员 xx 撤回了一条成员消息
if (isAdmin.value) {
message.message.body = `管理员"${userInfo.name}"撤回了一条成员消息` // 后期根据本地用户数据修改
} else {
// 如果被撤回的消息是消息发送者撤回,正常显示
const uid = message.fromUser.uid
const cacheUser = cachedStore.userCachedList[uid]
message.message.body = `"${cacheUser.name}"撤回了一条消息` // 后期根据本地用户数据修改
if (typeof data.recallUid === 'number') {
const cacheUser = cachedStore.userCachedList[data.recallUid]
// 如果撤回者的 id 不等于消息发送人的 id, 或者你本人就是管理员,那么显示管理员撤回的。
if (
data.recallUid !== message.fromUser.uid ||
(data.recallUid === userInfo.uid && isAdmin.value)
) {
message.message.body = `管理员"${cacheUser.name}"撤回了一条成员消息` // 后期根据本地用户数据修改
} else {
// 如果被撤回的消息是消息发送者撤回,正常显示
message.message.body = `"${cacheUser.name}"撤回了一条消息` // 后期根据本地用户数据修改
}
}
}
// 更新与这条撤回消息有关的消息
Expand Down
4 changes: 2 additions & 2 deletions src/views/Home/components/UserList/UserItem/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const props = defineProps({
},
})
const user = toRef(props.user)
const userInfo = useUserInfo(user.value.uid)
const userInfo = useUserInfo(user.value?.uid)
const isShowMenu = ref(false) // 是否显示菜单
// 弹出定位
const menuOptions = ref({ x: 0, y: 0 })
Expand All @@ -37,7 +37,7 @@ const handleRightClick = (e: MouseEvent) => {
:online="user.activeStatus === OnlineEnum.ONLINE"
/>
{{ userInfo.name }}
<ContextMenu v-model:show="isShowMenu" :options="menuOptions" :uid="(userInfo.uid as number)" />
<ContextMenu v-model:show="isShowMenu" :options="menuOptions" :uid="(user?.uid as number)" />
</li>
</template>

Expand Down

0 comments on commit afbe64e

Please sign in to comment.