Compare commits
No commits in common. "da3962b9f162473c8c4754c467e2633a07a6a7d5" and "31798c60a29a76d906617d3ca5d92d77316b7d13" have entirely different histories.
da3962b9f1
...
31798c60a2
1 changed files with 15 additions and 19 deletions
|
@ -226,25 +226,21 @@ 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;
|
||||||
try {
|
for (const v of categories) {
|
||||||
for (const v of categories) {
|
if (!v && !(typeof v === 'string')) continue;
|
||||||
if (!v && !(typeof v === 'string')) continue;
|
// TODO: When/if category permissions are added, check if the user has permissions for that category
|
||||||
// TODO: When/if category permissions are added, check if the user has permissions for that category
|
const category = await Category.findById(v);
|
||||||
const category = await Category.findById(v);
|
if (category && category.title && category._id) {
|
||||||
if (category && category.title && category._id) {
|
if (!socket.joinedCategories) socket.joinedCategories = {};
|
||||||
if (!socket.joinedCategories) socket.joinedCategories = {};
|
if (socket.joinedCategories[v]) continue;
|
||||||
if (socket.joinedCategories[v]) continue;
|
socket.joinedCategories[v] = category.title;
|
||||||
socket.joinedCategories[v] = category.title;
|
await socket.join(v);
|
||||||
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);
|
const upd = await this._generateClientListUpdateObject(v, category.title);
|
||||||
this._gateway.in(v).emit('clientListUpdate', upd);
|
this._gateway.in(v).emit('clientListUpdate', upd);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue