From 39a380dbafc0479c39f10ef54886f8bf65b3c43e Mon Sep 17 00:00:00 2001 From: avdb13 Date: Tue, 20 May 2025 11:24:43 +0000 Subject: [PATCH] fix logic errors --- src/api/client_server/notifications.rs | 6 +++--- src/database/key_value/globals.rs | 8 ++------ src/database/key_value/rooms/user.rs | 12 ++++++------ src/service/pusher.rs | 14 +++++++------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/api/client_server/notifications.rs b/src/api/client_server/notifications.rs index 12e899e2..923beabc 100644 --- a/src/api/client_server/notifications.rs +++ b/src/api/client_server/notifications.rs @@ -5,7 +5,7 @@ use crate::{services, Ar, Error, Ra, Result}; /// # `GET /_matrix/client/r0/notifications` /// /// Gets all events that we have been notified about. -#[allow(dead_code, clippy::unused_async)] +#[allow(clippy::unused_async)] pub(crate) async fn get_notifications_route( body: Ar, ) -> Result> { @@ -24,7 +24,7 @@ pub(crate) async fn get_notifications_route( }) .transpose()?; - let only = body + let highlight = body .only .as_ref() .is_some_and(|only| only.to_lowercase() == "highlight"); @@ -33,7 +33,7 @@ pub(crate) async fn get_notifications_route( sender_user, from, body.limit, - only, + highlight, )?; Ok(Ra(get_notifications::v3::Response { diff --git a/src/database/key_value/globals.rs b/src/database/key_value/globals.rs index 3b2348f9..3dc93b88 100644 --- a/src/database/key_value/globals.rs +++ b/src/database/key_value/globals.rs @@ -51,20 +51,16 @@ impl service::globals::Data for KeyValueDatabase { futures.push(self.userroomid_joined.watch_prefix(&userid_prefix)); futures.push(self.userroomid_invitestate.watch_prefix(&userid_prefix)); futures.push(self.userroomid_leftstate.watch_prefix(&userid_prefix)); - // futures.push( - // self.userroomid_notificationcount.watch_prefix(&userid_prefix), - // ); - // futures - // .push(self.userroomid_highlightcount.watch_prefix(& - // userid_prefix)); let localpart_bytes = user_id.localpart().as_bytes().to_vec(); let mut localpart_prefix = localpart_bytes.clone(); localpart_prefix.push(0xFF); + // Return when we store a notification futures.push( self.userpducountid_notification.watch_prefix(&localpart_prefix), ); + futures.push(self.userroompducountid.watch_prefix(&localpart_prefix)); // Events for rooms we are in for room_id in services() diff --git a/src/database/key_value/rooms/user.rs b/src/database/key_value/rooms/user.rs index 9ebe0189..0fea4b5c 100644 --- a/src/database/key_value/rooms/user.rs +++ b/src/database/key_value/rooms/user.rs @@ -53,7 +53,7 @@ impl service::rooms::user::Data for KeyValueDatabase { let event_id = EventId::parse( utils::string_from_bytes( - value.split(|b| *b == 0xFF).nth(2).unwrap(), + value.split(|b| *b == 0xFF).nth(1).unwrap(), ) .unwrap(), ) @@ -61,7 +61,7 @@ impl service::rooms::user::Data for KeyValueDatabase { let pdu = services().rooms.timeline.get_pdu(&event_id)?; - if flags[0] == 1 && !pdu.map_or(true, |pdu| pdu.is_redacted()) { + if flags[0] != 0 && !pdu.map_or(true, |pdu| !pdu.is_redacted()) { n += 1; } @@ -88,7 +88,7 @@ impl service::rooms::user::Data for KeyValueDatabase { let event_id = EventId::parse( utils::string_from_bytes( - value.split(|b| *b == 0xFF).nth(2).unwrap(), + value.split(|b| *b == 0xFF).nth(1).unwrap(), ) .unwrap(), ) @@ -96,7 +96,7 @@ impl service::rooms::user::Data for KeyValueDatabase { let pdu = services().rooms.timeline.get_pdu(&event_id)?; - if flags[1] == 1 && !pdu.map_or(true, |pdu| pdu.is_redacted()) { + if flags[1] != 0 && !pdu.map_or(true, |pdu| !pdu.is_redacted()) { n += 1; } @@ -217,7 +217,7 @@ impl service::rooms::user::Data for KeyValueDatabase { let (flags, value) = value.split_at(2); - let (notify, is_highlight) = (flags[0] == 1, flags[1] == 1); + let (notify, is_highlight) = (flags[0] != 0, flags[1] != 0); if !notify || highlight && !is_highlight { continue; @@ -238,7 +238,7 @@ impl service::rooms::user::Data for KeyValueDatabase { let pdu = services().rooms.timeline.get_pdu(&event_id)?; // do not bother with missing or redacted PDUs - let Some(pdu) = pdu.filter(|pdu| pdu.is_redacted()) else { + let Some(pdu) = pdu.filter(|pdu| !pdu.is_redacted()) else { continue; }; diff --git a/src/service/pusher.rs b/src/service/pusher.rs index 2b5782a6..c56abf80 100644 --- a/src/service/pusher.rs +++ b/src/service/pusher.rs @@ -288,7 +288,13 @@ impl Service { notifi.prio = NotificationPriority::High; } - if !event_id_only { + if event_id_only { + self.send_request( + &http.url, + send_event_notification::v1::Request::new(notifi), + ) + .await?; + } else { notifi.sender = Some(event.sender.clone()); notifi.event_type = Some(event.kind.clone()); notifi.content = @@ -308,12 +314,6 @@ impl Service { .get_name(&event.room_id)?; } - self.send_request( - &http.url, - send_event_notification::v1::Request::new(notifi), - ) - .await?; - Ok(()) } // TODO: Handle email