Added basic ignore/unignore functionality

This commit is contained in:
rainbow napkin 2026-11-08 21:01:01 -05:00
parent 999fae91b7
commit b80f82b9f2
6 changed files with 139 additions and 1 deletions

View file

@ -132,6 +132,40 @@ class commandProcessor{
//ignore user
await userDB.ignoreByUser(commandObj.argumentArray[1]);
//Update all users sockets on every channel
this.server.crawlConnections(commandObj.socket.user.user, (user)=>{
//syncrhonously fire and forget ignored user list
user.sendIgnoredList(userDB);
});
//disable send flag
return false;
}
async unignore(commandObj){
//If we wherent given a user to ignore
if(commandObj.argumentArray[1] == null){
//Silently return
return;
}
//Attempt to find user DB doc object
const userDB = await userModel.findOne({user: commandObj.socket.user.user});
//Prevent missing users
if(userDB == null){
throw loggerUtils.exceptionSmith("Called from invalid user", "validation");
}
//ignore user
await userDB.unignoreByUser(commandObj.argumentArray[1]);
//Update all users sockets on every channel
this.server.crawlConnections(commandObj.socket.user.user, (user)=>{
//syncrhonously fire and forget ignored user list
user.sendIgnoredList(userDB);
});
//disable send flag
return false;
}

View file

@ -216,6 +216,7 @@ class connectedUser{
chan: Array.from(this.permMap.chan),
},
flair: this.flair,
ignored: (await userDB.getIgnoredUsers()).user
}
//For each flair listed in the Database
@ -332,6 +333,21 @@ class connectedUser{
this.channel.broadcastUserList();
this.sendClientMetadata();
}
/**
* Sends updated ignored list to a client
* @param {Mongoose.Document} userDB - Users DB Document
*/
async sendIgnoredList(userDB){
//if we wherent handed a user document
if(userDB == null){
//Pull it based on user name
userDB = await userModel.findOne({user: this.user});
}
//Retrieve and send updated ignored users list to clients socket
this.emit("ignore", (await userDB.getIgnoredUsers()).user);
}
}
module.exports = connectedUser;

View file

@ -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;