fix logic errors

This commit is contained in:
avdb13 2025-05-20 11:24:43 +00:00
parent f48ca403cf
commit 39a380dbaf
4 changed files with 18 additions and 22 deletions

View file

@ -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<get_notifications::v3::Request>,
) -> Result<Ra<get_notifications::v3::Response>> {
@ -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 {

View file

@ -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()

View file

@ -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;
};

View file

@ -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