Skip to content

Commit

Permalink
feat(clienth-api): Implement the simplified sliding sync spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan authored and toger5 committed Jul 25, 2024
1 parent cd22f67 commit 049f337
Show file tree
Hide file tree
Showing 8 changed files with 1,008 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/ruma-client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ unstable-msc2967 = []
unstable-msc3266 = []
unstable-msc3488 = []
unstable-msc3575 = []
unstable-simplified-msc3575 = []
unstable-msc3814 = []
unstable-msc3843 = []
unstable-msc3983 = []
Expand Down
8 changes: 4 additions & 4 deletions crates/ruma-client-api/src/discovery/discover_homeserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Response {
pub authentication: Option<AuthenticationServerInfo>,

/// Information about the homeserver's trusted proxy to use for sliding sync development.
#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
#[serde(rename = "org.matrix.msc3575.proxy", skip_serializing_if = "Option::is_none")]
pub sliding_sync_proxy: Option<SlidingSyncProxyInfo>,
}
Expand All @@ -76,7 +76,7 @@ impl Response {
tile_server: None,
#[cfg(feature = "unstable-msc2965")]
authentication: None,
#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
sliding_sync_proxy: None,
}
}
Expand Down Expand Up @@ -154,15 +154,15 @@ impl AuthenticationServerInfo {
}

/// Information about a discovered sliding sync proxy.
#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
#[derive(Clone, Debug, Deserialize, Hash, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct SlidingSyncProxyInfo {
/// The URL of a sliding sync proxy that is trusted by the homeserver.
pub url: String,
}

