From ab832da03eccef5d4b962c2464de819942212456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 7 Dec 2020 14:34:18 +0100 Subject: [PATCH] base: Deserialize ephemeral events. --- matrix_sdk_base/src/client.rs | 20 ++++++++++++++++---- matrix_sdk_base/src/responses.rs | 25 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index cc181edb..f6198c4d 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -55,7 +55,8 @@ use zeroize::Zeroizing; use crate::{ error::Result, responses::{ - AccountData, JoinedRoom, LeftRoom, Presence, Rooms, State, SyncResponse, Timeline, + AccountData, Ephemeral, JoinedRoom, LeftRoom, Presence, Rooms, State, SyncResponse, + Timeline, }, session::Session, store::{InnerSummary, Room, RoomType, StateChanges, Store}, @@ -623,9 +624,20 @@ impl BaseClient { summary.mark_members_missing(); } - rooms - .join - .insert(room_id, JoinedRoom::new(timeline, state, account_data)); + // TODO should we store this? + let ephemeral = Ephemeral { + events: room_info + .ephemeral + .events + .into_iter() + .filter_map(|e| e.deserialize().ok()) + .collect(), + }; + + rooms.join.insert( + room_id, + JoinedRoom::new(timeline, state, account_data, ephemeral), + ); changes.add_room(summary); } diff --git a/matrix_sdk_base/src/responses.rs b/matrix_sdk_base/src/responses.rs index ab363ebe..936f559f 100644 --- a/matrix_sdk_base/src/responses.rs +++ b/matrix_sdk_base/src/responses.rs @@ -4,8 +4,8 @@ use std::collections::BTreeMap; use matrix_sdk_common::{ api::r0::sync::sync_events::DeviceLists, events::{ - presence::PresenceEvent, AnyBasicEvent, AnySyncRoomEvent, AnySyncStateEvent, - AnyToDeviceEvent, + presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, + AnySyncStateEvent, AnyToDeviceEvent, }, identifiers::{DeviceKeyAlgorithm, RoomId}, }; @@ -84,21 +84,34 @@ pub struct JoinedRoom { pub state: State, /// The private data that this user has attached to this room. pub account_data: AccountData, - // /// The ephemeral events in the room that aren't recorded in the timeline or state of the - // /// room. e.g. typing. - // pub ephemeral: Ephemeral, + /// The ephemeral events in the room that aren't recorded in the timeline or state of the + /// room. e.g. typing. + pub ephemeral: Ephemeral, } impl JoinedRoom { - pub fn new(timeline: Timeline, state: State, account_data: AccountData) -> Self { + pub fn new( + timeline: Timeline, + state: State, + account_data: AccountData, + ephemeral: Ephemeral, + ) -> Self { Self { timeline, state, account_data, + ephemeral, } } } +/// The ephemeral events in the room that aren't recorded in the timeline or +/// state of the room. e.g. typing. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Ephemeral { + pub events: Vec, +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct LeftRoom { /// The timeline of messages and state changes in the room up to the point