mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
fix: don't return all members on message query / search
This commit is contained in:
@@ -236,6 +236,30 @@ impl Server {
|
||||
.collect::<Vec<Member>>())
|
||||
}
|
||||
|
||||
pub async fn fetch_members_with_ids(id: &str, ids: &Vec<String>) -> Result<Vec<Member>> {
|
||||
Ok(get_collection("server_members")
|
||||
.find(
|
||||
doc! {
|
||||
"_id.server": id,
|
||||
"_id.user": {
|
||||
"$in": ids
|
||||
}
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "server_members",
|
||||
})?
|
||||
.filter_map(async move |s| s.ok())
|
||||
.collect::<Vec<Document>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.filter_map(|x| from_document(x).ok())
|
||||
.collect::<Vec<Member>>())
|
||||
}
|
||||
|
||||
pub async fn fetch_member_ids(id: &str) -> Result<Vec<String>> {
|
||||
Ok(get_collection("server_members")
|
||||
.find(
|
||||
|
||||
@@ -218,7 +218,7 @@ impl User {
|
||||
|
||||
/// Utility function for fetching multiple users from the perspective of one.
|
||||
/// Assumes user has a mutual connection with others.
|
||||
pub async fn fetch_multiple_users(&self, user_ids: Vec<String>) -> Result<Vec<User>> {
|
||||
pub async fn fetch_multiple_users(&self, user_ids: &Vec<String>) -> Result<Vec<User>> {
|
||||
let mut users = vec![];
|
||||
let mut cursor = get_collection("users")
|
||||
.find(
|
||||
|
||||
@@ -104,7 +104,7 @@ pub async fn generate_ready(mut user: User) -> Result<ClientboundNotification> {
|
||||
|
||||
user_ids.remove(&user.id);
|
||||
let mut users = if user_ids.len() > 0 {
|
||||
user.fetch_multiple_users(user_ids.into_iter().collect::<Vec<String>>())
|
||||
user.fetch_multiple_users(&user_ids.into_iter().collect::<Vec<String>>())
|
||||
.await?
|
||||
} else {
|
||||
vec![]
|
||||
|
||||
@@ -16,7 +16,7 @@ pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||
}
|
||||
|
||||
if let Channel::Group { recipients, .. } = target {
|
||||
Ok(json!(user.fetch_multiple_users(recipients).await?))
|
||||
Ok(json!(user.fetch_multiple_users(&recipients).await?))
|
||||
} else {
|
||||
Err(Error::InvalidOperation)
|
||||
}
|
||||
|
||||
@@ -166,13 +166,13 @@ pub async fn req(user: User, target: Ref, options: Options) -> Result<Value> {
|
||||
|
||||
ids.remove(&user.id);
|
||||
let user_ids = ids.into_iter().collect();
|
||||
let users = user.fetch_multiple_users(user_ids).await?;
|
||||
let users = user.fetch_multiple_users(&user_ids).await?;
|
||||
|
||||
if let Channel::TextChannel { server, .. } = target {
|
||||
Ok(json!({
|
||||
"messages": messages,
|
||||
"users": users,
|
||||
"members": Server::fetch_members(&server).await?
|
||||
"members": Server::fetch_members_with_ids(&server, &user_ids).await?
|
||||
}))
|
||||
} else {
|
||||
Ok(json!({
|
||||
|
||||
@@ -108,10 +108,10 @@ pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<Valu
|
||||
}
|
||||
},
|
||||
Sort::Latest => doc! {
|
||||
"_id": -1
|
||||
"_id": -1 as i32
|
||||
},
|
||||
Sort::Oldest => doc! {
|
||||
"_id": 1
|
||||
"_id": 1 as i32
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -142,13 +142,13 @@ pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<Valu
|
||||
|
||||
ids.remove(&user.id);
|
||||
let user_ids = ids.into_iter().collect();
|
||||
let users = user.fetch_multiple_users(user_ids).await?;
|
||||
let users = user.fetch_multiple_users(&user_ids).await?;
|
||||
|
||||
if let Channel::TextChannel { server, .. } = target {
|
||||
Ok(json!({
|
||||
"messages": messages,
|
||||
"users": users,
|
||||
"members": Server::fetch_members(&server).await?
|
||||
"members": Server::fetch_members_with_ids(&server, &user_ids).await?
|
||||
}))
|
||||
} else {
|
||||
Ok(json!({
|
||||
|
||||
@@ -46,6 +46,6 @@ pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||
|
||||
Ok(json!({
|
||||
"members": members,
|
||||
"users": user.fetch_multiple_users(member_ids).await?
|
||||
"users": user.fetch_multiple_users(&member_ids).await?
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub const VERSION: &str = "0.5.3-alpha.12";
|
||||
pub const VERSION: &str = "0.5.3-alpha.13";
|
||||
|
||||
Reference in New Issue
Block a user