client-api: Add support for notifications for threads

According to MSC 3773
This commit is contained in:
Kévin Commaille 2022-10-02 12:51:44 +02:00 committed by Kévin Commaille
parent 4debc88263
commit b57338c1cf
4 changed files with 34 additions and 4 deletions

View File

@ -16,6 +16,7 @@ Improvements:
* Add support for the threads list API (MSC3856 / Matrix 1.4)
* Stabilize support for private read receipts
* Add support for the pagination direction parameter to `/relations` (MSC3715 / Matrix 1.4)
* Add support for notifications for threads (MSC3773 / Matrix 1.4)
# 0.15.1

View File

@ -97,6 +97,15 @@ pub struct RoomEventFilter<'a> {
/// Defaults to `LazyLoadOptions::Disabled`.
#[serde(flatten)]
pub lazy_load_options: LazyLoadOptions,
/// Whether to enable [per-thread notification counts].
///
/// Only applies to the [`sync_events`] endpoint.
///
/// [per-thread notification counts]: https://spec.matrix.org/v1.4/client-server-api/#receiving-notifications
/// [`sync_events`]: crate::sync::sync_events
#[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
pub unread_thread_notifications: bool,
}
impl<'a> RoomEventFilter<'a> {
@ -123,6 +132,7 @@ impl<'a> RoomEventFilter<'a> {
&& self.types.is_none()
&& self.url_filter.is_none()
&& self.lazy_load_options.is_disabled()
&& !self.unread_thread_notifications
}
}
@ -138,6 +148,7 @@ impl IncomingRoomEventFilter {
&& self.types.is_none()
&& self.url_filter.is_none()
&& self.lazy_load_options.is_disabled()
&& !self.unread_thread_notifications
}
}

View File

@ -13,11 +13,11 @@ pub mod v4;
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct UnreadNotificationsCount {
/// The number of unread notifications for this room with the highlight flag set.
/// The number of unread notifications with the highlight flag set.
#[serde(skip_serializing_if = "Option::is_none")]
pub highlight_count: Option<UInt>,
/// The total number of unread notifications for this room.
/// The total number of unread notifications.
#[serde(skip_serializing_if = "Option::is_none")]
pub notification_count: Option<UInt>,
}

View File

@ -15,7 +15,7 @@ use ruma_common::{
},
presence::PresenceState,
serde::{Incoming, Raw},
DeviceKeyAlgorithm, OwnedRoomId,
DeviceKeyAlgorithm, OwnedEventId, OwnedRoomId,
};
use serde::{Deserialize, Serialize};
@ -243,10 +243,27 @@ pub struct JoinedRoom {
#[serde(default, skip_serializing_if = "RoomSummary::is_empty")]
pub summary: RoomSummary,
/// Counts of unread notifications for this room.
/// Counts of [unread notifications] for this room.
///
/// If `unread_thread_notifications` was set to `true` in the [`RoomEventFilter`], these
/// include only the unread notifications for the main timeline.
///
/// [unread notifications]: https://spec.matrix.org/v1.4/client-server-api/#receiving-notifications
/// [`RoomEventFilter`]: crate::filter::RoomEventFilter
#[serde(default, skip_serializing_if = "UnreadNotificationsCount::is_empty")]
pub unread_notifications: UnreadNotificationsCount,
/// Counts of [unread notifications] for threads in this room.
///
/// This is a map from thread root ID to unread notifications in the thread.
///
/// Only set if `unread_thread_notifications` was set to `true` in the [`RoomEventFilter`].
///
/// [unread notifications]: https://spec.matrix.org/v1.4/client-server-api/#receiving-notifications
/// [`RoomEventFilter`]: crate::filter::RoomEventFilter
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub unread_thread_notifications: BTreeMap<OwnedEventId, UnreadNotificationsCount>,
/// The timeline of messages and state changes in the room.
#[serde(default, skip_serializing_if = "Timeline::is_empty")]
pub timeline: Timeline,
@ -290,6 +307,7 @@ impl JoinedRoom {
pub fn is_empty(&self) -> bool {
let is_empty = self.summary.is_empty()
&& self.unread_notifications.is_empty()
&& self.unread_thread_notifications.is_empty()
&& self.timeline.is_empty()
&& self.state.is_empty()
&& self.account_data.is_empty()