Added basic ignore/unignore functionality
This commit is contained in:
parent
999fae91b7
commit
b80f82b9f2
6 changed files with 139 additions and 1 deletions
|
|
@ -687,6 +687,12 @@ userSchema.methods.ignoreByUserDoc = async function(userDB){
|
|||
throw loggerUtils.exceptionSmith("User not found", "validation");
|
||||
}
|
||||
|
||||
//if someone is trying to self-ignore
|
||||
if(userDB._id.equals(this._id)){
|
||||
//Remind them of the brutal truth that is reality
|
||||
throw loggerUtils.exceptionSmith("YOU CANNOT ESCAPE THE PRISON THAT IS YOUR MIND!!!", "validation");
|
||||
}
|
||||
|
||||
if(this.ignored.includes(userDB._id)){
|
||||
throw loggerUtils.exceptionSmith("User already ignored", "validation");
|
||||
}
|
||||
|
|
@ -700,6 +706,41 @@ userSchema.methods.ignoreByUserDoc = async function(userDB){
|
|||
console.log(await this.getIgnoredUsers());
|
||||
}
|
||||
|
||||
/**
|
||||
* un-ignores a given user by their username
|
||||
* @param {Mongoose.Document} userDB - DB Document of user to ignore
|
||||
*/
|
||||
userSchema.methods.unignoreByUser = async function(user){
|
||||
//Pull user doc from DB
|
||||
const userDB = await this.constructor.findOne({user});
|
||||
//Do an unignorem user by username
|
||||
await this.unignoreByUserDoc(userDB);
|
||||
}
|
||||
|
||||
/**
|
||||
* un-ignores a given user by their DB Document
|
||||
* @param {Mongoose.Document} userDB - DB Document of user to ignore
|
||||
*/
|
||||
userSchema.methods.unignoreByUserDoc = async function(userDB){
|
||||
//Prevent missing users
|
||||
if(userDB == null){
|
||||
throw loggerUtils.exceptionSmith("User not found", "validation");
|
||||
}
|
||||
|
||||
//prevent double un-ignoring
|
||||
if(!this.ignored.includes(userDB._id)){
|
||||
throw loggerUtils.exceptionSmith("User not ignored", "validation");
|
||||
}
|
||||
|
||||
//Filter user out of ignored array
|
||||
this.ignored = this.ignored.filter((id)=>{return !id.equals(userDB._id)});
|
||||
|
||||
//Save the DB document
|
||||
await this.save();
|
||||
|
||||
console.log(await this.getIgnoredUsers());
|
||||
}
|
||||
|
||||
userSchema.methods.getIgnoredUsers = async function(fetchAlts = true){
|
||||
//Not me commiting ancient fucking sin
|
||||
const _this = this;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue