ruma_client_api/sync/
sync_events.rs

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