fix(ws): only process unread notifications and handle multiple payload formats
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:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user