fix #10
This commit is contained in:
parent
7d1882895b
commit
6c5470e6b1
1 changed files with 19 additions and 15 deletions
|
@ -226,22 +226,26 @@ GatewayServer.prototype.eventSetup = function() {
|
||||||
|
|
||||||
socket.on('subscribe', async (categories) => {
|
socket.on('subscribe', async (categories) => {
|
||||||
if ( !socket.isConnected || !socket.user || !categories || !Array.isArray(categories) || categories === []) return;
|
if ( !socket.isConnected || !socket.user || !categories || !Array.isArray(categories) || categories === []) return;
|
||||||
for (const v of categories) {
|
try {
|
||||||
if (!v && !(typeof v === 'string')) continue;
|
for (const v of categories) {
|
||||||
// TODO: When/if category permissions are added, check if the user has permissions for that category
|
if (!v && !(typeof v === 'string')) continue;
|
||||||
const category = await Category.findById(v);
|
// TODO: When/if category permissions are added, check if the user has permissions for that category
|
||||||
if (category && category.title && category._id) {
|
const category = await Category.findById(v);
|
||||||
if (!socket.joinedCategories) socket.joinedCategories = {};
|
if (category && category.title && category._id) {
|
||||||
if (socket.joinedCategories[v]) continue;
|
if (!socket.joinedCategories) socket.joinedCategories = {};
|
||||||
socket.joinedCategories[v] = category.title;
|
if (socket.joinedCategories[v]) continue;
|
||||||
await socket.join(v);
|
socket.joinedCategories[v] = category.title;
|
||||||
|
await socket.join(v);
|
||||||
console.log(`[*] [gateway] User ${socket.user.username} subscribed to room ${v} (${category.title}), sending updated user list to all members of that room...`);
|
|
||||||
|
console.log(`[*] [gateway] User ${socket.user.username} subscribed to room ${v} (${category.title}), sending updated user list to all members of that room...`);
|
||||||
const upd = await this._generateClientListUpdateObject(v, category.title);
|
|
||||||
this._gateway.in(v).emit('clientListUpdate', upd);
|
const upd = await this._generateClientListUpdateObject(v, category.title);
|
||||||
|
this._gateway.in(v).emit('clientListUpdate', upd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnecting', async () => {
|
socket.on('disconnecting', async () => {
|
||||||
|
|
Reference in a new issue