mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
@@ -10,6 +10,7 @@ use rocket::serde::json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
use std::collections::HashSet;
|
||||
use std::time::SystemTime;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -340,4 +341,23 @@ impl Message {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_associated_user_ids(&self, ids: &mut HashSet<String>) {
|
||||
ids.insert(self.author.clone());
|
||||
|
||||
if let Content::SystemMessage(sys) = &self.content {
|
||||
match sys {
|
||||
SystemMessage::Text { .. } => {},
|
||||
SystemMessage::UserAdded { id, by } => { ids.insert(id.clone()); ids.insert(by.clone()); },
|
||||
SystemMessage::UserRemove { id, by } => { ids.insert(id.clone()); ids.insert(by.clone()); },
|
||||
SystemMessage::UserJoined { id } => { ids.insert(id.clone()); },
|
||||
SystemMessage::UserLeft { id } => { ids.insert(id.clone()); },
|
||||
SystemMessage::UserKicked { id } => { ids.insert(id.clone()); },
|
||||
SystemMessage::UserBanned { id } => { ids.insert(id.clone()); },
|
||||
SystemMessage::ChannelRenamed { by, .. } => { ids.insert(by.clone()); },
|
||||
SystemMessage::ChannelDescriptionChanged { by } => { ids.insert(by.clone()); },
|
||||
SystemMessage::ChannelIconChanged { by } => { ids.insert(by.clone()); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ pub async fn req(user: User, target: Ref, options: Options) -> Result<Value> {
|
||||
if options.include_users.unwrap_or_else(|| false) {
|
||||
let mut ids = HashSet::new();
|
||||
for message in &messages {
|
||||
ids.insert(message.author.clone());
|
||||
message.add_associated_user_ids(&mut ids);
|
||||
}
|
||||
|
||||
ids.remove(&user.id);
|
||||
|
||||
@@ -137,7 +137,7 @@ pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<Valu
|
||||
if options.include_users.unwrap_or_else(|| false) {
|
||||
let mut ids = HashSet::new();
|
||||
for message in &messages {
|
||||
ids.insert(message.author.clone());
|
||||
message.add_associated_user_ids(&mut ids);
|
||||
}
|
||||
|
||||
ids.remove(&user.id);
|
||||
|
||||
Reference in New Issue
Block a user