#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
impl SlidingSyncProxyInfo {
/// Creates a `SlidingSyncProxyInfo` with the given proxy URL.
pub fn new(url: String) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruma-client-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub enum ErrorKind {
CannotOverwriteMedia,

/// M_UNKNOWN_POS for sliding sync
#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
UnknownPos,

/// M_URL_NOT_SET
Expand Down Expand Up @@ -271,7 +271,7 @@ impl AsRef<str> for ErrorKind {
Self::DuplicateAnnotation => "M_DUPLICATE_ANNOTATION",
Self::NotYetUploaded => "M_NOT_YET_UPLOADED",
Self::CannotOverwriteMedia => "M_CANNOT_OVERWRITE_MEDIA",
#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
Self::UnknownPos => "M_UNKNOWN_POS",
Self::UrlNotSet => "M_URL_NOT_SET",
Self::BadStatus { .. } => "M_BAD_STATUS",
Expand Down
4 changes: 2 additions & 2 deletions crates/ruma-client-api/src/error/kind_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<'de> Visitor<'de> for ErrorKindVisitor {
ErrCode::DuplicateAnnotation => ErrorKind::DuplicateAnnotation,
ErrCode::NotYetUploaded => ErrorKind::NotYetUploaded,
ErrCode::CannotOverwriteMedia => ErrorKind::CannotOverwriteMedia,
#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
ErrCode::UnknownPos => ErrorKind::UnknownPos,
ErrCode::UrlNotSet => ErrorKind::UrlNotSet,
ErrCode::BadStatus => ErrorKind::BadStatus {
Expand Down Expand Up @@ -301,7 +301,7 @@ enum ErrCode {
NotYetUploaded,
#[ruma_enum(alias = "FI.MAU.MSC2246_CANNOT_OVERWRITE_MEDIA")]
CannotOverwriteMedia,
#[cfg(feature = "unstable-msc3575")]
#[cfg(any(feature = "unstable-msc3575", feature = "unstable-simplified-msc3575"))]
UnknownPos,
UrlNotSet,
BadStatus,
Expand Down
3 changes: 3 additions & 0 deletions crates/ruma-client-api/src/sync/sync_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub mod v3;
#[cfg(feature = "unstable-msc3575")]
pub mod v4;

#[cfg(feature = "unstable-simplified-msc3575")]
pub mod v5;

/// Unread notifications count.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
Expand Down
136 changes: 135 additions & 1 deletion crates/ruma-client-api/src/sync/sync_events/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use ruma_events::{
};
use serde::{de::Error as _, Deserialize, Serialize};

use super::{DeviceLists, UnreadNotificationsCount};
use super::{v5, DeviceLists, UnreadNotificationsCount};

const METADATA: Metadata = metadata! {
method: POST,
Expand Down Expand Up @@ -926,6 +926,140 @@ impl Typing {
}
}

impl From<v5::Request> for Request {
fn from(value: v5::Request) -> Self {
Self {
pos: value.pos,
conn_id: value.conn_id,
txn_id: value.txn_id,
timeout: value.timeout,
lists: value
.lists
.into_iter()
.map(|(list_name, list)| (list_name, list.into()))
.collect(),
room_subscriptions: value
.room_subscriptions
.into_iter()
.map(|(room_id, room_subscription)| (room_id, room_subscription.into()))
.collect(),
extensions: value.extensions.into(),

..Default::default()
}
}
}

impl From<v5::request::List> for SyncRequestList {
fn from(value: v5::request::List) -> Self {
Self {
ranges: value.ranges,
room_details: value.room_details.into(),
include_heroes: value.include_heroes,
filters: value.filters.map(Into::into),

// Defaults from Simplified MSC3575.
sort: vec!["by_recency".to_owned(), "by_name".to_owned()],
bump_event_types: vec![
TimelineEventType::RoomMessage,
TimelineEventType::RoomEncrypted,
TimelineEventType::Sticker,
],

..Default::default()
}
}
}

impl From<v5::request::RoomDetails> for RoomDetailsConfig {
fn from(value: v5::request::RoomDetails) -> Self {
Self { required_state: value.required_state, timeline_limit: value.timeline_limit }
}
}

impl From<v5::request::ListFilters> for SyncRequestListFilters {
fn from(value: v5::request::ListFilters) -> Self {
Self {
is_invite: value.is_invite,
not_room_types: value.not_room_types,
..Default::default()
}
}
}

impl From<v5::request::RoomSubscription> for RoomSubscription {
fn from(value: v5::request::RoomSubscription) -> Self {
Self {
required_state: value.required_state,
timeline_limit: value.timeline_limit,
include_heroes: value.include_heroes,
}
}
}

impl From<v5::request::Extensions> for ExtensionsConfig {
fn from(value: v5::request::Extensions) -> Self {
Self {
to_device: value.to_device.into(),
e2ee: value.e2ee.into(),
account_data: value.account_data.into(),
receipts: value.receipts.into(),
typing: value.typing.into(),

..Default::default()
}
}
}

impl From<v5::request::ToDevice> for ToDeviceConfig {
fn from(value: v5::request::ToDevice) -> Self {
Self {
enabled: value.enabled,
limit: value.limit,
since: value.since,
lists: value.lists,
rooms: value.rooms,
}
}
}

impl From<v5::request::E2EE> for E2EEConfig {
fn from(value: v5::request::E2EE) -> Self {
Self { enabled: value.enabled }
}
}

impl From<v5::request::AccountData> for AccountDataConfig {
fn from(value: v5::request::AccountData) -> Self {
Self { enabled: value.enabled, lists: value.lists, rooms: value.rooms }
}
}

impl From<v5::request::Receipts> for ReceiptsConfig {
fn from(value: v5::request::Receipts) -> Self {
Self {
enabled: value.enabled,
lists: value.lists,
rooms: value.rooms.map(|rooms| rooms.into_iter().map(Into::into).collect()),
}
}
}

impl From<v5::request::ReceiptsRoom> for RoomReceiptConfig {
fn from(value: v5::request::ReceiptsRoom) -> Self {
match value {
v5::request::ReceiptsRoom::Room(room_id) => Self::Room(room_id),
_ => Self::AllSubscribed,
}
}
}

impl From<v5::request::Typing> for TypingConfig {
fn from(value: v5::request::Typing) -> Self {
Self { enabled: value.enabled, lists: value.lists, rooms: value.rooms }
}
}

#[cfg(test)]
mod tests {
use ruma_common::owned_room_id;
Expand Down
Loading

0 comments on commit 049f337

Please sign in to comment.