Started work on personal emotes.
This commit is contained in:
parent
db5fac83ab
commit
a4a1f6a65b
16 changed files with 248 additions and 18 deletions
|
|
@ -56,7 +56,8 @@ module.exports = class{
|
|||
//await this.sendClientMetadata(userDB, socket);
|
||||
await userObj.sendClientMetadata();
|
||||
await userObj.sendSiteEmotes();
|
||||
await userObj.sendChanEmotes();
|
||||
await userObj.sendChanEmotes(chanDB);
|
||||
await userObj.sendPersonalEmotes(userDB);
|
||||
|
||||
//Send out the userlist
|
||||
this.broadcastUserList(socket.chan);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
//local imports
|
||||
const commandPreprocessor = require('./commandPreprocessor');
|
||||
const loggerUtils = require('../../utils/loggerUtils');
|
||||
const linkUtils = require('../../utils/linkUtils');
|
||||
const emoteValidator = require('../../validators/emoteValidator');
|
||||
const {userModel} = require('../../schemas/userSchema');
|
||||
|
||||
module.exports = class{
|
||||
|
|
@ -29,6 +31,7 @@ module.exports = class{
|
|||
socket.on("chatMessage", (data) => {this.handleChat(socket, data)});
|
||||
socket.on("setFlair", (data) => {this.setFlair(socket, data)});
|
||||
socket.on("setHighLevel", (data) => {this.setHighLevel(socket, data)});
|
||||
socket.on("addPersonalEmote", (data) => {this.addPersonalEmote(socket, data)});
|
||||
}
|
||||
|
||||
handleChat(socket, data){
|
||||
|
|
@ -79,6 +82,36 @@ module.exports = class{
|
|||
}
|
||||
}
|
||||
|
||||
async addPersonalEmote(socket, data){
|
||||
//Sanatize and Validate input
|
||||
const name = emoteValidator.manualName(data.name);
|
||||
const link = emoteValidator.manualLink(data.link);
|
||||
|
||||
//If we received good input
|
||||
if(link && name){
|
||||
//Generate marked link object
|
||||
var emote = await linkUtils.markLink(link);
|
||||
|
||||
//If the link we have is an image or video
|
||||
if(emote.type == 'image' || emote.type == 'video'){
|
||||
//Get user document from DB
|
||||
const userDB = await userModel.findOne({user: socket.user.user})
|
||||
|
||||
//if we have a user in the DB
|
||||
if(userDB != null){
|
||||
//Convert marked link into emote object with 1 ez step for only $19.95
|
||||
emote.name = name;
|
||||
|
||||
//add emote to user document emotes list
|
||||
userDB.emotes.push(emote);
|
||||
|
||||
//Save user doc
|
||||
await userDB.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
relayUserChat(socket, msg, type, links){
|
||||
const user = this.server.getSocketInfo(socket);
|
||||
this.relayChat(user.user, user.flair, user.highLevel, msg, type, socket.chan, links)
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ module.exports = class commandPreprocessor{
|
|||
|
||||
//split the command
|
||||
this.splitCommand();
|
||||
|
||||
//Process the command
|
||||
await this.processServerCommand();
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ const channelModel = require('../../schemas/channel/channelSchema');
|
|||
const permissionModel = require('../../schemas/permissionSchema');
|
||||
const flairModel = require('../../schemas/flairSchema');
|
||||
const emoteModel = require('../../schemas/emoteSchema');
|
||||
const { userModel } = require('../../schemas/userSchema');
|
||||
|
||||
module.exports = class{
|
||||
constructor(userDB, chanRank, channel, socket){
|
||||
|
|
@ -111,6 +112,20 @@ module.exports = class{
|
|||
this.emit('chanEmotes', emoteList);
|
||||
}
|
||||
|
||||
async sendPersonalEmotes(userDB){
|
||||
//if we wherent handed a channel document
|
||||
if(userDB == null){
|
||||
//Pull it based on channel name
|
||||
userDB = await userModel.findOne({user: this.user});
|
||||
}
|
||||
|
||||
//Pull emotes from channel
|
||||
const emoteList = userDB.getEmotes();
|
||||
|
||||
//Send it off to the user
|
||||
this.emit('personalEmotes', emoteList);
|
||||
}
|
||||
|
||||
updateFlair(flair){
|
||||
this.flair = flair;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,17 @@ const {mongoose} = require('mongoose');
|
|||
const {validationResult, matchedData} = require('express-validator');
|
||||
|
||||
//Local Imports
|
||||
//Server
|
||||
const server = require('../../server');
|
||||
//DB Models
|
||||
const statModel = require('../statSchema');
|
||||
const {userModel} = require('../userSchema');
|
||||
const permissionModel = require('../permissionSchema');
|
||||
const emoteModel = require('../emoteSchema');
|
||||
//DB Schemas
|
||||
const channelPermissionSchema = require('./channelPermissionSchema');
|
||||
const channelBanSchema = require('./channelBanSchema');
|
||||
//Utils
|
||||
const { exceptionHandler, errorHandler } = require('../../utils/loggerUtils');
|
||||
|
||||
const channelSchema = new mongoose.Schema({
|
||||
|
|
@ -77,7 +81,7 @@ const channelSchema = new mongoose.Schema({
|
|||
type: mongoose.SchemaTypes.String,
|
||||
required: true
|
||||
}],
|
||||
//Not re-using the site-wide schema because post save should call different functions
|
||||
//Not re-using the site-wide schema because post/pre save should call different functions
|
||||
emotes: [{
|
||||
name:{
|
||||
type: mongoose.SchemaTypes.String,
|
||||
|
|
@ -178,6 +182,7 @@ channelSchema.pre('save', async function (next){
|
|||
}
|
||||
}
|
||||
|
||||
//if emotes where modified
|
||||
if(this.isModified('emotes')){
|
||||
//Get the active Channel object from the application side of the house
|
||||
const activeChannel = server.channelManager.activeChannels.get(this.name);
|
||||
|
|
|
|||
|
|
@ -18,10 +18,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
const {mongoose} = require('mongoose');
|
||||
|
||||
//local imports
|
||||
//server
|
||||
const server = require('../server');
|
||||
//DB Models
|
||||
const statModel = require('./statSchema');
|
||||
const flairModel = require('./flairSchema');
|
||||
const permissionModel = require('./permissionSchema');
|
||||
const emoteModel = require('./emoteSchema');
|
||||
//Utils
|
||||
const hashUtil = require('../utils/hashUtils');
|
||||
|
||||
|
||||
|
|
@ -40,7 +44,9 @@ const userSchema = new mongoose.Schema({
|
|||
required: true
|
||||
},
|
||||
email: {
|
||||
type: mongoose.SchemaTypes.String
|
||||
type: mongoose.SchemaTypes.String,
|
||||
optional: true,
|
||||
default: ""
|
||||
},
|
||||
date: {
|
||||
type: mongoose.SchemaTypes.Date,
|
||||
|
|
@ -92,7 +98,24 @@ const userSchema = new mongoose.Schema({
|
|||
type: mongoose.SchemaTypes.ObjectID,
|
||||
default: null,
|
||||
ref: "flair"
|
||||
}
|
||||
},
|
||||
//Not re-using the site-wide schema because post/pre save should call different functions
|
||||
emotes: [{
|
||||
name:{
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true
|
||||
},
|
||||
link:{
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true
|
||||
},
|
||||
type:{
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
enum: emoteModel.typeEnum,
|
||||
default: emoteModel.typeEnum[0]
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
//This is one of those places where you really DON'T want to use an arrow function over an anonymous one!
|
||||
|
|
@ -124,6 +147,15 @@ userSchema.pre('save', async function (next){
|
|||
await this.killAllSessions("Your site-wide rank has changed. Sign-in required.");
|
||||
}
|
||||
|
||||
//if emotes where modified
|
||||
if(this.isModified('emotes')){
|
||||
//Get the active Channel object from the application side of the house
|
||||
server.channelManager.crawlConnections(this.user, (conn)=>{
|
||||
//Send out emotes to each one
|
||||
conn.sendPersonalEmotes(this);
|
||||
});
|
||||
}
|
||||
|
||||
//All is good, continue on saving.
|
||||
next();
|
||||
});
|
||||
|
|
@ -347,6 +379,24 @@ userSchema.methods.getTokeCount = function(){
|
|||
return tokeCount;
|
||||
}
|
||||
|
||||
userSchema.methods.getEmotes = function(){
|
||||
//Create an empty array to hold our emote list
|
||||
const emoteList = [];
|
||||
|
||||
//For each channel emote
|
||||
this.emotes.forEach((emote) => {
|
||||
//Push an object with select information from the emote to the emote list
|
||||
emoteList.push({
|
||||
name: emote.name,
|
||||
link: emote.link,
|
||||
type: emote.type
|
||||
});
|
||||
});
|
||||
|
||||
//return the emote list
|
||||
return emoteList;
|
||||
}
|
||||
|
||||
//note: if you gotta call this from a request authenticated by it's user, make sure to kill that session first!
|
||||
userSchema.methods.killAllSessions = async function(reason = "A full log-out from all devices was requested for your account."){
|
||||
//get authenticated sessions
|
||||
|
|
|
|||
|
|
@ -16,8 +16,34 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
|
||||
//NPM Imports
|
||||
const { check } = require('express-validator');
|
||||
const validator = require('validator');//We need validators for express-less code too!
|
||||
|
||||
module.exports = {
|
||||
name: (field = 'name') => check(field).escape().trim().isAlphanumeric().isLength({min: 1, max: 14}),
|
||||
link: (field = 'link') => check(field).trim().isURL()
|
||||
link: (field = 'link') => check(field).trim().isURL(),
|
||||
manualName: (input) => {
|
||||
//Trim and sanatize input
|
||||
const clean = validator.trim(validator.escape(input));
|
||||
|
||||
//if cleaned input is a proper emote name
|
||||
if(validator.isLength(clean, {min: 1, max: 14}) && validator.isAlphanumeric(clean)){
|
||||
//return cleaned input
|
||||
return clean;
|
||||
}
|
||||
|
||||
//otherwise return false
|
||||
return false;
|
||||
},
|
||||
manualLink: (input) => {
|
||||
//Trim the input
|
||||
const clean = validator.trim(input)
|
||||
|
||||
//If we have a URL return the trimmed input
|
||||
if(validator.isURL(clean)){
|
||||
return clean;
|
||||
}
|
||||
|
||||
//otherwise return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.-->
|
|||
<option>Flair</option>
|
||||
</select>
|
||||
<span class="chat-panel panel-head-spacer-span" id="chat-panel-head-spacer-span"></span>
|
||||
<p class="chat-panel panel-head-element" id="chat-panel-user-count">NULL Users</p>
|
||||
<p class="chat-panel panel-head-element interactive" id="chat-panel-user-count">NULL Users</p>
|
||||
<i class="chat-panel panel-head-element bi-caret-down-fill" id="chat-panel-users-toggle"></i>
|
||||
</div>
|
||||
<div class="chat-panel" id="chat-panel-main-div">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue