Handle message updates via websockets for current channel

This commit is contained in:
2024-08-24 18:13:18 +02:00
parent d9a7282929
commit 7dbb36ddb0
6 changed files with 126 additions and 13 deletions

View File

@@ -3,27 +3,27 @@ import { WebSocket } from "ws";
export const attachEvents = (ws: WebSocket) => {
events.on('file-uploaded', (id, channelId, messageId, filePath, fileType, fileSize, originalName) => {
ws.send(JSON.stringify({ type: 'file-uploaded', id, channelId, messageId, filePath, fileType, fileSize, originalName }));
ws.send(JSON.stringify({ type: 'file-uploaded', data: {id, channelId, messageId, filePath, fileType, fileSize, originalName }}));
});
events.on('message-created', (id, channelId, content) => {
ws.send(JSON.stringify({ type: 'message-created', id, channelId, content }));
ws.send(JSON.stringify({ type: 'message-created', data: {id, channelId, content }}));
});
events.on('message-updated', (id, content) => {
ws.send(JSON.stringify({ type: 'message-updated', id, content }));
ws.send(JSON.stringify({ type: 'message-updated', data: {id, content }}));
});
events.on('message-deleted', (id) => {
ws.send(JSON.stringify({ type: 'message-deleted', id }));
ws.send(JSON.stringify({ type: 'message-deleted', data: {id }}));
});
events.on('channel-created', (channel) => {
ws.send(JSON.stringify({ type: 'channel-created', channel }));
ws.send(JSON.stringify({ type: 'channel-created', data: {channel }}));
});
events.on('channel-deleted', (id) => {
ws.send(JSON.stringify({ type: 'channel-deleted', id }));
ws.send(JSON.stringify({ type: 'channel-deleted', data: {id} }));
});
events.on('channel-merged', (channelId, targetChannelId) => {
ws.send(JSON.stringify({ type: 'channel-merged', channelId, targetChannelId }));
ws.send(JSON.stringify({ type: 'channel-merged', data: {channelId, targetChannelId }}));
});
events.on('channel-updated', (id, name) => {
ws.send(JSON.stringify({ type: 'channel-updated', id, name }));
ws.send(JSON.stringify({ type: 'channel-updated', data: {id, name }}));
});
}