store: Honor state keys for the state storage.

master
Damir Jelić 2020-12-19 14:44:46 +01:00
parent b05fed5a3b
commit 7abf0c8805
2 changed files with 45 additions and 31 deletions

View File

@ -523,7 +523,7 @@ impl BaseClient {
) -> ( ) -> (
InviteState, InviteState,
BTreeMap<UserId, StrippedMemberEvent>, BTreeMap<UserId, StrippedMemberEvent>,
BTreeMap<String, AnyStrippedStateEvent>, BTreeMap<String, BTreeMap<String, AnyStrippedStateEvent>>,
) { ) {
events.into_iter().fold( events.into_iter().fold(
(InviteState::default(), BTreeMap::new(), BTreeMap::new()), (InviteState::default(), BTreeMap::new(), BTreeMap::new()),
@ -544,7 +544,10 @@ impl BaseClient {
} }
} else { } else {
room_info.handle_state_event(&e); room_info.handle_state_event(&e);
state_events.insert(e.content().event_type().to_owned(), e); state_events
.entry(e.content().event_type().to_owned())
.or_insert_with(BTreeMap::new)
.insert(e.state_key().to_owned(), e);
} }
} }
Err(err) => { Err(err) => {
@ -566,7 +569,7 @@ impl BaseClient {
) -> ( ) -> (
State, State,
BTreeMap<UserId, MemberEvent>, BTreeMap<UserId, MemberEvent>,
BTreeMap<String, AnySyncStateEvent>, BTreeMap<String, BTreeMap<String, AnySyncStateEvent>>,
BTreeSet<UserId>, BTreeSet<UserId>,
) { ) {
let mut state = State::default(); let mut state = State::default();
@ -610,7 +613,10 @@ impl BaseClient {
), ),
} }
} else { } else {
state_events.insert(event.content().event_type().to_owned(), event); state_events
.entry(event.content().event_type().to_owned())
.or_insert_with(BTreeMap::new)
.insert(event.state_key().to_owned(), event);
} }
} }

View File

@ -42,11 +42,11 @@ pub struct StateChanges {
pub presence: BTreeMap<UserId, PresenceEvent>, pub presence: BTreeMap<UserId, PresenceEvent>,
pub members: BTreeMap<RoomId, BTreeMap<UserId, MemberEvent>>, pub members: BTreeMap<RoomId, BTreeMap<UserId, MemberEvent>>,
pub state: BTreeMap<RoomId, BTreeMap<String, AnySyncStateEvent>>, pub state: BTreeMap<RoomId, BTreeMap<String, BTreeMap<String, AnySyncStateEvent>>>,
pub room_account_data: BTreeMap<RoomId, BTreeMap<String, AnyBasicEvent>>, pub room_account_data: BTreeMap<RoomId, BTreeMap<String, AnyBasicEvent>>,
pub room_infos: BTreeMap<RoomId, RoomInfo>, pub room_infos: BTreeMap<RoomId, RoomInfo>,
pub stripped_state: BTreeMap<RoomId, BTreeMap<String, AnyStrippedStateEvent>>, pub stripped_state: BTreeMap<RoomId, BTreeMap<String, BTreeMap<String, AnyStrippedStateEvent>>>,
pub stripped_members: BTreeMap<RoomId, BTreeMap<UserId, StrippedMemberEvent>>, pub stripped_members: BTreeMap<RoomId, BTreeMap<UserId, StrippedMemberEvent>>,
pub invited_room_info: BTreeMap<RoomId, RoomInfo>, pub invited_room_info: BTreeMap<RoomId, RoomInfo>,
} }
@ -77,6 +77,8 @@ impl StateChanges {
self.stripped_state self.stripped_state
.entry(room_id.to_owned()) .entry(room_id.to_owned())
.or_insert_with(BTreeMap::new) .or_insert_with(BTreeMap::new)
.entry(event.content().event_type().to_string())
.or_insert_with(BTreeMap::new)
.insert(event.state_key().to_string(), event); .insert(event.state_key().to_string(), event);
} }
@ -92,7 +94,9 @@ impl StateChanges {
self.state self.state
.entry(room_id.to_owned()) .entry(room_id.to_owned())
.or_insert_with(BTreeMap::new) .or_insert_with(BTreeMap::new)
.insert(event.content().event_type().to_string(), event); .entry(event.content().event_type().to_string())
.or_insert_with(BTreeMap::new)
.insert(event.state_key().to_string(), event);
} }
} }
@ -242,7 +246,8 @@ impl Store {
} }
} }
for (room, events) in &changes.state { for (room, event_types) in &changes.state {
for events in event_types.values() {
for event in events.values() { for event in events.values() {
state.insert( state.insert(
format!( format!(
@ -256,6 +261,7 @@ impl Store {
)?; )?;
} }
} }
}
for (room_id, summary) in &changes.room_infos { for (room_id, summary) in &changes.room_infos {
summaries summaries
@ -280,7 +286,8 @@ impl Store {
} }
} }
for (room, events) in &changes.stripped_state { for (room, event_types) in &changes.stripped_state {
for events in event_types.values() {
for event in events.values() { for event in events.values() {
stripped_state.insert( stripped_state.insert(
format!( format!(
@ -294,6 +301,7 @@ impl Store {
)?; )?;
} }
} }
}
Ok(()) Ok(())
}, },