Route which lets clients determine messages that have updated / deleted.

This commit is contained in:
Paul Makles
2021-02-16 09:34:24 +00:00
parent 2bafffbbc1
commit b6b51bca26
7 changed files with 122 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
use crate::database::*;
use crate::util::result::{Error, Result};
use futures::StreamExt;
use mongodb::options::FindOptions;
use mongodb::bson::{Document, doc};
use rocket_contrib::json::JsonValue;
#[get("/<target>/mutual")]
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
let channels = get_collection("channels")
.find(
doc! {
"$or": [
{ "type": "Group" },
],
"$and": [
{ "recipients": &user.id },
{ "recipients": &target.id }
]
},
FindOptions::builder()
.projection(doc! { "_id": 1 })
.build()
)
.await
.map_err(|_| Error::DatabaseError {
operation: "find",
with: "channels",
})?
.filter_map(async move |s| s.ok())
.collect::<Vec<Document>>()
.await
.into_iter()
.filter_map(|x| x.get_str("_id").ok().map(|x| x.to_string()))
.collect::<Vec<String>>();
Ok(json!({
"channels": channels
}))
}

View File

@@ -6,6 +6,7 @@ mod fetch_dms;
mod fetch_relationship;
mod fetch_relationships;
mod fetch_user;
mod find_mutual;
mod get_avatar;
mod get_default_avatar;
mod open_dm;
@@ -22,6 +23,7 @@ pub fn routes() -> Vec<Route> {
fetch_dms::req,
open_dm::req,
// Relationships
find_mutual::req,
fetch_relationships::req,
fetch_relationship::req,
add_friend::req,