mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui: messages: use new websocket gateway
This commit is contained in:
1 file changed
+16
-6
@@ -50,22 +50,32 @@ const page = new NamedPage('home_messages', () => {
|
|||||||
(window as any).store = reduxStore;
|
(window as any).store = reduxStore;
|
||||||
ctx.plugin(MessagePadService, { store, WebSocket });
|
ctx.plugin(MessagePadService, { store, WebSocket });
|
||||||
|
|
||||||
const sock = new WebSocket(`${UiContext.ws_prefix}home/messages-conn`);
|
const sock = new WebSocket(`${UiContext.ws_prefix}websocket`);
|
||||||
|
sock.onopen = () => {
|
||||||
|
sock.send(JSON.stringify({
|
||||||
|
operation: 'subscribe',
|
||||||
|
request_id: Math.random().toString(16).substring(2),
|
||||||
|
credential: document.cookie.split('sid=')[1].split(';')[0],
|
||||||
|
channels: ['message'],
|
||||||
|
}));
|
||||||
|
}
|
||||||
sock.onmessage = (message) => {
|
sock.onmessage = (message) => {
|
||||||
const msg = JSON.parse(message.data);
|
const msg = JSON.parse(message.data);
|
||||||
|
if (msg.operation !== 'event') return;
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'DIALOGUES_MESSAGE_PUSH',
|
type: 'DIALOGUES_MESSAGE_PUSH',
|
||||||
payload: msg,
|
payload: msg.payload,
|
||||||
});
|
});
|
||||||
|
const udoc = msg.payload.udoc;
|
||||||
const notification = new VjNotification({
|
const notification = new VjNotification({
|
||||||
title: msg.udoc.uname,
|
title: udoc.uname,
|
||||||
avatar: msg.udoc.avatarUrl,
|
avatar: udoc.avatarUrl,
|
||||||
message: msg.mdoc.content,
|
message: msg.payload.mdoc.content,
|
||||||
duration: 15000,
|
duration: 15000,
|
||||||
action: () => {
|
action: () => {
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'DIALOGUES_SWITCH_TO',
|
type: 'DIALOGUES_SWITCH_TO',
|
||||||
payload: msg.udoc._id,
|
payload: udoc._id,
|
||||||
});
|
});
|
||||||
notification.hide();
|
notification.hide();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user