diff --git a/crates/quark/src/impl/mongo/channels/channel_unread.rs b/crates/quark/src/impl/mongo/channels/channel_unread.rs index 0f5fd733..8442f3cc 100644 --- a/crates/quark/src/impl/mongo/channels/channel_unread.rs +++ b/crates/quark/src/impl/mongo/channels/channel_unread.rs @@ -37,30 +37,46 @@ impl AbstractChannelUnread for MongoDb { } async fn acknowledge_channels(&self, user: &str, channels: &[String]) -> Result<()> { + let current_time = Ulid::new().to_string(); + self.col::(COL) - .update_one( + .delete_many( doc! { "_id.channel": { "$in": channels }, - "_id.user": user, + "_id.user": user }, - doc! { - "$unset": { - "mentions": 1_i32 - }, - "$set": { - "last_id": Ulid::new().to_string() - } - }, - UpdateOptions::builder().upsert(true).build(), + None, ) .await - .map(|_| ()) .map_err(|_| Error::DatabaseError { - operation: "update", - with: "channel_unread", + operation: "delete_many", + with: "channel_unreads", + })?; + + self.col::(COL) + .insert_many( + channels + .iter() + .map(|channel| { + doc! { + "_id": { + "channel": channel, + "user": user + }, + "last_id": ¤t_time + } + }) + .collect::>(), + None, + ) + .await + .map_err(|_| Error::DatabaseError { + operation: "update_many", + with: "channel_unreads", }) + .map(|_| ()) } async fn add_mention_to_unread<'a>(