mirror of
https://github.com/HuLaSpark/HuLa.git
synced 2026-09-24 23:11:59 +08:00
fix(mobile): 🐛 reposted in Moments, unread notification in Moments
This commit is contained in:
@@ -821,6 +821,12 @@ impl WebSocketClient {
|
||||
let _ = app_handle.emit("ws-delete-friend", data);
|
||||
}
|
||||
|
||||
// 朋友圈相关
|
||||
"feedSendMsg" => {
|
||||
info!("🎉 Feed message received");
|
||||
let _ = app_handle.emit_to("home", "ws-feed-send-msg", data);
|
||||
}
|
||||
|
||||
// 未知消息类型
|
||||
_ => {
|
||||
warn!("❓ Received unhandled message type: {}", message_type);
|
||||
|
||||
+12
@@ -46,6 +46,7 @@ import { useGroupStore } from '@/stores/group'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { useChatStore } from '@/stores/chat'
|
||||
import { useAnnouncementStore } from '@/stores/announcement'
|
||||
import { useFeedStore } from '@/stores/feed'
|
||||
import type { MarkItemType, RevokedMsgType, UserItem } from '@/services/types.ts'
|
||||
|
||||
const mobileRtcCallFloatCell = isMobile()
|
||||
@@ -55,6 +56,7 @@ const mobileRtcCallFloatCell = isMobile()
|
||||
const userStore = useUserStore()
|
||||
const contactStore = useContactStore()
|
||||
const announcementStore = useAnnouncementStore()
|
||||
const feedStore = useFeedStore()
|
||||
const userUid = computed(() => userStore.userInfo!.uid)
|
||||
const groupStore = useGroupStore()
|
||||
const chatStore = useChatStore()
|
||||
@@ -371,6 +373,16 @@ useMitt.on(WsResponseMessageType.USER_STATE_CHANGE, async (data: { uid: string;
|
||||
})
|
||||
})
|
||||
|
||||
useMitt.on(WsResponseMessageType.FEED_SEND_MSG, (data: { uid: string }) => {
|
||||
if (data.uid !== userStore.userInfo!.uid) {
|
||||
feedStore.increaseUnreadCount()
|
||||
// 同步更新角标
|
||||
unreadCountManager.refreshBadge(globalStore.unReadMark)
|
||||
} else {
|
||||
console.log('🔔 [App.vue] 是自己发布的,不增加未读数')
|
||||
}
|
||||
})
|
||||
|
||||
useMitt.on(WsResponseMessageType.GROUP_SET_ADMIN_SUCCESS, (event) => {
|
||||
console.log('设置群管理员---> ', event)
|
||||
groupStore.updateAdminStatus(event.roomId, event.uids, event.status)
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
</n-flex>
|
||||
</n-popover>
|
||||
<!-- 该选项无提示时展示 -->
|
||||
<n-badge v-else :max="99" :value="item.badge">
|
||||
<n-badge v-else :max="99" :value="item.badge" :show="(item.badge ?? 0) > 0">
|
||||
<svg class="size-22px">
|
||||
<use
|
||||
:href="`#${activeUrl === item.url || openWindowsList.has(item.url) ? item.iconAction : item.icon}`"></use>
|
||||
@@ -260,6 +260,7 @@ import { useGlobalStore } from '@/stores/global.ts'
|
||||
import { useMenuTopStore } from '@/stores/menuTop.ts'
|
||||
import { usePluginsStore } from '@/stores/plugins.ts'
|
||||
import { useSettingStore } from '@/stores/setting.ts'
|
||||
import { useFeedStore } from '@/stores/feed.ts'
|
||||
import { itemsBottom, moreList } from '../config.tsx'
|
||||
import { leftHook } from '../hook.ts'
|
||||
import DefinePlugins from './definePlugins/index.vue'
|
||||
@@ -268,9 +269,11 @@ const appWindow = WebviewWindow.getCurrent()
|
||||
const { addListener } = useTauriListener()
|
||||
const globalStore = useGlobalStore()
|
||||
const pluginsStore = usePluginsStore()
|
||||
const feedStore = useFeedStore()
|
||||
const { showMode } = storeToRefs(useSettingStore())
|
||||
const { menuTop } = useMenuTopStore()
|
||||
const { plugins } = storeToRefs(pluginsStore)
|
||||
const { unreadCount: feedUnreadCount } = storeToRefs(feedStore)
|
||||
const unReadMark = computed(() => globalStore.unReadMark)
|
||||
// const headerRef = useTemplateRef('header')
|
||||
// const actionListRef = useTemplateRef('actionList')
|
||||
@@ -341,6 +344,18 @@ const setHomeHeight = () => {
|
||||
invoke('set_height', { height: showMode.value === ShowModeEnum.TEXT ? 505 : 423 })
|
||||
}
|
||||
|
||||
// 监听朋友圈未读数量变化,同步到 dynamic 插件的 badge
|
||||
watch(
|
||||
feedUnreadCount,
|
||||
(newCount) => {
|
||||
const dynamicPlugin = plugins.value.find((p) => p.url === 'dynamic')
|
||||
if (dynamicPlugin) {
|
||||
pluginsStore.updatePlugin({ ...dynamicPlugin, badge: newCount })
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
// 初始化窗口高度
|
||||
setHomeHeight()
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// import { useGlobalStore } from '@/stores/global'
|
||||
import { useFeedStore } from '@/stores/feed'
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
type NavItem = {
|
||||
label: string
|
||||
@@ -32,21 +33,20 @@ type NavItem = {
|
||||
}
|
||||
|
||||
const route = useRoute()
|
||||
// const globalStore = useGlobalStore()
|
||||
|
||||
// const unReadMark = computed(() => globalStore.unReadMark)
|
||||
const feedStore = useFeedStore()
|
||||
const { unreadCount: feedUnreadCount } = storeToRefs(feedStore)
|
||||
|
||||
const getUnReadCount = (label: string) => {
|
||||
label // 避免报错,临时引用
|
||||
return 0 // 在移动端message页面中,未读计数有问题,所以先不展示
|
||||
if (label === '社区') {
|
||||
return feedUnreadCount.value
|
||||
}
|
||||
return 0
|
||||
|
||||
// 其他未读计数暂时关闭(message页面有问题)
|
||||
// if (label === '消息') {
|
||||
// return unReadMark.value.newMsgUnreadCount
|
||||
// } else if (label === '联系人') {
|
||||
// return unReadMark.value.newFriendUnreadCount
|
||||
// } else if (label === '社区') {
|
||||
// return unReadMark.value.newGroupUnreadCount
|
||||
// } else {
|
||||
// return 0
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -302,6 +302,11 @@ const options = ref<Array<{ name: string; src: string }>>([])
|
||||
const { currentSession: activeItem } = storeToRefs(globalStore)
|
||||
const friend = contactStore.contactsList.find((item) => item.uid === globalStore.currentSession.detailId)
|
||||
|
||||
// 保存初始值,用于判断是否真正修改了内容
|
||||
const initialRemarkValue = ref('')
|
||||
const initialNicknameValue = ref('')
|
||||
const initialNameValue = ref('')
|
||||
|
||||
const {
|
||||
fileInput,
|
||||
localImageUrl,
|
||||
@@ -467,31 +472,59 @@ const handleTop = (value: boolean) => {
|
||||
|
||||
// 处理群备注更新
|
||||
const handleInfoUpdate = async () => {
|
||||
// 检查是否真正修改了内容
|
||||
const remarkChanged = remarkValue.value !== initialRemarkValue.value
|
||||
const nicknameChanged = nicknameValue.value !== initialNicknameValue.value
|
||||
|
||||
// 如果群聊和单聊的备注、昵称都没有改变,则不调用接口
|
||||
if (!remarkChanged && !nicknameChanged) {
|
||||
return
|
||||
}
|
||||
|
||||
if (isGroup.value) {
|
||||
await persistMyRoomInfo({
|
||||
roomId: globalStore.currentSession.roomId,
|
||||
remark: remarkValue.value,
|
||||
myName: nicknameValue.value
|
||||
})
|
||||
// 更新初始值
|
||||
initialRemarkValue.value = remarkValue.value
|
||||
initialNicknameValue.value = nicknameValue.value
|
||||
} else {
|
||||
// 单聊只检查备注是否修改
|
||||
if (!remarkChanged) {
|
||||
return
|
||||
}
|
||||
|
||||
await modifyFriendRemark({
|
||||
targetUid: globalStore.currentSession.detailId,
|
||||
remark: remarkValue.value
|
||||
})
|
||||
|
||||
friend!.remark = remarkValue.value
|
||||
// 更新初始值
|
||||
initialRemarkValue.value = remarkValue.value
|
||||
}
|
||||
window.$message.success(title.value + '备注更新成功')
|
||||
}
|
||||
|
||||
// 处理群名称更新
|
||||
const handleGroupInfoUpdate = async () => {
|
||||
// 检查群名称是否真正修改了
|
||||
if (nameValue.value === initialNameValue.value) {
|
||||
return
|
||||
}
|
||||
|
||||
await updateRoomInfo({
|
||||
id: activeItem.value.roomId,
|
||||
name: nameValue.value,
|
||||
avatar: avatarValue.value
|
||||
})
|
||||
activeItem.value.avatar = avatarValue.value
|
||||
|
||||
// 更新初始值
|
||||
initialNameValue.value = nameValue.value
|
||||
window.$message.success('群名称更新成功')
|
||||
}
|
||||
|
||||
// 获取群组详情和成员信息
|
||||
@@ -610,6 +643,11 @@ onMounted(async () => {
|
||||
avatarValue.value = response.avatar
|
||||
nicknameValue.value = response.myName || ''
|
||||
remarkValue.value = response.remark || ''
|
||||
|
||||
// 保存初始值
|
||||
initialNameValue.value = nameValue.value
|
||||
initialNicknameValue.value = nicknameValue.value
|
||||
initialRemarkValue.value = remarkValue.value
|
||||
if (item.value && item.value.roomId) {
|
||||
fetchGroupMembers(item.value.roomId)
|
||||
}
|
||||
@@ -620,6 +658,8 @@ onMounted(async () => {
|
||||
} else {
|
||||
// 这里需要拿到好友的信息
|
||||
remarkValue.value = friend?.remark || ''
|
||||
// 保存初始值
|
||||
initialRemarkValue.value = remarkValue.value
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -45,6 +45,8 @@ import { useUserStore } from '@/stores/user'
|
||||
import { AvatarUtils } from '@/utils/AvatarUtils'
|
||||
import { useDebounceFn, useThrottleFn } from '@vueuse/core'
|
||||
import DynamicList from '@/components/common/DynamicList.vue'
|
||||
import { useMitt } from '@/hooks/useMitt'
|
||||
import { WsResponseMessageType } from '@/services/wsType'
|
||||
|
||||
const router = useRouter()
|
||||
const feedStore = useFeedStore()
|
||||
@@ -88,6 +90,8 @@ const onRefresh = () => {
|
||||
Promise.all([apiPromise, delayPromise])
|
||||
.then(() => {
|
||||
loading.value = false
|
||||
// 刷新后清空未读数量
|
||||
feedStore.clearUnreadCount()
|
||||
console.log('刷新完成')
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -133,14 +137,26 @@ const handleItemClick = (feedId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
// 监听朋友圈消息推送
|
||||
const handleFeedSendMsg = (_payload: any) => {
|
||||
feedStore.increaseUnreadCount()
|
||||
}
|
||||
|
||||
// 初始化数据
|
||||
onMounted(async () => {
|
||||
// 初始加载动态列表
|
||||
await feedStore.getFeedList(true)
|
||||
|
||||
// 打开朋友圈时清空未读数量
|
||||
feedStore.clearUnreadCount()
|
||||
|
||||
// 注册朋友圈消息监听
|
||||
useMitt.on(WsResponseMessageType.FEED_SEND_MSG, handleFeedSendMsg)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// 清理工作
|
||||
// 清理事件监听
|
||||
useMitt.off(WsResponseMessageType.FEED_SEND_MSG, handleFeedSendMsg)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -261,7 +261,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { sumBy } from 'es-toolkit'
|
||||
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'
|
||||
import { useUserStore } from '@/stores/user.ts'
|
||||
import { useContactStore } from '@/stores/contacts.ts'
|
||||
@@ -280,11 +279,7 @@ const contactStore = useContactStore()
|
||||
const feedStore = useFeedStore()
|
||||
const groupStore = useGroupStore()
|
||||
|
||||
// 从store中获取响应式数据
|
||||
const {
|
||||
feedList: dynamicList
|
||||
// feedStats
|
||||
} = storeToRefs(feedStore)
|
||||
const { feedList: dynamicList, unreadCount } = storeToRefs(feedStore)
|
||||
|
||||
const showCommentModal = ref(false)
|
||||
const newComment = ref('')
|
||||
@@ -336,9 +331,6 @@ interface CommentItem {
|
||||
userAvatar: string
|
||||
}
|
||||
|
||||
// 计算属性
|
||||
const unreadCount = computed(() => sumBy(dynamicList.value, (feed) => feed.commentCount || 0))
|
||||
|
||||
// 验证发布内容是否有效(只验证文本内容)
|
||||
const isPublishValid = computed(() => {
|
||||
return newFeedContent.value.trim().length > 0
|
||||
@@ -436,6 +428,8 @@ const handleInfoTip = () => {
|
||||
const handleRefresh = async () => {
|
||||
try {
|
||||
await feedStore.refresh()
|
||||
// 刷新后清空未读数量
|
||||
feedStore.clearUnreadCount()
|
||||
window.$message.success('刷新成功')
|
||||
} catch (error) {
|
||||
console.error('刷新动态失败:', error)
|
||||
@@ -572,6 +566,9 @@ onMounted(async () => {
|
||||
// 初始加载朋友圈列表
|
||||
await feedStore.getFeedList(true)
|
||||
|
||||
// 打开朋友圈时清空未读数量
|
||||
feedStore.clearUnreadCount()
|
||||
|
||||
// 加载联系人列表
|
||||
try {
|
||||
await contactStore.getContactList(true)
|
||||
|
||||
@@ -459,6 +459,14 @@ class RustWebSocketClient {
|
||||
contactStore.deleteContact(event.payload)
|
||||
})
|
||||
)
|
||||
|
||||
// 朋友圈相关事件
|
||||
this.listenerController.add(
|
||||
await listen('ws-feed-send-msg', (event: any) => {
|
||||
info(`收到朋友圈消息: ${JSON.stringify(event.payload)}`)
|
||||
useMitt.emit(WsResponseMessageType.FEED_SEND_MSG, event.payload)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
info('创建RustWebSocketClient')
|
||||
|
||||
@@ -74,7 +74,9 @@ export enum WsResponseMessageType {
|
||||
WEBRTC_SIGNAL = 'WEBRTC_SIGNAL',
|
||||
/** 全局静音 */
|
||||
AllMuted = 'AllMuted',
|
||||
CANCEL = 'CANCEL'
|
||||
CANCEL = 'CANCEL',
|
||||
/** 朋友圈消息推送 */
|
||||
FEED_SEND_MSG = 'feedSendMsg'
|
||||
}
|
||||
|
||||
export enum NoticeTypeEnum {
|
||||
|
||||
+29
-1
@@ -65,6 +65,9 @@ export const useFeedStore = defineStore(
|
||||
fansCount: 0
|
||||
})
|
||||
|
||||
// 未读消息数量
|
||||
const unreadCount = ref(0)
|
||||
|
||||
/**
|
||||
* 获取动态列表
|
||||
* @param isFresh 是否刷新列表,true则重新加载,false则加载更多
|
||||
@@ -193,10 +196,32 @@ export const useFeedStore = defineStore(
|
||||
Object.assign(feedStats, stats)
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加未读消息数量
|
||||
*/
|
||||
const increaseUnreadCount = (count = 1) => {
|
||||
unreadCount.value += count
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空未读消息数量
|
||||
*/
|
||||
const clearUnreadCount = () => {
|
||||
unreadCount.value = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置未读消息数量
|
||||
*/
|
||||
const setUnreadCount = (count: number) => {
|
||||
unreadCount.value = count
|
||||
}
|
||||
|
||||
return {
|
||||
feedList,
|
||||
feedOptions,
|
||||
feedStats,
|
||||
unreadCount,
|
||||
getFeedList,
|
||||
publishFeed,
|
||||
deleteFeed,
|
||||
@@ -204,7 +229,10 @@ export const useFeedStore = defineStore(
|
||||
loadMore,
|
||||
refresh,
|
||||
clearFeedList,
|
||||
updateStats
|
||||
updateStats,
|
||||
increaseUnreadCount,
|
||||
clearUnreadCount,
|
||||
setUnreadCount
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user