diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index bbc7c2b..91740a5 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -30,7 +30,7 @@ GatewayServer.prototype.eventSetup = function() { setTimeout(() => { if (socket.isConnected) return; - console.log('[*] [gateway] [handshake] User still not connected after timeout, removing...'); + console.log('[E] [gateway] [handshake] User still not connected after timeout, removing...'); socket.disconnect(); socket.disconnect(true); }, config.gatewayStillNotConnectedTimeoutMS); @@ -108,13 +108,15 @@ GatewayServer.prototype.eventSetup = function() { socket.on('subscribe', async (categories) => { if (!categories || !Array.isArray(categories) || categories === []) return; - for (let v of categories) { + for (const v of categories) { + if (!v) continue; // TODO: When/if category permissions are added, check if the user has permissions for that category const category = await Category.findById(v); if (category && category.title && category._id) { if (!socket.joinedCategories) socket.joinedCategories = {}; - socket.joinedCategories[v] = category.title; - socket.join(v); + if (socket.joinedCategories[category._id]) continue; + socket.joinedCategories[category._id] = category.title; + socket.join(category._id); } } }); diff --git a/app/app.html b/app/app.html index ed4ce31..567a47b 100755 --- a/app/app.html +++ b/app/app.html @@ -47,6 +47,29 @@
+ + Debug info and shit + + +

gateway.isConnected: {{ gateway.isConnected }}

+

gateway.socket.id: {{ gateway.socket.id }}

+

gateway.debugInfo: {{ JSON.stringify(gateway.debugInfo) }}

+

userLoggedIn: true

+

userLoggedIn: false

+
+

loggedInUser.username: {{ loggedInUser.username }}

+

loggedInUser._id: {{ loggedInUser._id }}

+

loggedInUser.permissionLevel: {{ loggedInUser.permissionLevel }}

+

loggedInUser.role: {{ loggedInUser.role }}

+
+ + + Dump + Close + +
+
+ Create category @@ -102,6 +125,7 @@ {{ loggedInUser.username }} Manage account + Debug info and shit diff --git a/app/resources/js/app.js b/app/resources/js/app.js index 9c5e912..aa1d10c 100755 --- a/app/resources/js/app.js +++ b/app/resources/js/app.js @@ -84,6 +84,7 @@ GatewayConnection.prototype.connect = function(token) { console.log('[*] [gateway] [handshake] Got hello from server, sending yoo...', debugInfo); this.socket.emit('yoo'); this.isConnected = true; + this.debugInfo = debugInfo; this.onConnect('CONNECT_RECEIVED_HELLO'); console.log('[*] [gateway] [handshake] Assuming that server received yoo and that connection is completed.'); }); @@ -150,7 +151,8 @@ const app = new Vue({ dialog: { show: { createPost: false, - createCategory: false + createCategory: false, + debug: false }, text: { createPost: { @@ -242,6 +244,15 @@ const app = new Vue({ this.message.typed = ''; }, + // Debug + toggleDebugDialog: async function() { + this.dialog.show.debug = !this.dialog.show.debug; + }, + debugDump: async function() { + console.log('[DEBUG DUMP] [gateway]', this.gateway); + console.log('[DEBUG DUMP] [loggedInUser] (this contains sensitive information about the current logged in user, do not leak it to other people lol)', this.loggedInUser); + }, + // Category and post browsing browseCategories: async function() { const res = await fetch(`${window.location.origin}/api/v1/content/category/list?count=50`, { @@ -387,6 +398,11 @@ const app = new Vue({ }); if (res.ok) { + this.okNotification('Successfully created post'); + this.dialog.show.createPost = false; + this.browse(this.selection.category); + return; + } else { if (res.status === 401 || res.status === 403) { this.okNotification('You are not allowed to do that'); return; @@ -399,11 +415,6 @@ const app = new Vue({ const json = await res.json(); this.okNotification(getCreatePostError(json)); return; - } else { - this.okNotification('Successfully created post'); - this.dialog.show.createPost = false; - this.browse(this.selection.category); - return; } }, createCategory: async function() { @@ -422,6 +433,11 @@ const app = new Vue({ }); if (res.ok) { + this.okNotification('Successfully created category'); + this.dialog.show.createCategory = false; + this.browseCategories(); + return; + } else { if (res.status === 401 || res.status === 403) { this.okNotification('You are not allowed to do that'); return; @@ -434,11 +450,6 @@ const app = new Vue({ const json = await res.json(); this.okNotification(getCreateCategoryError(json)); return; - } else { - this.okNotification('Successfully created category'); - this.dialog.show.createCategory = false; - this.browseCategories(); - return; } },