base: Deserialize ephemeral events.

master
Damir Jelić 2020-12-07 14:34:18 +01:00
parent de61798d78
commit ab832da03e
2 changed files with 35 additions and 10 deletions

View File

@ -55,7 +55,8 @@ use zeroize::Zeroizing;
use crate::{ use crate::{
error::Result, error::Result,
responses::{ responses::{
AccountData, JoinedRoom, LeftRoom, Presence, Rooms, State, SyncResponse, Timeline, AccountData, Ephemeral, JoinedRoom, LeftRoom, Presence, Rooms, State, SyncResponse,
Timeline,
}, },
session::Session, session::Session,
store::{InnerSummary, Room, RoomType, StateChanges, Store}, store::{InnerSummary, Room, RoomType, StateChanges, Store},
@ -623,9 +624,20 @@ impl BaseClient {
summary.mark_members_missing(); summary.mark_members_missing();
} }
rooms // TODO should we store this?
.join let ephemeral = Ephemeral {
.insert(room_id, JoinedRoom::new(timeline, state, account_data)); 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); changes.add_room(summary);
} }

View File

@ -4,8 +4,8 @@ use std::collections::BTreeMap;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::sync::sync_events::DeviceLists, api::r0::sync::sync_events::DeviceLists,
events::{ events::{
presence::PresenceEvent, AnyBasicEvent, AnySyncRoomEvent, AnySyncStateEvent, presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
AnyToDeviceEvent, AnySyncStateEvent, AnyToDeviceEvent,
}, },
identifiers::{DeviceKeyAlgorithm, RoomId}, identifiers::{DeviceKeyAlgorithm, RoomId},
}; };
@ -84,21 +84,34 @@ pub struct JoinedRoom {
pub state: State, pub state: State,
/// The private data that this user has attached to this room. /// The private data that this user has attached to this room.
pub account_data: AccountData, pub account_data: AccountData,
// /// The ephemeral events in the room that aren't recorded in the timeline or state of the /// The ephemeral events in the room that aren't recorded in the timeline or state of the
// /// room. e.g. typing. /// room. e.g. typing.
// pub ephemeral: Ephemeral, pub ephemeral: Ephemeral,
} }
impl JoinedRoom { 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 { Self {
timeline, timeline,
state, state,
account_data, 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<AnySyncEphemeralRoomEvent>,
}
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LeftRoom { pub struct LeftRoom {
/// The timeline of messages and state changes in the room up to the point /// The timeline of messages and state changes in the room up to the point