fix: leave

This commit is contained in:
cha0s 2020-12-11 23:36:54 -06:00
parent 6687884604
commit d10508fa05

View File

@ -1,5 +1,6 @@
import {
channelIsAnonymous,
parseChannel,
parseChatChannel,
renderChannel,
validateChannel,
@ -16,6 +17,7 @@ import Message from './packets/message.server';
import ensureCanonical from './ensure-canonical';
import defaultState, {channelsToHydrate} from './state';
import joinChannel from './join-channel';
import leaveChannel from './leave-channel';
export * from './state';
@ -66,6 +68,14 @@ export default {
.filter(({type}) => 'r' === type)
.filter((channel) => req.userId || channelIsAnonymous(channel))
.map((channel) => joinChannel(latus, channel, socket));
socket.on('disconnecting', async () => {
Object.keys(socket.rooms).forEach((room) => {
const parsed = parseChannel(room);
if (parsed && 'r' === parsed.type) {
leaveChannel(parsed, socket);
}
});
});
return Promise.all(joins);
},
'@reddichat/state/defaultState': async (req, latus) => ({