mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
Include servers in mutual route.
This commit is contained in:
@@ -29,6 +29,34 @@ pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||
.into_iter()
|
||||
.filter_map(|x| x.get_str("_id").ok().map(|x| x.to_string()))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
let server_ids = User::fetch_server_ids(&user.id).await?;
|
||||
let servers = get_collection("server_members")
|
||||
.find(
|
||||
doc! {
|
||||
"_id.user": &target.id,
|
||||
"_id.server": {
|
||||
"$in": server_ids
|
||||
}
|
||||
},
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find_one",
|
||||
with: "server_members",
|
||||
})?
|
||||
.filter_map(async move |s| s.ok())
|
||||
.collect::<Vec<Document>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.filter_map(|x| {
|
||||
x.get_document("_id")
|
||||
.ok()
|
||||
.map(|i| i.get_str("server").ok().map(|x| x.to_string()))
|
||||
})
|
||||
.flatten()
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok(json!({ "users": users }))
|
||||
Ok(json!({ "users": users, "servers": servers }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user