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

@@ -128,6 +128,20 @@ impl Channel {
operation: "delete_many",
with: "channel_invites",
})?;
// Delete any unreads.
get_collection("channel_unreads")
.delete_many(
doc! {
"_id.channel": id
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "delete_many",
with: "channel_unreads",
})?;
// Check if there are any attachments we need to delete.
let message_ids = messages

View File

@@ -180,6 +180,8 @@ impl Server {
})?;
}
// ! FIXME: delete any unreads
for with in &["server_members", "server_bans"] {
get_collection(with)
.delete_many(

View File

@@ -1,3 +1,19 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
pub type UserSettings = HashMap<String, (i64, String)>;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ChannelCompositeKey {
pub channel: String,
pub user: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ChannelUnread {
#[serde(rename = "_id")]
pub id: ChannelCompositeKey,
pub last_id: String,
pub mentions: Option<Vec<String>>,
}

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)
}
}