New Feature: Add server-side channel unreads.

This commit is contained in:
Paul
2021-06-16 23:24:31 +01:00
parent d2b17b64e7
commit 4727f997ed
14 changed files with 133 additions and 10 deletions

View File

@@ -253,4 +253,23 @@ impl User {
.flatten()
.collect::<Vec<String>>())
}
/// Utility function to fetch unread objects for user.
pub async fn fetch_unreads(&self) -> Result<Vec<Document>> {
Ok(get_collection("channel_unreads")
.find(
doc! {
"_id.user": &self.id
},
None
)
.await
.map_err(|_| Error::DatabaseError {
operation: "find_one",
with: "user_settings",
})?
.filter_map(async move |s| s.ok())
.collect::<Vec<Document>>()
.await)
}
}