fix(ws): only process unread notifications and handle multiple payload formats
Some checks failed
Frontend CI / build-and-push-web (push) Failing after 3m37s
Frontend CI / ota-android (push) Successful in 10m50s
Frontend CI / build-android-apk (push) Failing after 17m44s

Previously, the notification handler would process all notifications regardless of read status, and only accepted `extra_data` from the payload. Now it:
- Only calls systemNotificationService and increments unread count for unread notifications
- Falls back to `payload.extra` or `payload.data` when `extra_data` is not present
This commit is contained in:
lafay
2026-04-25 15:59:59 +08:00
parent eccfd67550
commit de0afa93a1
2 changed files with 7 additions and 4 deletions

View File

@@ -619,12 +619,14 @@ class WebSocketService {
receiver_id: payload.receiver_id, receiver_id: payload.receiver_id,
category: payload.category, category: payload.category,
system_type: payload.system_type, system_type: payload.system_type,
extra_data: payload.extra_data, extra_data: payload.extra_data || payload.extra || payload.data,
is_read: !!payload.is_read, is_read: !!payload.is_read,
created_at: payload.created_at || new Date().toISOString(), created_at: payload.created_at || new Date().toISOString(),
}; };
this.emit('notification', m); this.emit('notification', m);
systemNotificationService.handleWSMessage(m as any).catch(() => {}); if (!m.is_read) {
systemNotificationService.handleWSMessage(m as any).catch(() => {});
}
} }
// Call signaling handlers // Call signaling handlers

View File

@@ -131,9 +131,10 @@ export class WSMessageHandler implements IWSMessageHandler {
// 监听系统通知,实时更新系统未读数 // 监听系统通知,实时更新系统未读数
wsService.on('notification', (message: WSNotificationMessage) => { wsService.on('notification', (message: WSNotificationMessage) => {
if (!message.is_read) { if (message.is_read) {
this.incrementSystemUnread(); return;
} }
this.incrementSystemUnread();
if (message.created_at) { if (message.created_at) {
const store = useMessageStore.getState(); const store = useMessageStore.getState();
const currentLast = store.lastSystemMessageAt; const currentLast = store.lastSystemMessageAt;