System Messages for SocketIO (#62)

This commit is contained in:
AtHeartEngineer
2023-08-26 08:17:25 -04:00
committed by GitHub

View File

@@ -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');
});
});
});
}