Skip to main content

ruma_client_api/sync/
sync_events.rs

1//! `GET /_matrix/client/*/sync` and `POST /_matrix/client/*/sync`
2//!
3//! Get all new events from all rooms since the last sync or a given point in time.
4
5use js_int::UInt;
6use ruma_common::OwnedUserId;
7use serde::{Deserialize, Serialize};
8
9#[cfg(feature = "unstable-msc4186")]
10pub mod msc4186;
11pub mod v3;
12#[cfg(feature = "unstable-msc4186")]
13pub mod v4;
14
15/// Unread notifications count.
16#[derive(Clone, Debug, Default, Deserialize, Serialize)]
17#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
18pub struct UnreadNotificationsCount {
19    /// The number of unread notifications with the highlight flag set.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub highlight_count: Option<UInt>,
22
23    /// The total number of unread notifications.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub notification_count: Option<UInt>,
26}
27
28impl UnreadNotificationsCount {
29    /// Creates an empty `UnreadNotificationsCount`.
30    pub fn new() -> Self {
31        Default::default()
32    }
33
34    /// Returns true if there are no notification count updates.
35    pub fn is_empty(&self) -> bool {
36        let Self { highlight_count, notification_count } = self;
37        highlight_count.is_none() && notification_count.is_none()
38    }
39}
40
41/// Information on E2E device updates.
42#[derive(Clone, Debug, Default, Deserialize, Serialize)]
43#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
44pub struct DeviceLists {
45    /// List of users who have updated their device identity keys or who now
46    /// share an encrypted room with the client since the previous sync.
47    #[serde(default, skip_serializing_if = "Vec::is_empty")]
48    pub changed: Vec<OwnedUserId>,
49
50    /// List of users who no longer share encrypted rooms since the previous sync
51    /// response.
52    #[serde(default, skip_serializing_if = "Vec::is_empty")]
53    pub left: Vec<OwnedUserId>,
54}
55
56impl DeviceLists {
57    /// Creates an empty `DeviceLists`.
58    pub fn new() -> Self {
59        Default::default()
60    }
61
62    /// Returns true if there are no device list updates.
63    pub fn is_empty(&self) -> bool {
64        let Self { changed, left } = self;
65        changed.is_empty() && left.is_empty()
66    }
67}