base: Store main account data.
parent
e38f0762ee
commit
5c608ed474
|
@ -639,13 +639,7 @@ impl BaseClient {
|
|||
|
||||
rooms.join.insert(
|
||||
room_id,
|
||||
JoinedRoom::new(
|
||||
timeline,
|
||||
state,
|
||||
account_data,
|
||||
ephemeral,
|
||||
notification_count,
|
||||
),
|
||||
JoinedRoom::new(timeline, state, account_data, ephemeral, notification_count),
|
||||
);
|
||||
|
||||
changes.add_room(summary);
|
||||
|
@ -684,6 +678,12 @@ impl BaseClient {
|
|||
}
|
||||
}
|
||||
|
||||
for event in &response.account_data.events {
|
||||
if let Ok(e) = event.deserialize() {
|
||||
changes.add_account_data(e);
|
||||
}
|
||||
}
|
||||
|
||||
self.store.save_changes(&changes).await;
|
||||
*self.sync_token.write().await = Some(response.next_batch.clone());
|
||||
self.apply_changes(&changes).await;
|
||||
|
@ -694,6 +694,9 @@ impl BaseClient {
|
|||
presence: Presence {
|
||||
events: changes.presence.into_iter().map(|(_, v)| v).collect(),
|
||||
},
|
||||
account_data: AccountData {
|
||||
events: changes.account_data.into_iter().map(|(_, e)| e).collect(),
|
||||
},
|
||||
device_lists: response.device_lists,
|
||||
device_one_time_keys_count: response
|
||||
.device_one_time_keys_count
|
||||
|
|
|
@ -20,8 +20,8 @@ pub struct SyncResponse {
|
|||
pub rooms: Rooms,
|
||||
/// Updates to the presence status of other users.
|
||||
pub presence: Presence,
|
||||
///// The global private data created by this user.
|
||||
//pub account_data: AccountData,
|
||||
/// The global private data created by this user.
|
||||
pub account_data: AccountData,
|
||||
/// Messages sent dirrectly between devices.
|
||||
pub to_device: ToDevice,
|
||||
/// Information on E2E device updates.
|
||||
|
|
|
@ -30,6 +30,7 @@ use tracing::info;
|
|||
pub struct Store {
|
||||
inner: Db,
|
||||
session: Tree,
|
||||
account_data: Tree,
|
||||
members: Tree,
|
||||
joined_user_ids: Tree,
|
||||
invited_user_ids: Tree,
|
||||
|
@ -46,6 +47,7 @@ pub struct StateChanges {
|
|||
pub session: Option<Session>,
|
||||
pub members: BTreeMap<RoomId, BTreeMap<UserId, SyncStateEvent<MemberEventContent>>>,
|
||||
pub state: BTreeMap<RoomId, BTreeMap<String, AnySyncStateEvent>>,
|
||||
pub account_data: BTreeMap<String, AnyBasicEvent>,
|
||||
pub room_account_data: BTreeMap<RoomId, BTreeMap<String, AnyBasicEvent>>,
|
||||
pub room_summaries: BTreeMap<RoomId, InnerSummary>,
|
||||
// display_names: BTreeMap<RoomId, BTreeMap<String, BTreeMap<UserId, ()>>>,
|
||||
|
@ -97,6 +99,11 @@ impl StateChanges {
|
|||
.insert(room.room_id.as_ref().to_owned(), room);
|
||||
}
|
||||
|
||||
pub fn add_account_data(&mut self, event: AnyBasicEvent) {
|
||||
self.account_data
|
||||
.insert(event.content().event_type().to_owned(), event);
|
||||
}
|
||||
|
||||
pub fn add_room_account_data(&mut self, room_id: &RoomId, event: AnyBasicEvent) {
|
||||
self.room_account_data
|
||||
.entry(room_id.to_owned())
|
||||
|
@ -501,6 +508,7 @@ impl InnerSummary {
|
|||
impl Store {
|
||||
fn open_helper(db: Db) -> Self {
|
||||
let session = db.open_tree("session").unwrap();
|
||||
let account_data = db.open_tree("account_data").unwrap();
|
||||
|
||||
let members = db.open_tree("members").unwrap();
|
||||
let joined_user_ids = db.open_tree("joined_user_ids").unwrap();
|
||||
|
@ -514,6 +522,7 @@ impl Store {
|
|||
Self {
|
||||
inner: db,
|
||||
session,
|
||||
account_data,
|
||||
members,
|
||||
joined_user_ids,
|
||||
invited_user_ids,
|
||||
|
@ -553,6 +562,7 @@ impl Store {
|
|||
pub async fn save_changes(&self, changes: &StateChanges) {
|
||||
let ret: TransactionResult<()> = (
|
||||
&self.session,
|
||||
&self.account_data,
|
||||
&self.members,
|
||||
&self.joined_user_ids,
|
||||
&self.invited_user_ids,
|
||||
|
@ -564,6 +574,7 @@ impl Store {
|
|||
.transaction(
|
||||
|(
|
||||
session,
|
||||
account_data,
|
||||
members,
|
||||
joined,
|
||||
invited,
|
||||
|
@ -585,6 +596,11 @@ impl Store {
|
|||
}
|
||||
}
|
||||
|
||||
for (event_type, event) in &changes.account_data {
|
||||
account_data
|
||||
.insert(event_type.as_str(), serde_json::to_vec(&event).unwrap())?;
|
||||
}
|
||||
|
||||
for (room, events) in &changes.room_account_data {
|
||||
for (event_type, event) in events {
|
||||
room_account_data.insert(
|
||||
|
|
Loading…
Reference in New Issue