Finished up with personal emotes.
This commit is contained in:
parent
a4a1f6a65b
commit
93cece48ea
5 changed files with 103 additions and 50 deletions
|
|
@ -32,6 +32,7 @@ module.exports = class{
|
|||
socket.on("setFlair", (data) => {this.setFlair(socket, data)});
|
||||
socket.on("setHighLevel", (data) => {this.setHighLevel(socket, data)});
|
||||
socket.on("addPersonalEmote", (data) => {this.addPersonalEmote(socket, data)});
|
||||
socket.on("deletePersonalEmote", (data) => {this.deletePersonalEmote(socket, data)});
|
||||
}
|
||||
|
||||
handleChat(socket, data){
|
||||
|
|
@ -112,6 +113,16 @@ module.exports = class{
|
|||
}
|
||||
}
|
||||
|
||||
async deletePersonalEmote(socket, data){
|
||||
//Get user doc from DB based on socket
|
||||
const userDB = await userModel.findOne({user: socket.user.user});
|
||||
|
||||
//if we found a user
|
||||
if(userDB != null){
|
||||
await userDB.deleteEmote(data.name);
|
||||
}
|
||||
}
|
||||
|
||||
relayUserChat(socket, msg, type, links){
|
||||
const user = this.server.getSocketInfo(socket);
|
||||
this.relayChat(user.user, user.flair, user.highLevel, msg, type, socket.chan, links)
|
||||
|
|
|
|||
|
|
@ -268,40 +268,6 @@ userSchema.statics.tattooToke = function(tokemap){
|
|||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
userSchema.methods.checkPass = function(pass){
|
||||
return hashUtil.comparePassword(pass, this.pass);
|
||||
}
|
||||
|
||||
userSchema.methods.getAuthenticatedSessions = async function(){
|
||||
var returnArr = [];
|
||||
|
||||
//retrieve active sessions (they really need to implement this shit async already)
|
||||
return new Promise((resolve) => {
|
||||
server.store.all((err, sessions) => {
|
||||
//You guys ever hear of a 'not my' problem? Fucking y33tskies lmao, better use a try/catch
|
||||
if(err){
|
||||
throw err;
|
||||
|
||||
}
|
||||
|
||||
//crawl through active sessions
|
||||
sessions.forEach((session) => {
|
||||
//if a session matches the current user
|
||||
if(session.user.id == this.id){
|
||||
//we return it
|
||||
returnArr.push(session);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
resolve(returnArr);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
userSchema.statics.getUserList = async function(fullList = false){
|
||||
var userList = [];
|
||||
//Get all of our users
|
||||
|
|
@ -337,6 +303,39 @@ userSchema.statics.getUserList = async function(fullList = false){
|
|||
}
|
||||
|
||||
//methods
|
||||
userSchema.methods.checkPass = function(pass){
|
||||
return hashUtil.comparePassword(pass, this.pass);
|
||||
}
|
||||
|
||||
userSchema.methods.getAuthenticatedSessions = async function(){
|
||||
var returnArr = [];
|
||||
|
||||
//retrieve active sessions (they really need to implement this shit async already)
|
||||
return new Promise((resolve) => {
|
||||
server.store.all((err, sessions) => {
|
||||
//You guys ever hear of a 'not my' problem? Fucking y33tskies lmao, better use a try/catch
|
||||
if(err){
|
||||
throw err;
|
||||
|
||||
}
|
||||
|
||||
//crawl through active sessions
|
||||
sessions.forEach((session) => {
|
||||
//if a session matches the current user
|
||||
if(session.user.id == this.id){
|
||||
//we return it
|
||||
returnArr.push(session);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
resolve(returnArr);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
userSchema.methods.getProfile = function(){
|
||||
//Create profile hashtable
|
||||
const profile = {
|
||||
|
|
@ -397,6 +396,22 @@ userSchema.methods.getEmotes = function(){
|
|||
return emoteList;
|
||||
}
|
||||
|
||||
userSchema.methods.deleteEmote = async function(name){
|
||||
//Get index by emote name
|
||||
const emoteIndex = this.emotes.findIndex(checkName);
|
||||
|
||||
//Splice out found emote
|
||||
this.emotes.splice(emoteIndex, 1);
|
||||
|
||||
//Save the user doc
|
||||
await this.save();
|
||||
|
||||
function checkName(emote){
|
||||
//return emotes
|
||||
return emote.name == name;
|
||||
}
|
||||
}
|
||||
|
||||
//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