From 943ed647354dcbcdba4949928aca4591660ff392 Mon Sep 17 00:00:00 2001 From: hippoz Date: Fri, 26 Mar 2021 22:50:21 +0200 Subject: [PATCH] replace all mentions of category with channel for better consistency --- README.md | 2 +- brainlet/api/v1/content.js | 36 ++--- brainlet/api/v1/gateway/index.js | 78 +++++----- brainlet/api/v2/gateway/index.js | 4 +- brainlet/app/app.html | 44 +++--- brainlet/app/resources/js/app.js | 160 ++++++++++---------- brainlet/models/{Category.js => Channel.js} | 8 +- brainlet/models/Post.js | 2 +- libbrainlet/bridgebot.js | 2 +- libbrainlet/gatewayconnection.js | 12 +- resources/Docs/DOCS.md | 2 +- 11 files changed, 175 insertions(+), 175 deletions(-) rename brainlet/models/{Category.js => Channel.js} (67%) diff --git a/README.md b/README.md index 3de165c..d35e54f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Brainlet -Brainlet is a simple chat app. Each category has a text channel associated with it, all messages sent in the text channel are temporary, while in the category itself all posts are permanent. +Brainlet is a simple chat app. Each channel has a text channel associated with it, all messages sent in the text channel are temporary, while in the channel itself all posts are permanent. # Resources diff --git a/brainlet/api/v1/content.js b/brainlet/api/v1/content.js index a3020e6..e471753 100755 --- a/brainlet/api/v1/content.js +++ b/brainlet/api/v1/content.js @@ -1,5 +1,5 @@ const User = require("../../models/User"); -const Category = require("../../models/Category"); +const Channel = require("../../models/Channel"); const Post = require("../../models/Post"); const config = require("../../config"); const { authenticateEndpoint } = require("./../../common/auth/authfunctions"); @@ -17,7 +17,7 @@ const createLimiter = rateLimit({ mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true}); -app.post("/category/create", [ +app.post("/channel/create", [ createLimiter, body("title").not().isEmpty().trim().isLength({ min: 3, max: 32 }).escape() ], authenticateEndpoint(async (req, res, user) => { @@ -28,7 +28,7 @@ app.post("/category/create", [ } const title = req.body.title; - const category = await Category.create({ + const channel = await Channel.create({ title: title, creator: user._id, posts: [] @@ -37,13 +37,13 @@ app.post("/category/create", [ res.status(200).json({ error: false, message: "SUCCESS_CATEGORY_CREATED", - category: category.getPublicObject() + channel: channel.getPublicObject() }); }, undefined, config.roleMap.USER)); app.post("/post/create", [ createLimiter, - body("category").not().isEmpty().trim().escape().isLength({ min: 24, max: 24 }), + body("channel").not().isEmpty().trim().escape().isLength({ min: 24, max: 24 }), body("title").not().isEmpty().trim().isLength({ min: 3, max: 32 }).escape(), body("body").not().isEmpty().trim().isLength({ min: 3, max: 1000 }).escape(), ], authenticateEndpoint(async (req, res, user) => { @@ -53,7 +53,7 @@ app.post("/post/create", [ return; } - const category = req.body.category; + const channel = req.body.channel; const title = req.body.title; const content = req.body.body; @@ -61,10 +61,10 @@ app.post("/post/create", [ post.title = title; post.body = content; post.creator = user._id; - post.category = category; + post.channel = channel; - const r = await Category.updateOne({ - _id: category + const r = await Channel.updateOne({ + _id: channel }, { $push: { posts: post } }); @@ -86,8 +86,8 @@ app.post("/post/create", [ }); }, undefined, config.roleMap.USER)); -app.get("/category/:category/info", [ - param("category").not().isEmpty().trim().escape().isLength({ min: 24, max: 24 }) +app.get("/channel/:channel/info", [ + param("channel").not().isEmpty().trim().escape().isLength({ min: 24, max: 24 }) ], authenticateEndpoint(async (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { @@ -95,13 +95,13 @@ app.get("/category/:category/info", [ return; } - const categoryId = req.params.category; - const category = await Category.findById(categoryId).populate("posts.creator", User.getPulicFields()); + const channelId = req.params.channel; + const channel = await Channel.findById(channelId).populate("posts.creator", User.getPulicFields()); // TODO: Implement subscribing to a channel and stuff const users = await User.find().sort({ _id: -1 }).limit(50).select(User.getPulicFields()); - if (!category) { + if (!channel) { res.status(404).json({ error: true, message: "ERROR_CATEGORY_NOT_FOUND" @@ -112,7 +112,7 @@ app.get("/category/:category/info", [ res.status(200).json({ error: false, message: "SUCCESS_CATEGORY_DATA_FETCHED", - category: category.getPublicObject(), + channel: channel.getPublicObject(), userInfo: { userListLimit: 50, users: users @@ -120,19 +120,19 @@ app.get("/category/:category/info", [ }); }, undefined, config.roleMap.USER)); -app.get("/category/list", authenticateEndpoint(async (req, res) => { +app.get("/channel/list", authenticateEndpoint(async (req, res) => { let count = parseInt(req.query.count); if (!Number.isInteger(count)) { count = 10; } // TODO: This is probably not efficient - const categories = await Category.find().lean().sort({ _id: -1 }).limit(count).select("-posts -__v").populate("creator", User.getPulicFields()); + const channels = await Channel.find().lean().sort({ _id: -1 }).limit(count).select("-posts -__v").populate("creator", User.getPulicFields()); res.status(200).json({ error: false, message: "SUCCESS_CATEGORY_LIST_FETCHED", - categories + channels }); }, undefined, config.roleMap.USER)); diff --git a/brainlet/api/v1/gateway/index.js b/brainlet/api/v1/gateway/index.js index 5a0ca88..ee07a2a 100644 --- a/brainlet/api/v1/gateway/index.js +++ b/brainlet/api/v1/gateway/index.js @@ -1,7 +1,7 @@ const User = require("../../../models/User"); const secret = require("../../../secret"); const config = require("../../../config"); -const Category = require("../../../models/Category"); +const Channel = require("../../../models/Channel"); const RateLimiter = require("../../../common/util/ratelimiter"); const jwt = require("jsonwebtoken"); @@ -23,15 +23,15 @@ class GatewayServer { } } -GatewayServer.prototype._sendSystemMessage = function(socket, message, category) { +GatewayServer.prototype._sendSystemMessage = function(socket, message, channel) { const messageObject = { author: { username: "__SYSTEM", _id: "5fc69864f15a7c5e504c9a1f" }, - category: { - title: category.title, - _id: category._id + channel: { + title: channel.title, + _id: channel._id }, content: message, _id: uuid.v4() @@ -53,7 +53,7 @@ GatewayServer.prototype._processCommand = async function(socket, message) { switch (command) { case "INVALID_COMMAND": { - this._sendSystemMessage(socket, "Invalid command.", message.category); + this._sendSystemMessage(socket, "Invalid command.", message.channel); break; } case "admin/fr": { @@ -61,33 +61,33 @@ GatewayServer.prototype._processCommand = async function(socket, message) { if (socket.user.permissionLevel >= config.roleMap.ADMIN) { this._gateway.emit("refreshClient", { reason: fullCommand[1] || "REFRESH" }); } else { - this._sendSystemMessage(socket, "how about no", message.category); + this._sendSystemMessage(socket, "how about no", message.channel); } } else { - this._sendSystemMessage(socket, "Invalid number of arguments.", message.category); + this._sendSystemMessage(socket, "Invalid number of arguments.", message.channel); } break; } case "admin/fru": { if (args === 1) { if (socket.user.permissionLevel >= config.roleMap.ADMIN) { - const user = await this._findSocketInRoom(message.category._id, fullCommand[1]); + const user = await this._findSocketInRoom(message.channel._id, fullCommand[1]); if (!user) { - this._sendSystemMessage(socket, "User not found.", message.category); + this._sendSystemMessage(socket, "User not found.", message.channel); break; } this._gateway.in(user.user.sid).emit("refreshClient", { reason: "REFRESH" }); } else { - this._sendSystemMessage(socket, "how about no", message.category); + this._sendSystemMessage(socket, "how about no", message.channel); } } else { - this._sendSystemMessage(socket, "Invalid number of arguments.", message.category); + this._sendSystemMessage(socket, "Invalid number of arguments.", message.channel); } break; } default: { - this._sendSystemMessage(socket, "That command does not exist.", message.category); + this._sendSystemMessage(socket, "That command does not exist.", message.channel); break; } } @@ -170,8 +170,8 @@ GatewayServer.prototype.eventSetup = function() { console.log(`[*] [gateway] [handshake] Got yoo from ${socket.user.username}, connection is finally completed!`); socket.isConnected = true; - socket.on("message", async ({ category, content, nickAuthor, destUser }) => { - if (!category || !content || !socket.joinedCategories || !socket.isConnected || !socket.user || !(typeof content === "string") || !(typeof category._id === "string")) return; + socket.on("message", async ({ channel, content, nickAuthor, destUser }) => { + if (!channel || !content || !socket.joinedChannels || !socket.isConnected || !socket.user || !(typeof content === "string") || !(typeof channel._id === "string")) return; content = content.trim(); if (!content || content === "" || content === " " || content.length >= 2000) return; if (!this.rateLimiter.consoom(socket.user.token)) { // TODO: maybe user ip instead of token? @@ -179,9 +179,9 @@ GatewayServer.prototype.eventSetup = function() { return; } - // TODO: When/if category permissions are added, check if the user has permissions for that category - const categoryTitle = socket.joinedCategories[category._id]; - if (!categoryTitle || !(typeof categoryTitle === "string")) return; + // TODO: When/if channel permissions are added, check if the user has permissions for that channel + const channelTitle = socket.joinedChannels[channel._id]; + if (!channelTitle || !(typeof channelTitle === "string")) return; let messageObject = { author: { @@ -189,9 +189,9 @@ GatewayServer.prototype.eventSetup = function() { _id: socket.user._id, color: socket.user.color }, - category: { - title: categoryTitle, - _id: category._id + channel: { + title: channelTitle, + _id: channel._id }, content: content, _id: uuid.v4() @@ -214,32 +214,32 @@ GatewayServer.prototype.eventSetup = function() { } if (destUser && destUser._id && (typeof destUser._id) === "string") { - const user = await this._findSocketInRoom(messageObject.category._id, destUser._id); + const user = await this._findSocketInRoom(messageObject.channel._id, destUser._id); if (!user) return; this._gateway.in(user.user.sid).emit("message", messageObject); return; } - this._gateway.in(category._id).emit("message", messageObject); + this._gateway.in(channel._id).emit("message", messageObject); }); - socket.on("subscribe", async (categories) => { - if ( !socket.isConnected || !socket.user || !categories || !Array.isArray(categories) || categories === []) return; + socket.on("subscribe", async (channels) => { + if ( !socket.isConnected || !socket.user || !channels || !Array.isArray(channels) || channels === []) return; try { - for (const v of categories) { + for (const v of channels) { if (!v && !(typeof v === "string")) 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 = {}; - if (socket.joinedCategories[v]) continue; - socket.joinedCategories[v] = category.title; + // TODO: When/if channel permissions are added, check if the user has permissions for that channel + const channel = await Channel.findById(v); + if (channel && channel.title && channel._id) { + if (!socket.joinedChannels) socket.joinedChannels = {}; + if (socket.joinedChannels[v]) continue; + socket.joinedChannels[v] = channel.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} (${channel.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, channel.title); this._gateway.in(v).emit("clientListUpdate", upd); } } @@ -255,10 +255,10 @@ GatewayServer.prototype.eventSetup = function() { // Socket io automatically adds a user to a room with their own id if (room === socket.id) return; - const categoryTitle = socket.joinedCategories[room] || "UNKNOWN"; + const channelTitle = socket.joinedChannels[room] || "UNKNOWN"; await socket.leave(room); - const upd = await this._generateClientListUpdateObject(room, categoryTitle); + const upd = await this._generateClientListUpdateObject(room, channelTitle); socket.in(room).emit("clientListUpdate", upd); }); }); @@ -309,11 +309,11 @@ GatewayServer.prototype._findSocketInRoom = async function(room, userid) { return updatedClientList[0] || undefined; }; -GatewayServer.prototype._generateClientListUpdateObject = async function(room, categoryTitle="UNKNOWN") { +GatewayServer.prototype._generateClientListUpdateObject = async function(room, channelTitle="UNKNOWN") { const clientList = await this._getSocketsInRoom(room); return { - category: { - title: categoryTitle, + channel: { + title: channelTitle, _id: room }, clientList diff --git a/brainlet/api/v2/gateway/index.js b/brainlet/api/v2/gateway/index.js index 878ae4a..6ad411b 100644 --- a/brainlet/api/v2/gateway/index.js +++ b/brainlet/api/v2/gateway/index.js @@ -3,7 +3,7 @@ const EventEmitter = require("events"); const uuid = require("uuid"); const User = require("../../../models/User"); -const Category = require("../../../models/Category"); +const Channel = require("../../../models/Channel"); const { parseMessage, opcodeSeparator, getOpcodeByName } = require("./messageparser"); const { checkToken } = require("../../../common/auth/authfunctions"); @@ -57,7 +57,7 @@ class GatewayServer extends EventEmitter { // The user is now successfully authenticated, send the YOO_ACK packet // TODO: This is probably not efficient - let channels = await Category.find().lean().sort({ _id: -1 }).limit(50).select("-posts -__v").populate("creator", User.getPulicFields(true)); + let channels = await Channel.find().lean().sort({ _id: -1 }).limit(50).select("-posts -__v").populate("creator", User.getPulicFields(true)); if (!channels) channels = []; channels = channels.map(x => ({ ...x, _id: x._id.toString() })); diff --git a/brainlet/app/app.html b/brainlet/app/app.html index 5ef28cc..ed2ba9d 100755 --- a/brainlet/app/app.html +++ b/brainlet/app/app.html @@ -77,24 +77,24 @@ - - Create category + + Create channel - + - Close - Create + Close + Create - Create post for {{ selection.category.title }} + Create post for {{ selection.channel.title }} @@ -137,19 +137,19 @@ - -

