store: Honor state keys for the state storage.
parent
b05fed5a3b
commit
7abf0c8805
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,18 +246,20 @@ impl Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (room, events) in &changes.state {
|
for (room, event_types) in &changes.state {
|
||||||
for event in events.values() {
|
for events in event_types.values() {
|
||||||
state.insert(
|
for event in events.values() {
|
||||||
format!(
|
state.insert(
|
||||||
"{}{}{}",
|
format!(
|
||||||
room.as_str(),
|
"{}{}{}",
|
||||||
event.content().event_type(),
|
room.as_str(),
|
||||||
event.state_key(),
|
event.content().event_type(),
|
||||||
)
|
event.state_key(),
|
||||||
.as_bytes(),
|
)
|
||||||
serde_json::to_vec(&event).unwrap(),
|
.as_bytes(),
|
||||||
)?;
|
serde_json::to_vec(&event).unwrap(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,18 +286,20 @@ impl Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (room, events) in &changes.stripped_state {
|
for (room, event_types) in &changes.stripped_state {
|
||||||
for event in events.values() {
|
for events in event_types.values() {
|
||||||
stripped_state.insert(
|
for event in events.values() {
|
||||||
format!(
|
stripped_state.insert(
|
||||||
"{}{}{}",
|
format!(
|
||||||
room.as_str(),
|
"{}{}{}",
|
||||||
event.content().event_type(),
|
room.as_str(),
|
||||||
event.state_key(),
|
event.content().event_type(),
|
||||||
)
|
event.state_key(),
|
||||||
.as_bytes(),
|
)
|
||||||
serde_json::to_vec(&event).unwrap(),
|
.as_bytes(),
|
||||||
)?;
|
serde_json::to_vec(&event).unwrap(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue