mirror of
https://github.com/Discreetly/server.git
synced 2026-01-10 21:38:02 -05:00
System Messages for SocketIO (#62)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { MessageI, RoomI } from 'discreetly-interfaces';
|
||||
import { Socket, Server as SocketIOServer } from 'socket.io';
|
||||
import verifyProof from '../crypto/verifier';
|
||||
import { getRoomByID } from '../data/db';
|
||||
import { getRoomByID, createSystemMessages } from '../data/db';
|
||||
import { pp } from '../utils';
|
||||
import { createMessage } from '../data/messages';
|
||||
import type { createMessageResult } from '../data/messages';
|
||||
@@ -61,5 +61,20 @@ export function websocketSetup(io: SocketIOServer) {
|
||||
userCount[id] = userCount[id] ? userCount[id] - 1 : 0;
|
||||
io.to(id).emit('Members', userCount[id] ? userCount[id] : 0);
|
||||
});
|
||||
|
||||
socket.on('systemMessage', (msg: string, roomID: bigint) => {
|
||||
const id = roomID.toString();
|
||||
createSystemMessages(msg, id)
|
||||
.then(() => {
|
||||
if (roomID) {
|
||||
io.to(id).emit('systemMessage', msg);
|
||||
} else {
|
||||
io.emit('systemMessage', msg);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
pp(err, 'error');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user