Skip to main content

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::{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        let Self { highlight_count, notification_count } = self;
36        highlight_count.is_none() && notification_count.is_none()
37    }
38}
39
40/// Information on E2E device updates.
41#[derive(Clone, Debug, Default, Deserialize, Serialize)]
42#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
43pub struct DeviceLists {
44    /// List of users who have updated their device identity keys or who now
45    /// share an encrypted room with the client since the previous sync.
46    #[serde(default, skip_serializing_if = "Vec::is_empty")]
47    pub changed: Vec<OwnedUserId>,
48
49    /// List of users who no longer share encrypted rooms since the previous sync
50    /// response.
51    #[serde(default, skip_serializing_if = "Vec::is_empty")]
52    pub left: Vec<OwnedUserId>,
53}
54
55impl DeviceLists {
56    /// Creates an empty `DeviceLists`.
57    pub fn new() -> Self {
58        Default::default()
59    }
60
61    /// Returns true if there are no device list updates.
62    pub fn is_empty(&self) -> bool {
63        let Self { changed, left } = self;
64        changed.is_empty() && left.is_empty()
65    }
66}