mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
fix logic errors
This commit is contained in:
parent
f48ca403cf
commit
39a380dbaf
4 changed files with 18 additions and 22 deletions
|
|
@ -5,7 +5,7 @@ use crate::{services, Ar, Error, Ra, Result};
|
||||||
/// # `GET /_matrix/client/r0/notifications`
|
/// # `GET /_matrix/client/r0/notifications`
|
||||||
///
|
///
|
||||||
/// Gets all events that we have been notified about.
|
/// 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(
|
pub(crate) async fn get_notifications_route(
|
||||||
body: Ar<get_notifications::v3::Request>,
|
body: Ar<get_notifications::v3::Request>,
|
||||||
) -> Result<Ra<get_notifications::v3::Response>> {
|
) -> Result<Ra<get_notifications::v3::Response>> {
|
||||||
|
|
@ -24,7 +24,7 @@ pub(crate) async fn get_notifications_route(
|
||||||
})
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let only = body
|
let highlight = body
|
||||||
.only
|
.only
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|only| only.to_lowercase() == "highlight");
|
.is_some_and(|only| only.to_lowercase() == "highlight");
|
||||||
|
|
@ -33,7 +33,7 @@ pub(crate) async fn get_notifications_route(
|
||||||
sender_user,
|
sender_user,
|
||||||
from,
|
from,
|
||||||
body.limit,
|
body.limit,
|
||||||
only,
|
highlight,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Ra(get_notifications::v3::Response {
|
Ok(Ra(get_notifications::v3::Response {
|
||||||
|
|
|
||||||
|
|
@ -51,20 +51,16 @@ impl service::globals::Data for KeyValueDatabase {
|
||||||
futures.push(self.userroomid_joined.watch_prefix(&userid_prefix));
|
futures.push(self.userroomid_joined.watch_prefix(&userid_prefix));
|
||||||
futures.push(self.userroomid_invitestate.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_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 localpart_bytes = user_id.localpart().as_bytes().to_vec();
|
||||||
let mut localpart_prefix = localpart_bytes.clone();
|
let mut localpart_prefix = localpart_bytes.clone();
|
||||||
localpart_prefix.push(0xFF);
|
localpart_prefix.push(0xFF);
|
||||||
|
|
||||||
|
// Return when we store a notification
|
||||||
futures.push(
|
futures.push(
|
||||||
self.userpducountid_notification.watch_prefix(&localpart_prefix),
|
self.userpducountid_notification.watch_prefix(&localpart_prefix),
|
||||||
);
|
);
|
||||||
|
futures.push(self.userroompducountid.watch_prefix(&localpart_prefix));
|
||||||
|
|
||||||
// Events for rooms we are in
|
// Events for rooms we are in
|
||||||
for room_id in services()
|
for room_id in services()
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
|
||||||
|
|
||||||
let event_id = EventId::parse(
|
let event_id = EventId::parse(
|
||||||
utils::string_from_bytes(
|
utils::string_from_bytes(
|
||||||
value.split(|b| *b == 0xFF).nth(2).unwrap(),
|
value.split(|b| *b == 0xFF).nth(1).unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
|
@ -61,7 +61,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
|
||||||
|
|
||||||
let pdu = services().rooms.timeline.get_pdu(&event_id)?;
|
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;
|
n += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
|
||||||
|
|
||||||
let event_id = EventId::parse(
|
let event_id = EventId::parse(
|
||||||
utils::string_from_bytes(
|
utils::string_from_bytes(
|
||||||
value.split(|b| *b == 0xFF).nth(2).unwrap(),
|
value.split(|b| *b == 0xFF).nth(1).unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
|
@ -96,7 +96,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
|
||||||
|
|
||||||
let pdu = services().rooms.timeline.get_pdu(&event_id)?;
|
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;
|
n += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,7 +217,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
|
||||||
|
|
||||||
let (flags, value) = value.split_at(2);
|
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 {
|
if !notify || highlight && !is_highlight {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -238,7 +238,7 @@ impl service::rooms::user::Data for KeyValueDatabase {
|
||||||
let pdu = services().rooms.timeline.get_pdu(&event_id)?;
|
let pdu = services().rooms.timeline.get_pdu(&event_id)?;
|
||||||
|
|
||||||
// do not bother with missing or redacted PDUs
|
// 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;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,13 @@ impl Service {
|
||||||
notifi.prio = NotificationPriority::High;
|
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.sender = Some(event.sender.clone());
|
||||||
notifi.event_type = Some(event.kind.clone());
|
notifi.event_type = Some(event.kind.clone());
|
||||||
notifi.content =
|
notifi.content =
|
||||||
|
|
@ -308,12 +314,6 @@ impl Service {
|
||||||
.get_name(&event.room_id)?;
|
.get_name(&event.room_id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.send_request(
|
|
||||||
&http.url,
|
|
||||||
send_event_notification::v1::Request::new(notifi),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
// TODO: Handle email
|
// TODO: Handle email
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue