mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-04 21:19:27 +08:00
fix(notification): decode SSE messages and encode data for in-app notifications
This commit is contained in:
parent
e129cfc5ab
commit
c0928e0ffd
@ -8,11 +8,11 @@
|
||||
*/
|
||||
|
||||
import { observable, reaction } from '@formily/reactive';
|
||||
import { SSEData } from '../../types';
|
||||
import { messageMapObs, updateUnreadMsgsCount } from './message';
|
||||
import { fetchChannels } from './channel';
|
||||
import { getAPIClient } from '../utils';
|
||||
import { uid } from '@nocobase/utils/client';
|
||||
import { SSEData } from '../../types';
|
||||
import { getAPIClient } from '../utils';
|
||||
import { fetchChannels } from './channel';
|
||||
import { messageMapObs, updateUnreadMsgsCount } from './message';
|
||||
|
||||
export const liveSSEObs = observable<{ value: SSEData | null }>({ value: null });
|
||||
reaction(
|
||||
@ -66,7 +66,8 @@ export const startMsgSSEStreamWithRetry: () => () => void = () => {
|
||||
if (done) break;
|
||||
const messages = value.split('\n\n').filter(Boolean);
|
||||
for (const message of messages) {
|
||||
const sseData: SSEData = JSON.parse(message.replace(/^data:\s*/, '').trim());
|
||||
const decodedMessage = decodeURIComponent(message);
|
||||
const sseData: SSEData = JSON.parse(decodedMessage.replace(/^data:\s*/, '').trim());
|
||||
liveSSEObs.value = sseData;
|
||||
}
|
||||
}
|
||||
|
@ -60,14 +60,16 @@ export default class InAppNotificationChannel extends BaseNotificationChannel {
|
||||
for (const clientId in clients) {
|
||||
const stream = clients[clientId];
|
||||
stream.write(
|
||||
`data: ${JSON.stringify({
|
||||
type: message.type,
|
||||
data: {
|
||||
...message.data,
|
||||
title: message.data.title || '',
|
||||
content: message.data.content || '',
|
||||
},
|
||||
})}\n\n`,
|
||||
`data: ${encodeURIComponent(
|
||||
JSON.stringify({
|
||||
type: message.type,
|
||||
data: {
|
||||
...message.data,
|
||||
title: message.data.title || '',
|
||||
content: message.data.content || '',
|
||||
},
|
||||
}),
|
||||
)}\n\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user