Started work on personal emotes.
This commit is contained in:
parent
db5fac83ab
commit
a4a1f6a65b
16 changed files with 248 additions and 18 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue