diff --git a/src/app/channel/chatHandler.js b/src/app/channel/chatHandler.js index e8a6804..fc11c2e 100644 --- a/src/app/channel/chatHandler.js +++ b/src/app/channel/chatHandler.js @@ -22,7 +22,7 @@ const {userModel} = require('../../schemas/userSchema'); module.exports = class{ constructor(server){ this.server = server; - this.commandPreprocessor = new commandPreprocessor(server) + this.commandPreprocessor = new commandPreprocessor(server, this) } defineListeners(socket){ @@ -89,8 +89,27 @@ module.exports = class{ this.server.io.emit("chatMessage", {user: "Server", flair: "", highLevel: 10, msg, type: "announcement"}); } - relayChannelAnnouncement(socket, msg){ - //This codebase is always at a 10 - this.server.io.in(socket.chan).emit("chatMessage", {user: "Channel", flair: "", highLevel: 10, msg, type: "announcement"}); + relayChannelAnnouncement(chan, msg){ + const activeChan = this.server.activeChannels.get(chan); + + //If channel isn't null + if(activeChan != null){ + //This codebase is always at a 10 + this.server.io.in(chan).emit("chatMessage", {user: "Channel", flair: "", highLevel: 10, msg, type: "announcement"}); + } + } + + clearChat(chan, user){ + const activeChan = this.server.activeChannels.get(chan); + + //If channel isn't null + if(activeChan != null){ + const target = activeChan.userList.get(user); + + //If no user was entered OR the user was found + if(user == null || target != null){ + this.server.io.in(chan).emit("clearChat", {user}); + } + } } } \ No newline at end of file diff --git a/src/app/channel/commandPreprocessor.js b/src/app/channel/commandPreprocessor.js index 805cbf1..4330a0c 100644 --- a/src/app/channel/commandPreprocessor.js +++ b/src/app/channel/commandPreprocessor.js @@ -22,9 +22,10 @@ const permissionModel = require('../../schemas/permissionSchema'); const channelModel = require('../../schemas/channel/channelSchema'); module.exports = class commandPreprocessor{ - constructor(server){ + constructor(server, chatHandler){ this.server = server; - this.commandProcessor = new commandProcessor(server, this); + this.chatHandler = chatHandler; + this.commandProcessor = new commandProcessor(server, this, chatHandler); } async preprocess(socket, data){ @@ -82,27 +83,30 @@ module.exports = class commandPreprocessor{ //If the send flag is true if(this.sendFlag){ //FUCKIN' SEND IT! - this.server.chatHandler.relayChat(this.socket, this.commandArray.join('').trimStart()); + this.chatHandler.relayChat(this.socket, this.commandArray.join('').trimStart()); } } } class commandProcessor{ - constructor(server, preprocessor){ + constructor(server, preprocessor, chatHandler){ this.server = server; this.preprocessor = preprocessor + this.chatHandler = chatHandler; } + //Command keywords get run through .toLowerCase(), so we should use lowercase method names for command methods whisper(){ //splice out our whisper this.preprocessor.commandArray.splice(0,2); //send it - this.server.chatHandler.relayChat(this.preprocessor.socket, this.preprocessor.commandArray.join(''), 'whisper'); + this.chatHandler.relayChat(this.preprocessor.socket, this.preprocessor.commandArray.join(''), 'whisper'); return; } async announce(){ + //Get the current channel from the database const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan}); //Check if the user has permission, and publicly shame them if they don't (lmao) @@ -110,7 +114,7 @@ class commandProcessor{ //splice out our whisper this.preprocessor.commandArray.splice(0,2); //send it - this.server.chatHandler.relayChannelAnnouncement(this.preprocessor.socket, this.preprocessor.commandArray.join('')); + this.chatHandler.relayChannelAnnouncement(this.preprocessor.socket.chan, this.preprocessor.commandArray.join('')); } } @@ -120,7 +124,18 @@ class commandProcessor{ //splice out our whisper this.preprocessor.commandArray.splice(0,2); //send it - this.server.chatHandler.relayServerAnnouncement(this.preprocessor.commandArray.join('')); + this.chatHandler.relayServerAnnouncement(this.preprocessor.commandArray.join('')); + } + } + + async clear(){ + //Get the current channel from the database + const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan}); + + //Check if the user has permission, and publicly shame them if they don't (lmao) + if(!(this.preprocessor.sendFlag = !(await chanDB.permCheck(this.preprocessor.socket.user, 'clearChat')))){ + //Send off the command + this.chatHandler.clearChat(this.preprocessor.socket.chan, this.preprocessor.argumentArray[1]); } } } \ No newline at end of file diff --git a/src/schemas/channel/channelPermissionSchema.js b/src/schemas/channel/channelPermissionSchema.js index 5c83209..16f9c4d 100644 --- a/src/schemas/channel/channelPermissionSchema.js +++ b/src/schemas/channel/channelPermissionSchema.js @@ -64,6 +64,12 @@ const channelPermissionSchema = new mongoose.Schema({ default: "admin", required: true }, + clearChat: { + type: mongoose.SchemaTypes.String, + enum: rankEnum, + default: "admin", + required: true + }, deleteChannel: { type: mongoose.SchemaTypes.String, enum: rankEnum, diff --git a/src/validators/permissionsValidator.js b/src/validators/permissionsValidator.js index 061aaa6..a244b5f 100644 --- a/src/validators/permissionsValidator.js +++ b/src/validators/permissionsValidator.js @@ -123,6 +123,12 @@ module.exports.channelPermissionValidator = { options: module.exports.isRank }, }, + 'channelPermissionsMap.clearChat': { + optional: true, + custom: { + options: module.exports.isRank + }, + }, 'channelPermissionsMap.deleteChannel': { optional: true, custom: { diff --git a/www/css/theme/movie-night.css b/www/css/theme/movie-night.css index c72147b..f5300a0 100644 --- a/www/css/theme/movie-night.css +++ b/www/css/theme/movie-night.css @@ -70,11 +70,16 @@ a{ color: var(--accent0); } -a:hover{ +a:hover, i:hover{ color: var(--focus0-alt0); text-shadow: var(--focus-glow0); } +a:active, i:active{ + color: var(--focus0-alt1); + box-shadow: var(--focus-glow0-alt0); +} + select{ background-color: var(--bg2); border-radius: 0.5em; diff --git a/www/js/channel/chat.js b/www/js/channel/chat.js index 69da64a..f1955a1 100644 --- a/www/js/channel/chat.js +++ b/www/js/channel/chat.js @@ -71,8 +71,22 @@ class chatBox{ } defineListeners(){ - this.client.socket.on("chatMessage", (data) => { - this.displayChat(data); + this.client.socket.on("chatMessage", this.displayChat.bind(this)); + this.client.socket.on("clearChat", this.clearChat.bind(this)); + } + + clearChat(data){ + //If we where passed a user to check + if(data.user != null){ + var clearedChats = document.querySelectorAll(`.chat-entry-${data.user}`); + }else{ + var clearedChats = document.querySelectorAll('.chat-entry'); + } + + //For each chat found + clearedChats.forEach((chat) => { + //fuckin' nukem! + chat.remove(); }); }