forked from jmug/stoatchat
fix: marking server as read would not mark it as read
fixes #169 Porting code forwards from an older revision of the codebase; https://github.com/revoltchat/backend/blob/0.5.3-alpha.10/src/database/entities/server.rs
This commit is contained in:
@@ -37,30 +37,46 @@ impl AbstractChannelUnread for MongoDb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn acknowledge_channels(&self, user: &str, channels: &[String]) -> Result<()> {
|
async fn acknowledge_channels(&self, user: &str, channels: &[String]) -> Result<()> {
|
||||||
|
let current_time = Ulid::new().to_string();
|
||||||
|
|
||||||
self.col::<Document>(COL)
|
self.col::<Document>(COL)
|
||||||
.update_one(
|
.delete_many(
|
||||||
doc! {
|
doc! {
|
||||||
"_id.channel": {
|
"_id.channel": {
|
||||||
"$in": channels
|
"$in": channels
|
||||||
},
|
},
|
||||||
"_id.user": user,
|
"_id.user": user
|
||||||
},
|
},
|
||||||
doc! {
|
None,
|
||||||
"$unset": {
|
|
||||||
"mentions": 1_i32
|
|
||||||
},
|
|
||||||
"$set": {
|
|
||||||
"last_id": Ulid::new().to_string()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
UpdateOptions::builder().upsert(true).build(),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
|
||||||
.map_err(|_| Error::DatabaseError {
|
.map_err(|_| Error::DatabaseError {
|
||||||
operation: "update",
|
operation: "delete_many",
|
||||||
with: "channel_unread",
|
with: "channel_unreads",
|
||||||
|
})?;
|
||||||
|
|
||||||
|
self.col::<Document>(COL)
|
||||||
|
.insert_many(
|
||||||
|
channels
|
||||||
|
.iter()
|
||||||
|
.map(|channel| {
|
||||||
|
doc! {
|
||||||
|
"_id": {
|
||||||
|
"channel": channel,
|
||||||
|
"user": user
|
||||||
|
},
|
||||||
|
"last_id": ¤t_time
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<Document>>(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|_| Error::DatabaseError {
|
||||||
|
operation: "update_many",
|
||||||
|
with: "channel_unreads",
|
||||||
})
|
})
|
||||||
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_mention_to_unread<'a>(
|
async fn add_mention_to_unread<'a>(
|
||||||
|
|||||||
Reference in New Issue
Block a user