New Feature: Add server-side channel unreads.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -180,6 +180,8 @@ impl Server {
|
||||
})?;
|
||||
}
|
||||
|
||||
// ! FIXME: delete any unreads
|
||||
|
||||
for with in &["server_members", "server_bans"] {
|
||||
get_collection(with)
|
||||
.delete_many(
|
||||
|
||||
@@ -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>>,
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user