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