Skip to content

Commit bf55330

Browse files
committed
ui: messages: use new websocket gateway
1 parent d01dbc6 commit bf55330

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

packages/ui-default/pages/home_messages.page.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,32 @@ const page = new NamedPage('home_messages', () => {
5050
(window as any).store = reduxStore;
5151
ctx.plugin(MessagePadService, { store, WebSocket });
5252

53-
const sock = new WebSocket(`${UiContext.ws_prefix}home/messages-conn`);
53+
const sock = new WebSocket(`${UiContext.ws_prefix}websocket`);
54+
sock.onopen = () => {
55+
sock.send(JSON.stringify({
56+
operation: 'subscribe',
57+
request_id: Math.random().toString(16).substring(2),
58+
credential: document.cookie.split('sid=')[1].split(';')[0],
59+
channels: ['message'],
60+
}));
61+
}
5462
sock.onmessage = (message) => {
5563
const msg = JSON.parse(message.data);
64+
if (msg.operation !== 'event') return;
5665
store.dispatch({
5766
type: 'DIALOGUES_MESSAGE_PUSH',
58-
payload: msg,
67+
payload: msg.payload,
5968
});
69+
const udoc = msg.payload.udoc;
6070
const notification = new VjNotification({
61-
title: msg.udoc.uname,
62-
avatar: msg.udoc.avatarUrl,
63-
message: msg.mdoc.content,
71+
title: udoc.uname,
72+
avatar: udoc.avatarUrl,
73+
message: msg.payload.mdoc.content,
6474
duration: 15000,
6575
action: () => {
6676
store.dispatch({
6777
type: 'DIALOGUES_SWITCH_TO',
68-
payload: msg.udoc._id,
78+
payload: udoc._id,
6979
});
7080
notification.hide();
7181
},

0 commit comments

Comments
 (0)