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::{
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);
}

View File

@ -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<AnySyncEphemeralRoomEvent>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LeftRoom {
/// The timeline of messages and state changes in the room up to the point