base: Correctly store the state events of rooms.
parent
ae33904a93
commit
a4e7dc1042
|
@ -25,7 +25,7 @@ docs = ["encryption", "sqlite_cryptostore", "messages"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1.41"
|
async-trait = "0.1.41"
|
||||||
serde = "1.0.117"
|
serde = { version = "1.0.117", features = ["rc"]}
|
||||||
dashmap= "*"
|
dashmap= "*"
|
||||||
serde_json = "1.0.59"
|
serde_json = "1.0.59"
|
||||||
zeroize = "1.1.1"
|
zeroize = "1.1.1"
|
||||||
|
@ -51,6 +51,8 @@ http = "0.2.1"
|
||||||
tracing-subscriber = "0.2.13"
|
tracing-subscriber = "0.2.13"
|
||||||
tempfile = "3.1.0"
|
tempfile = "3.1.0"
|
||||||
mockito = "0.27.0"
|
mockito = "0.27.0"
|
||||||
|
rustyline = "7.0.0"
|
||||||
|
syntect = "4.4.0"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||||
tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] }
|
tokio = { version = "0.2.22", default-features = false, features = ["rt-threaded", "macros"] }
|
||||||
|
|
|
@ -32,7 +32,7 @@ use matrix_sdk_common::{
|
||||||
room::member::MemberEventContent, AnyBasicEvent, AnyStrippedStateEvent, AnySyncRoomEvent,
|
room::member::MemberEventContent, AnyBasicEvent, AnyStrippedStateEvent, AnySyncRoomEvent,
|
||||||
AnySyncStateEvent, StateEvent, SyncStateEvent,
|
AnySyncStateEvent, StateEvent, SyncStateEvent,
|
||||||
},
|
},
|
||||||
identifiers::{RoomId, UserId},
|
identifiers::{RoomId, UserId, room_id},
|
||||||
locks::RwLock,
|
locks::RwLock,
|
||||||
Raw,
|
Raw,
|
||||||
};
|
};
|
||||||
|
@ -49,7 +49,7 @@ use matrix_sdk_crypto::{
|
||||||
Device, EncryptionSettings, IncomingResponse, OlmError, OlmMachine, OutgoingRequest, Sas,
|
Device, EncryptionSettings, IncomingResponse, OlmError, OlmMachine, OutgoingRequest, Sas,
|
||||||
ToDeviceRequest, UserDevices,
|
ToDeviceRequest, UserDevices,
|
||||||
};
|
};
|
||||||
use tracing::{info, warn};
|
use tracing::{error, info, warn};
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -58,7 +58,7 @@ use crate::{
|
||||||
AccountData, Ephemeral, JoinedRoom, LeftRoom, Presence, Rooms, State, SyncResponse,
|
AccountData, Ephemeral, JoinedRoom, LeftRoom, Presence, Rooms, State, SyncResponse,
|
||||||
Timeline,
|
Timeline,
|
||||||
},
|
},
|
||||||
rooms::{RoomInfo, Room, RoomType},
|
rooms::{Room, RoomInfo, RoomType},
|
||||||
session::Session,
|
session::Session,
|
||||||
store::{StateChanges, Store},
|
store::{StateChanges, Store},
|
||||||
};
|
};
|
||||||
|
@ -515,18 +515,25 @@ impl BaseClient {
|
||||||
let mut state = State::default();
|
let mut state = State::default();
|
||||||
|
|
||||||
for e in events {
|
for e in events {
|
||||||
if let Ok(event) = hoist_and_deserialize_state_event(e) {
|
match hoist_and_deserialize_state_event(e) {
|
||||||
match &event {
|
Ok(event) => {
|
||||||
AnySyncStateEvent::RoomMember(member) => {
|
match &event {
|
||||||
handle_membership(&mut changes, room_id, member);
|
AnySyncStateEvent::RoomMember(member) => {
|
||||||
}
|
handle_membership(&mut changes, room_id, member);
|
||||||
e => {
|
}
|
||||||
summary.handle_state_event(&e);
|
e => {
|
||||||
changes.add_state_event(room_id, e.clone());
|
summary.handle_state_event(&e);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
state.events.push(event);
|
changes.add_state_event(room_id, e.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state.events.push(event);
|
||||||
|
}
|
||||||
|
Err(err) => warn!(
|
||||||
|
"Couldn't deserialize state event for room {}: {:?} {:#?}",
|
||||||
|
room_id, err, e
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ 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.state_key().to_string(), event);
|
.insert(event.content().event_type().to_string(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_event(room_id: &RoomId, event: SyncStateEvent<MemberEventContent>) -> Self {
|
pub fn from_event(room_id: &RoomId, event: SyncStateEvent<MemberEventContent>) -> Self {
|
||||||
|
@ -254,13 +254,13 @@ impl Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (room, events) in &changes.state {
|
for (room, events) in &changes.state {
|
||||||
for (state_key, event) in events {
|
for (_, event) in events {
|
||||||
state.insert(
|
state.insert(
|
||||||
format!(
|
format!(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
room.as_str(),
|
room.as_str(),
|
||||||
event.content().event_type(),
|
event.content().event_type(),
|
||||||
state_key
|
event.state_key(),
|
||||||
)
|
)
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
serde_json::to_vec(&event).unwrap(),
|
serde_json::to_vec(&event).unwrap(),
|
||||||
|
@ -335,6 +335,12 @@ impl Store {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_room_infos(&self) -> impl Stream<Item = RoomInfo> {
|
||||||
|
stream::iter(
|
||||||
|
self.room_summaries.iter().map(|r| serde_json::from_slice(&r.unwrap().1).unwrap())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_session(&self) -> Option<Session> {
|
pub fn get_session(&self) -> Option<Session> {
|
||||||
self.session
|
self.session
|
||||||
.get("session")
|
.get("session")
|
||||||
|
|
Loading…
Reference in New Issue