Browsing category: {{ selection.category.title }}

-

Browsing {{ selection.category.title }}

-

- Browsing {{ selection.category.title }} with - {{ user.user.username }} + +

Browsing channel: {{ selection.channel.title }}

+

Browsing {{ selection.channel.title }}

+

+ Browsing {{ selection.channel.title }} with + {{ user.user.username }}

- arrow_back - refresh + arrow_back + refresh
-
- +
+
by {{ post.creator.username }} @@ -161,7 +161,7 @@ {{ button.text }}
-
+
{{ post.author.username }} @@ -174,26 +174,26 @@
- + add edit - + add Create a new post - + category - Create a new category + Create a new channel - + diff --git a/brainlet/app/resources/js/app.js b/brainlet/app/resources/js/app.js index af68af1..64161c9 100755 --- a/brainlet/app/resources/js/app.js +++ b/brainlet/app/resources/js/app.js @@ -10,8 +10,8 @@ const getCreatePostError = (json) => { case 'body': { return 'Invalid content. Must be between 3 and 1000 characters'; } - case 'category': { - return 'Invalid category. Something went wrong.'; + case 'channel': { + return 'Invalid channel. Something went wrong.'; } default: { return 'Invalid value sent to server. Something went wrong.'; @@ -20,7 +20,7 @@ const getCreatePostError = (json) => { } case 'ERROR_CATEGORY_NOT_FOUND': { - return 'The category you tried to post to no longer exists.'; + return 'The channel you tried to post to no longer exists.'; } case 'ERROR_ACCESS_DENIED': { @@ -33,7 +33,7 @@ const getCreatePostError = (json) => { } } -const getCreateCategoryError = (json) => { +const getCreateChannelError = (json) => { switch (json.message) { case 'ERROR_REQUEST_INVALID_DATA': { switch (json.errors[0].param) { @@ -109,22 +109,22 @@ GatewayConnection.prototype.connect = function(token) { }); }; -GatewayConnection.prototype.sendMessage = function(categoryId, content) { +GatewayConnection.prototype.sendMessage = function(channelId, content) { if (!this.isConnected) return 1; if (content.length >= 2000) return 1; this.socket.emit('message', { - category: { - _id: categoryId + channel: { + _id: channelId }, content }); }; -GatewayConnection.prototype.subscribeToCategoryChat = function(categoryId) { +GatewayConnection.prototype.subscribeToChannelChat = function(channelId) { if (!this.isConnected) return; - const request = [categoryId]; + const request = [channelId]; console.log('[*] [gateway] Subscribing to channel(s)', request); @@ -143,11 +143,11 @@ const app = new Vue({ showApp: false, menuVisible: false, selection: { - category: { + channel: { title: '', browsing: false, _id: undefined, - isCategory: false, + isChannel: false, isChatContext: false }, posts: [] @@ -156,7 +156,7 @@ const app = new Vue({ dialog: { show: { createPost: false, - createCategory: false, + createChannel: false, debug: false }, text: { @@ -164,7 +164,7 @@ const app = new Vue({ title: '', body: '' }, - createCategory: { + createChannel: { title: '' } } @@ -201,7 +201,7 @@ const app = new Vue({ this.loggedInUser = json.user; this.showApp = true; this.performGatewayConnection(); - this.browseCategories(); + this.browseChannels(); Notification.requestPermission(); } else { this.showApp = false; @@ -259,9 +259,9 @@ const app = new Vue({ }); }); }, - shouldMergeMessage: function(messageObject, categoryMessageList) { - const lastMessageIndex = categoryMessageList.length-1; - const lastMessage = categoryMessageList[lastMessageIndex]; + shouldMergeMessage: function(messageObject, channelMessageList) { + const lastMessageIndex = channelMessageList.length-1; + const lastMessage = channelMessageList[lastMessageIndex]; if (!lastMessage) return; if (lastMessage.author._id === messageObject.author._id) { @@ -277,32 +277,32 @@ const app = new Vue({ return false; }, processMessage: async function(messageObject) { - if (!this.messages[messageObject.category._id]) this.$set(this.messages, messageObject.category._id, []); - const categoryMessageList = this.messages[messageObject.category._id]; - const lastMessageIndex = categoryMessageList.length-1; + if (!this.messages[messageObject.channel._id]) this.$set(this.messages, messageObject.channel._id, []); + const channelMessageList = this.messages[messageObject.channel._id]; + const lastMessageIndex = channelMessageList.length-1; - if (this.shouldMergeMessage(messageObject, categoryMessageList)) { - categoryMessageList[lastMessageIndex].content += `\n${messageObject.content}`; + if (this.shouldMergeMessage(messageObject, channelMessageList)) { + channelMessageList[lastMessageIndex].content += `\n${messageObject.content}`; } else { - this.messages[messageObject.category._id].push(messageObject); + this.messages[messageObject.channel._id].push(messageObject); } - if (messageObject.category._id === this.selection.category._id) { + if (messageObject.channel._id === this.selection.channel._id) { this.$nextTick(() => { - // TODO: When the user presses back, actually undo this scroll cause its annoying to scroll back up in the category list + // TODO: When the user presses back, actually undo this scroll cause its annoying to scroll back up in the channel list const container = this.$el.querySelector('#posts-container'); container.scrollTop = container.scrollHeight; }); } - if (messageObject.author.username !== this.loggedInUser.username && messageObject.category._id !== this.selection.category._id) { - this.okNotification(`${messageObject.category.title}/${messageObject.author.username}: ${messageObject.content}`); + if (messageObject.author.username !== this.loggedInUser.username && messageObject.channel._id !== this.selection.channel._id) { + this.okNotification(`${messageObject.channel.title}/${messageObject.author.username}: ${messageObject.content}`); } if (messageObject.author.username !== this.loggedInUser.username) { if (Notification.permission === 'granted') { try { - new Notification(`${messageObject.category.title}/${messageObject.author.username}`, { + new Notification(`${messageObject.channel.title}/${messageObject.author.username}`, { body: messageObject.content }); } catch(e) { @@ -313,20 +313,20 @@ const app = new Vue({ } }, processUserListUpdate: async function(e) { - const { category, clientList } = e; - if (!this.userLists[category._id]) this.$set(this.userLists, category._id, []); - this.userLists[category._id] = clientList; + const { channel, clientList } = e; + if (!this.userLists[channel._id]) this.$set(this.userLists, channel._id, []); + this.userLists[channel._id] = clientList; }, - openChatForCategory: async function(categoryId) { - this.gateway.subscribeToCategoryChat(categoryId); + openChatForChannel: async function(channelId) { + this.gateway.subscribeToChannelChat(channelId); - this.selection.category.isChatContext = true; - this.selection.category.browsing = true; - this.selection.category.title = 'Chat'; - this.selection.category._id = categoryId; + this.selection.channel.isChatContext = true; + this.selection.channel.browsing = true; + this.selection.channel.title = 'Chat'; + this.selection.channel._id = channelId; }, sendCurrentMessage: async function() { - const status = await this.gateway.sendMessage(this.selection.category._id, this.message.typed); + const status = await this.gateway.sendMessage(this.selection.channel._id, this.message.typed); if (status === 1) { this.okNotification('Failed to send message!'); return; @@ -343,9 +343,9 @@ const app = new Vue({ 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`, { + // Channel and post browsing + browseChannels: async function() { + const res = await fetch(`${window.location.origin}/api/v1/content/channel/list?count=50`, { method: 'GET', headers: { 'Accept': 'application/json', @@ -356,36 +356,36 @@ const app = new Vue({ if (res.ok) { const json = await res.json(); - this.selection.category.title = 'categories'; - this.selection.category.browsing = true; - this.selection.category.isCategory = false; - this.selection.category.isChatContext = false; - this.selection.category._id = '__CATEGORY_LIST'; + this.selection.channel.title = 'channels'; + this.selection.channel.browsing = true; + this.selection.channel.isChannel = false; + this.selection.channel.isChatContext = false; + this.selection.channel._id = '__CATEGORY_LIST'; this.selection.posts = []; this.cardButtons = []; this.button('chat', (post) => { if (post._id) { - this.openChatForCategory(post._id); + this.openChatForChannel(post._id); } }); this.button('topic', (post) => { this.browse(post); }); - for (let i = 0; i < json.categories.length; i++) { - const v = json.categories[i]; + for (let i = 0; i < json.channels.length; i++) { + const v = json.channels[i]; this.selection.posts.push({ title: v.title, body: '', _id: v._id, creator: v.creator }); } } else { - this.okNotification('Failed to fetch category list'); + this.okNotification('Failed to fetch channel list'); } }, - browse: async function(category) { - const { _id, title } = category; + browse: async function(channel) { + const { _id, title } = channel; - const res = await fetch(`${window.location.origin}/api/v1/content/category/${_id}/info`, { + const res = await fetch(`${window.location.origin}/api/v1/content/channel/${_id}/info`, { method: 'GET', headers: { 'Accept': 'application/json', @@ -396,39 +396,39 @@ const app = new Vue({ if (res.ok) { const json = await res.json(); - this.selection.category.title = title; - this.selection.category._id = _id; - this.selection.category.browsing = true; - this.selection.category.isCategory = true; - this.selection.category.isChatContext = false; + this.selection.channel.title = title; + this.selection.channel._id = _id; + this.selection.channel.browsing = true; + this.selection.channel.isChannel = true; + this.selection.channel.isChatContext = false; this.selection.posts = []; this.cardButtons = []; - for (let i = 0; i < json.category.posts.length; i++) { - const v = json.category.posts[i]; + for (let i = 0; i < json.channel.posts.length; i++) { + const v = json.channel.posts[i]; this.selection.posts.push({ title: v.title, body: v.body, _id: v._id, creator: v.creator }); } } else { - this.okNotification('Failed to fetch category'); + this.okNotification('Failed to fetch channel'); } }, refresh: function() { - if (this.selection.category.title === 'categories' && this.selection.category.isCategory === false) { - this.browseCategories(); + if (this.selection.channel.title === 'channels' && this.selection.channel.isChannel === false) { + this.browseChannels(); } else { - this.browse(this.selection.category); + this.browse(this.selection.channel); } }, button: function(text, click) { this.cardButtons.push({ text, click }); }, stopBrowsing: function() { - this.selection.category = { + this.selection.channel = { title: '', browsing: false, _id: undefined, - isCategory: false, + isChannel: false, isChatContext: false }; this.selection.posts = []; @@ -457,20 +457,20 @@ const app = new Vue({ // Content creation showCreatePostDialog: function() { - if (!this.selection.category.isCategory) { - this.okNotification('You are not in a category'); + if (!this.selection.channel.isChannel) { + this.okNotification('You are not in a channel'); return; } this.dialog.show.createPost = true; }, createPost: async function() { - if (!this.selection.category.isCategory) { - this.okNotification('You are not in a category'); + if (!this.selection.channel.isChannel) { + this.okNotification('You are not in a channel'); return; } - const category = this.selection.category; + const channel = this.selection.channel; const input = this.dialog.text.createPost; const res = await fetch(`${window.location.origin}/api/v1/content/post/create`, { @@ -481,7 +481,7 @@ const app = new Vue({ }, credentials: 'include', body: JSON.stringify({ - category: category._id, + channel: channel._id, title: input.title, body: input.body }) @@ -490,7 +490,7 @@ const app = new Vue({ if (res.ok) { this.okNotification('Successfully created post'); this.dialog.show.createPost = false; - this.browse(this.selection.category); + this.browse(this.selection.channel); return; } else { if (res.status === 401 || res.status === 403) { @@ -507,10 +507,10 @@ const app = new Vue({ return; } }, - createCategory: async function() { - const input = this.dialog.text.createCategory; + createChannel: async function() { + const input = this.dialog.text.createChannel; - const res = await fetch(`${window.location.origin}/api/v1/content/category/create`, { + const res = await fetch(`${window.location.origin}/api/v1/content/channel/create`, { method: 'POST', headers: { 'Accept': 'application/json', @@ -523,9 +523,9 @@ const app = new Vue({ }); if (res.ok) { - this.okNotification('Successfully created category'); - this.dialog.show.createCategory = false; - this.browseCategories(); + this.okNotification('Successfully created channel'); + this.dialog.show.createChannel = false; + this.browseChannels(); return; } else { if (res.status === 401 || res.status === 403) { @@ -538,7 +538,7 @@ const app = new Vue({ } const json = await res.json(); - this.okNotification(getCreateCategoryError(json)); + this.okNotification(getCreateChannelError(json)); return; } }, diff --git a/brainlet/models/Category.js b/brainlet/models/Channel.js similarity index 67% rename from brainlet/models/Category.js rename to brainlet/models/Channel.js index 129eb42..b565435 100755 --- a/brainlet/models/Category.js +++ b/brainlet/models/Channel.js @@ -2,13 +2,13 @@ const mongoose = require("mongoose"); const Post = require("./Post"); const User = require("./User"); -const categorySchema = new mongoose.Schema({ +const channelSchema = new mongoose.Schema({ title: String, creator: {type: mongoose.Schema.Types.ObjectId, ref: "User"}, posts: [Post.schema] }); -categorySchema.method("getPublicObject", function() { +channelSchema.method("getPublicObject", function() { return { title: this.title, creator: this.populate("creator", User.getPulicFields()).creator, @@ -17,6 +17,6 @@ categorySchema.method("getPublicObject", function() { }; }); -const Category = mongoose.model("Category", categorySchema); +const Channel = mongoose.model("Channel", channelSchema); -module.exports = Category; \ No newline at end of file +module.exports = Channel; \ No newline at end of file diff --git a/brainlet/models/Post.js b/brainlet/models/Post.js index 59530db..c4612a8 100755 --- a/brainlet/models/Post.js +++ b/brainlet/models/Post.js @@ -4,7 +4,7 @@ const Post = mongoose.model("Post", { title: String, body: String, creator: {type: mongoose.Schema.Types.ObjectId, ref: "User"}, - categoryId: {type: mongoose.Schema.Types.ObjectId, ref: "Category"} + channelId: {type: mongoose.Schema.Types.ObjectId, ref: "Channel"} }); module.exports = Post; \ No newline at end of file diff --git a/libbrainlet/bridgebot.js b/libbrainlet/bridgebot.js index 8d13b1d..5b20016 100644 --- a/libbrainlet/bridgebot.js +++ b/libbrainlet/bridgebot.js @@ -50,7 +50,7 @@ const main = async () => { discord.login(secret.discord.token); - const category = client.gateway.subscribeToCategoryChat(LISTEN_ON); + const channel = client.gateway.subscribeToChannelChat(LISTEN_ON); discord.on('message', (e) => { if (e.webhookID) return; diff --git a/libbrainlet/gatewayconnection.js b/libbrainlet/gatewayconnection.js index 729fb93..3173cf5 100644 --- a/libbrainlet/gatewayconnection.js +++ b/libbrainlet/gatewayconnection.js @@ -59,13 +59,13 @@ GatewayConnection.prototype.connect = function(token) { this.socket.on('clientListUpdate', (e) => this.emit('clientListUpdate', e)); }; -GatewayConnection.prototype.sendMessage = function(categoryId, content, { nickAuthor, destUser }) { +GatewayConnection.prototype.sendMessage = function(channelId, content, { nickAuthor, destUser }) { if (!this.isConnected) return 1; if (content.length >= 2000) return 1; this.socket.emit('message', { - category: { - _id: categoryId + channel: { + _id: channelId }, nickAuthor, destUser, @@ -73,16 +73,16 @@ GatewayConnection.prototype.sendMessage = function(categoryId, content, { nickAu }); }; -GatewayConnection.prototype.subscribeToCategoryChat = function(categoryId) { +GatewayConnection.prototype.subscribeToChannelChat = function(channelId) { if (!this.isConnected) return; - const request = [categoryId]; + const request = [channelId]; console.log('[*] [gateway] Subscribing to channel(s)', request); this.socket.emit('subscribe', request); - return categoryId; + return channelId; }; module.exports = GatewayConnection; \ No newline at end of file diff --git a/resources/Docs/DOCS.md b/resources/Docs/DOCS.md index c7b8563..737cf11 100644 --- a/resources/Docs/DOCS.md +++ b/resources/Docs/DOCS.md @@ -23,7 +23,7 @@ Packets can also have JSON as a payload: ## Instructions -The terms "channel" and "category" are used interchangeably. +The terms "channel" and "channel" are used interchangeably. ## 0:HELLO *Part of handshake, Server to client*