matrix-sdk: Bump ruma

master
Damir Jelić 2021-05-12 16:21:44 +02:00
parent 4c09c6272b
commit 77c2a4ed4f
15 changed files with 140 additions and 101 deletions

View File

@ -1573,7 +1573,7 @@ impl Client {
MIN_UPLOAD_REQUEST_TIMEOUT, MIN_UPLOAD_REQUEST_TIMEOUT,
); );
let request = assign!(create_content::Request::new(data), { let request = assign!(create_content::Request::new(&data), {
content_type: Some(content_type.essence_str()), content_type: Some(content_type.essence_str()),
}); });

View File

@ -15,7 +15,12 @@
use std::ops::Deref; use std::ops::Deref;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::push::get_notifications::Notification, events::AnySyncRoomEvent, identifiers::RoomId, api::r0::push::get_notifications::Notification,
events::{
fully_read::FullyReadEventContent, AnySyncRoomEvent, GlobalAccountDataEvent,
RoomAccountDataEvent,
},
identifiers::RoomId,
}; };
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
@ -27,7 +32,6 @@ use crate::{
hangup::HangupEventContent, invite::InviteEventContent, hangup::HangupEventContent, invite::InviteEventContent,
}, },
custom::CustomEventContent, custom::CustomEventContent,
fully_read::FullyReadEventContent,
ignored_user_list::IgnoredUserListEventContent, ignored_user_list::IgnoredUserListEventContent,
presence::PresenceEvent, presence::PresenceEvent,
push_rules::PushRulesEventContent, push_rules::PushRulesEventContent,
@ -45,9 +49,9 @@ use crate::{
tombstone::TombstoneEventContent, tombstone::TombstoneEventContent,
}, },
typing::TypingEventContent, typing::TypingEventContent,
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
AnySyncStateEvent, BasicEvent, StrippedStateEvent, SyncEphemeralRoomEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, AnySyncStateEvent, StrippedStateEvent,
SyncMessageEvent, SyncStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent,
}, },
room::Room, room::Room,
Client, Client,
@ -73,6 +77,15 @@ impl Handler {
} }
pub(crate) async fn handle_sync(&self, response: &SyncResponse) { pub(crate) async fn handle_sync(&self, response: &SyncResponse) {
for event in response
.account_data
.events
.iter()
.filter_map(|e| e.deserialize().ok())
{
self.handle_account_data_event(&event).await;
}
for (room_id, room_info) in &response.rooms.join { for (room_id, room_info) in &response.rooms.join {
if let Some(room) = self.get_room(room_id) { if let Some(room) = self.get_room(room_id) {
for event in room_info for event in room_info
@ -90,7 +103,8 @@ impl Handler {
.iter() .iter()
.filter_map(|e| e.deserialize().ok()) .filter_map(|e| e.deserialize().ok())
{ {
self.handle_account_data_event(room.clone(), &event).await; self.handle_room_account_data_event(room.clone(), &event)
.await;
} }
for event in room_info for event in room_info
@ -121,7 +135,8 @@ impl Handler {
.iter() .iter()
.filter_map(|e| e.deserialize().ok()) .filter_map(|e| e.deserialize().ok())
{ {
self.handle_account_data_event(room.clone(), &event).await; self.handle_room_account_data_event(room.clone(), &event)
.await;
} }
for event in room_info for event in room_info
@ -272,13 +287,27 @@ impl Handler {
} }
} }
pub(crate) async fn handle_account_data_event(&self, room: Room, event: &AnyBasicEvent) { pub(crate) async fn handle_room_account_data_event(
&self,
room: Room,
event: &AnyRoomAccountDataEvent,
) {
match event { match event {
AnyBasicEvent::Presence(presence) => self.on_non_room_presence(room, &presence).await, AnyRoomAccountDataEvent::FullyRead(event) => {
AnyBasicEvent::IgnoredUserList(ignored) => { self.on_non_room_fully_read(room, &event).await
self.on_non_room_ignored_users(room, &ignored).await }
_ => {}
}
}
pub(crate) async fn handle_account_data_event(&self, event: &AnyGlobalAccountDataEvent) {
match event {
AnyGlobalAccountDataEvent::IgnoredUserList(ignored) => {
self.on_non_room_ignored_users(&ignored).await
}
AnyGlobalAccountDataEvent::PushRules(rules) => {
self.on_non_room_push_rules(&rules).await
} }
AnyBasicEvent::PushRules(rules) => self.on_non_room_push_rules(room, &rules).await,
_ => {} _ => {}
} }
} }
@ -289,9 +318,6 @@ impl Handler {
event: &AnySyncEphemeralRoomEvent, event: &AnySyncEphemeralRoomEvent,
) { ) {
match event { match event {
AnySyncEphemeralRoomEvent::FullyRead(full_read) => {
self.on_non_room_fully_read(room, full_read).await
}
AnySyncEphemeralRoomEvent::Typing(typing) => { AnySyncEphemeralRoomEvent::Typing(typing) => {
self.on_non_room_typing(room, typing).await self.on_non_room_typing(room, typing).await
} }
@ -307,7 +333,7 @@ impl Handler {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum CustomEvent<'c> { pub enum CustomEvent<'c> {
/// A custom basic event. /// A custom basic event.
Basic(&'c BasicEvent<CustomEventContent>), Basic(&'c GlobalAccountDataEvent<CustomEventContent>),
/// A custom basic event. /// A custom basic event.
EphemeralRoom(&'c SyncEphemeralRoomEvent<CustomEventContent>), EphemeralRoom(&'c SyncEphemeralRoomEvent<CustomEventContent>),
/// A custom room event. /// A custom room event.
@ -477,17 +503,16 @@ pub trait EventHandler: Send + Sync {
/// Fires when `Client` receives a `NonRoomEvent::RoomName` event. /// Fires when `Client` receives a `NonRoomEvent::RoomName` event.
async fn on_non_room_ignored_users( async fn on_non_room_ignored_users(
&self, &self,
_: Room, _: &GlobalAccountDataEvent<IgnoredUserListEventContent>,
_: &BasicEvent<IgnoredUserListEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `NonRoomEvent::RoomCanonicalAlias` event. /// Fires when `Client` receives a `NonRoomEvent::RoomCanonicalAlias` event.
async fn on_non_room_push_rules(&self, _: Room, _: &BasicEvent<PushRulesEventContent>) {} async fn on_non_room_push_rules(&self, _: &GlobalAccountDataEvent<PushRulesEventContent>) {}
/// Fires when `Client` receives a `NonRoomEvent::RoomAliases` event. /// Fires when `Client` receives a `NonRoomEvent::RoomAliases` event.
async fn on_non_room_fully_read( async fn on_non_room_fully_read(
&self, &self,
_: Room, _: Room,
_: &SyncEphemeralRoomEvent<FullyReadEventContent>, _: &RoomAccountDataEvent<FullyReadEventContent>,
) { ) {
} }
/// Fires when `Client` receives a `NonRoomEvent::Typing` event. /// Fires when `Client` receives a `NonRoomEvent::Typing` event.
@ -689,18 +714,17 @@ mod test {
} }
async fn on_non_room_ignored_users( async fn on_non_room_ignored_users(
&self, &self,
_: Room, _: &GlobalAccountDataEvent<IgnoredUserListEventContent>,
_: &BasicEvent<IgnoredUserListEventContent>,
) { ) {
self.0.lock().await.push("account ignore".to_string()) self.0.lock().await.push("account ignore".to_string())
} }
async fn on_non_room_push_rules(&self, _: Room, _: &BasicEvent<PushRulesEventContent>) { async fn on_non_room_push_rules(&self, _: &GlobalAccountDataEvent<PushRulesEventContent>) {
self.0.lock().await.push("account push rules".to_string()) self.0.lock().await.push("account push rules".to_string())
} }
async fn on_non_room_fully_read( async fn on_non_room_fully_read(
&self, &self,
_: Room, _: Room,
_: &SyncEphemeralRoomEvent<FullyReadEventContent>, _: &RoomAccountDataEvent<FullyReadEventContent>,
) { ) {
self.0.lock().await.push("account read".to_string()) self.0.lock().await.push("account read".to_string())
} }
@ -774,9 +798,9 @@ mod test {
assert_eq!( assert_eq!(
v.as_slice(), v.as_slice(),
[ [
"account ignore",
"receipt event", "receipt event",
"account read", "account read",
"account ignore",
"state rules", "state rules",
"state member", "state member",
"state aliases", "state aliases",
@ -902,9 +926,9 @@ mod test {
assert_eq!( assert_eq!(
v.as_slice(), v.as_slice(),
[ [
"account ignore",
"receipt event", "receipt event",
"account read", "account read",
"account ignore",
"state rules", "state rules",
"state member", "state member",
"state aliases", "state aliases",

View File

@ -31,6 +31,7 @@ use matrix_sdk_common::{
}, },
identifiers::{EventId, UserId}, identifiers::{EventId, UserId},
instant::{Duration, Instant}, instant::{Duration, Instant},
receipt::ReceiptType,
uuid::Uuid, uuid::Uuid,
}; };
@ -225,11 +226,8 @@ impl Joined {
/// ///
/// * `event_id` - The `EventId` specifies the event to set the read receipt on. /// * `event_id` - The `EventId` specifies the event to set the read receipt on.
pub async fn read_receipt(&self, event_id: &EventId) -> Result<()> { pub async fn read_receipt(&self, event_id: &EventId) -> Result<()> {
let request = create_receipt::Request::new( let request =
self.inner.room_id(), create_receipt::Request::new(self.inner.room_id(), ReceiptType::Read, event_id);
create_receipt::ReceiptType::Read,
event_id,
);
self.client.send(request, None).await?; self.client.send(request, None).await?;
Ok(()) Ok(())

View File

@ -4,7 +4,7 @@ use matrix_sdk::{
api_appservice, api_appservice,
api_appservice::Registration, api_appservice::Registration,
async_trait, async_trait,
events::{room::member::MemberEventContent, AnyEvent, AnyStateEvent, SyncStateEvent}, events::{room::member::MemberEventContent, AnyRoomEvent, AnyStateEvent, SyncStateEvent},
room::Room, room::Room,
EventHandler, Raw, EventHandler, Raw,
}; };
@ -82,7 +82,7 @@ async fn test_event_handler() -> Result<()> {
.await; .await;
let event = serde_json::from_value::<AnyStateEvent>(member_json()).unwrap(); let event = serde_json::from_value::<AnyStateEvent>(member_json()).unwrap();
let event: Raw<AnyEvent> = AnyEvent::State(event).into(); let event: Raw<AnyRoomEvent> = AnyRoomEvent::State(event).into();
let events = vec![event]; let events = vec![event];
let incoming = api_appservice::event::push_events::v1::IncomingRequest::new( let incoming = api_appservice::event::push_events::v1::IncomingRequest::new(
@ -100,7 +100,7 @@ async fn test_transaction() -> Result<()> {
let appservice = appservice(None).await?; let appservice = appservice(None).await?;
let event = serde_json::from_value::<AnyStateEvent>(member_json()).unwrap(); let event = serde_json::from_value::<AnyStateEvent>(member_json()).unwrap();
let event: Raw<AnyEvent> = AnyEvent::State(event).into(); let event: Raw<AnyRoomEvent> = AnyRoomEvent::State(event).into();
let events = vec![event]; let events = vec![event];
let incoming = api_appservice::event::push_events::v1::IncomingRequest::new( let incoming = api_appservice::event::push_events::v1::IncomingRequest::new(

View File

@ -42,8 +42,8 @@ use matrix_sdk_common::{
}, },
events::{ events::{
room::member::{MemberEventContent, MembershipState}, room::member::{MemberEventContent, MembershipState},
AnyBasicEvent, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventContent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
EventType, StateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventContent, EventType, StateEvent,
}, },
identifiers::{RoomId, UserId}, identifiers::{RoomId, UserId},
instant::Instant, instant::Instant,
@ -657,7 +657,7 @@ impl BaseClient {
async fn handle_room_account_data( async fn handle_room_account_data(
&self, &self,
room_id: &RoomId, room_id: &RoomId,
events: &[Raw<AnyBasicEvent>], events: &[Raw<AnyRoomAccountDataEvent>],
changes: &mut StateChanges, changes: &mut StateChanges,
) { ) {
for raw_event in events { for raw_event in events {
@ -667,7 +667,11 @@ impl BaseClient {
} }
} }
async fn handle_account_data(&self, events: &[Raw<AnyBasicEvent>], changes: &mut StateChanges) { async fn handle_account_data(
&self,
events: &[Raw<AnyGlobalAccountDataEvent>],
changes: &mut StateChanges,
) {
let mut account_data = BTreeMap::new(); let mut account_data = BTreeMap::new();
for raw_event in events { for raw_event in events {
@ -677,7 +681,7 @@ impl BaseClient {
continue; continue;
}; };
if let AnyBasicEvent::Direct(e) = &event { if let AnyGlobalAccountDataEvent::Direct(e) = &event {
for (user_id, rooms) in e.content.iter() { for (user_id, rooms) in e.content.iter() {
for room_id in rooms { for room_id in rooms {
if let Some(room) = changes.room_infos.get_mut(room_id) { if let Some(room) = changes.room_infos.get_mut(room_id) {
@ -1348,13 +1352,13 @@ impl BaseClient {
/// Gets the push rules from `changes` if they have been updated, otherwise get them from the /// Gets the push rules from `changes` if they have been updated, otherwise get them from the
/// store. As a fallback, uses `Ruleset::server_default` if the user is logged in. /// store. As a fallback, uses `Ruleset::server_default` if the user is logged in.
pub async fn get_push_rules(&self, changes: &StateChanges) -> Result<Ruleset> { pub async fn get_push_rules(&self, changes: &StateChanges) -> Result<Ruleset> {
if let Some(AnyBasicEvent::PushRules(event)) = changes if let Some(AnyGlobalAccountDataEvent::PushRules(event)) = changes
.account_data .account_data
.get(EventType::PushRules.as_str()) .get(EventType::PushRules.as_str())
.and_then(|e| e.deserialize().ok()) .and_then(|e| e.deserialize().ok())
{ {
Ok(event.content.global) Ok(event.content.global)
} else if let Some(AnyBasicEvent::PushRules(event)) = self } else if let Some(AnyGlobalAccountDataEvent::PushRules(event)) = self
.store .store
.get_account_data_event(EventType::PushRules) .get_account_data_event(EventType::PushRules)
.await? .await?

View File

@ -30,7 +30,7 @@ use matrix_sdk_common::{
tombstone::TombstoneEventContent, tombstone::TombstoneEventContent,
}, },
tag::Tags, tag::Tags,
AnyBasicEvent, AnyStateEventContent, AnySyncStateEvent, EventType, AnyRoomAccountDataEvent, AnyStateEventContent, AnySyncStateEvent, EventType,
}, },
identifiers::{MxcUri, RoomAliasId, RoomId, UserId}, identifiers::{MxcUri, RoomAliasId, RoomId, UserId},
}; };
@ -451,7 +451,7 @@ impl Room {
/// Get the `Tags` for this room. /// Get the `Tags` for this room.
pub async fn tags(&self) -> StoreResult<Option<Tags>> { pub async fn tags(&self) -> StoreResult<Option<Tags>> {
if let Some(AnyBasicEvent::Tag(event)) = self if let Some(AnyRoomAccountDataEvent::Tag(event)) = self
.store .store
.get_room_account_data_event(self.room_id(), EventType::Tag) .get_room_account_data_event(self.room_id(), EventType::Tag)
.await? .await?

View File

@ -23,7 +23,8 @@ use matrix_sdk_common::{
events::{ events::{
presence::PresenceEvent, presence::PresenceEvent,
room::member::{MemberEventContent, MembershipState}, room::member::{MemberEventContent, MembershipState},
AnyBasicEvent, AnyStrippedStateEvent, AnySyncStateEvent, EventType, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
AnySyncStateEvent, EventType,
}, },
identifiers::{RoomId, UserId}, identifiers::{RoomId, UserId},
instant::Instant, instant::Instant,
@ -40,7 +41,7 @@ use super::{Result, RoomInfo, StateChanges, StateStore};
pub struct MemoryStore { pub struct MemoryStore {
sync_token: Arc<RwLock<Option<String>>>, sync_token: Arc<RwLock<Option<String>>>,
filters: Arc<DashMap<String, String>>, filters: Arc<DashMap<String, String>>,
account_data: Arc<DashMap<String, Raw<AnyBasicEvent>>>, account_data: Arc<DashMap<String, Raw<AnyGlobalAccountDataEvent>>>,
members: Arc<DashMap<RoomId, DashMap<UserId, MemberEvent>>>, members: Arc<DashMap<RoomId, DashMap<UserId, MemberEvent>>>,
profiles: Arc<DashMap<RoomId, DashMap<UserId, MemberEventContent>>>, profiles: Arc<DashMap<RoomId, DashMap<UserId, MemberEventContent>>>,
display_names: Arc<DashMap<RoomId, DashMap<String, BTreeSet<UserId>>>>, display_names: Arc<DashMap<RoomId, DashMap<String, BTreeSet<UserId>>>>,
@ -49,7 +50,7 @@ pub struct MemoryStore {
room_info: Arc<DashMap<RoomId, RoomInfo>>, room_info: Arc<DashMap<RoomId, RoomInfo>>,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
room_state: Arc<DashMap<RoomId, DashMap<String, DashMap<String, Raw<AnySyncStateEvent>>>>>, room_state: Arc<DashMap<RoomId, DashMap<String, DashMap<String, Raw<AnySyncStateEvent>>>>>,
room_account_data: Arc<DashMap<RoomId, DashMap<String, Raw<AnyBasicEvent>>>>, room_account_data: Arc<DashMap<RoomId, DashMap<String, Raw<AnyRoomAccountDataEvent>>>>,
stripped_room_info: Arc<DashMap<RoomId, RoomInfo>>, stripped_room_info: Arc<DashMap<RoomId, RoomInfo>>,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
stripped_room_state: stripped_room_state:
@ -308,7 +309,7 @@ impl MemoryStore {
async fn get_account_data_event( async fn get_account_data_event(
&self, &self,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyGlobalAccountDataEvent>>> {
Ok(self Ok(self
.account_data .account_data
.get(event_type.as_ref()) .get(event_type.as_ref())
@ -319,7 +320,7 @@ impl MemoryStore {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>> {
Ok(self Ok(self
.room_account_data .room_account_data
.get(room_id) .get(room_id)
@ -411,7 +412,7 @@ impl StateStore for MemoryStore {
async fn get_account_data_event( async fn get_account_data_event(
&self, &self,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyGlobalAccountDataEvent>>> {
self.get_account_data_event(event_type).await self.get_account_data_event(event_type).await
} }
@ -419,7 +420,7 @@ impl StateStore for MemoryStore {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>> {
self.get_room_account_data_event(room_id, event_type).await self.get_room_account_data_event(room_id, event_type).await
} }
} }

View File

@ -26,8 +26,8 @@ use matrix_sdk_common::{
api::r0::push::get_notifications::Notification, api::r0::push::get_notifications::Notification,
async_trait, async_trait,
events::{ events::{
presence::PresenceEvent, room::member::MemberEventContent, AnyBasicEvent, presence::PresenceEvent, room::member::MemberEventContent, AnyGlobalAccountDataEvent,
AnyStrippedStateEvent, AnySyncStateEvent, EventContent, EventType, AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncStateEvent, EventContent, EventType,
}, },
identifiers::{RoomId, UserId}, identifiers::{RoomId, UserId},
locks::RwLock, locks::RwLock,
@ -195,7 +195,7 @@ pub trait StateStore: AsyncTraitDeps {
async fn get_account_data_event( async fn get_account_data_event(
&self, &self,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>>; ) -> Result<Option<Raw<AnyGlobalAccountDataEvent>>>;
/// Get an event out of the room account data store. /// Get an event out of the room account data store.
/// ///
@ -209,7 +209,7 @@ pub trait StateStore: AsyncTraitDeps {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>>; ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>>;
} }
/// A state store wrapper for the SDK. /// A state store wrapper for the SDK.
@ -362,7 +362,7 @@ pub struct StateChanges {
/// A user session, containing an access token and information about the associated user account. /// A user session, containing an access token and information about the associated user account.
pub session: Option<Session>, pub session: Option<Session>,
/// A mapping of event type string to `AnyBasicEvent`. /// A mapping of event type string to `AnyBasicEvent`.
pub account_data: BTreeMap<String, Raw<AnyBasicEvent>>, pub account_data: BTreeMap<String, Raw<AnyGlobalAccountDataEvent>>,
/// A mapping of `UserId` to `PresenceEvent`. /// A mapping of `UserId` to `PresenceEvent`.
pub presence: BTreeMap<UserId, Raw<PresenceEvent>>, pub presence: BTreeMap<UserId, Raw<PresenceEvent>>,
@ -374,7 +374,7 @@ pub struct StateChanges {
/// A mapping of `RoomId` to a map of event type string to a state key and `AnySyncStateEvent`. /// A mapping of `RoomId` to a map of event type string to a state key and `AnySyncStateEvent`.
pub state: BTreeMap<RoomId, BTreeMap<String, BTreeMap<String, Raw<AnySyncStateEvent>>>>, pub state: BTreeMap<RoomId, BTreeMap<String, BTreeMap<String, Raw<AnySyncStateEvent>>>>,
/// A mapping of `RoomId` to a map of event type string to `AnyBasicEvent`. /// A mapping of `RoomId` to a map of event type string to `AnyBasicEvent`.
pub room_account_data: BTreeMap<RoomId, BTreeMap<String, Raw<AnyBasicEvent>>>, pub room_account_data: BTreeMap<RoomId, BTreeMap<String, Raw<AnyRoomAccountDataEvent>>>,
/// A map of `RoomId` to `RoomInfo`. /// A map of `RoomId` to `RoomInfo`.
pub room_infos: BTreeMap<RoomId, RoomInfo>, pub room_infos: BTreeMap<RoomId, RoomInfo>,
@ -420,7 +420,11 @@ impl StateChanges {
} }
/// Update the `StateChanges` struct with the given `AnyBasicEvent`. /// Update the `StateChanges` struct with the given `AnyBasicEvent`.
pub fn add_account_data(&mut self, event: AnyBasicEvent, raw_event: Raw<AnyBasicEvent>) { pub fn add_account_data(
&mut self,
event: AnyGlobalAccountDataEvent,
raw_event: Raw<AnyGlobalAccountDataEvent>,
) {
self.account_data self.account_data
.insert(event.content().event_type().to_owned(), raw_event); .insert(event.content().event_type().to_owned(), raw_event);
} }
@ -429,8 +433,8 @@ impl StateChanges {
pub fn add_room_account_data( pub fn add_room_account_data(
&mut self, &mut self,
room_id: &RoomId, room_id: &RoomId,
event: AnyBasicEvent, event: AnyRoomAccountDataEvent,
raw_event: Raw<AnyBasicEvent>, raw_event: Raw<AnyRoomAccountDataEvent>,
) { ) {
self.room_account_data self.room_account_data
.entry(room_id.to_owned()) .entry(room_id.to_owned())

View File

@ -31,7 +31,7 @@ use matrix_sdk_common::{
events::{ events::{
presence::PresenceEvent, presence::PresenceEvent,
room::member::{MemberEventContent, MembershipState}, room::member::{MemberEventContent, MembershipState},
AnyBasicEvent, AnySyncStateEvent, EventType, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncStateEvent, EventType,
}, },
identifiers::{RoomId, UserId}, identifiers::{RoomId, UserId},
Raw, Raw,
@ -590,7 +590,7 @@ impl SledStore {
pub async fn get_account_data_event( pub async fn get_account_data_event(
&self, &self,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyGlobalAccountDataEvent>>> {
Ok(self Ok(self
.account_data .account_data
.get(event_type.encode())? .get(event_type.encode())?
@ -602,7 +602,7 @@ impl SledStore {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>> {
Ok(self Ok(self
.room_account_data .room_account_data
.get((room_id.as_str(), event_type.as_str()).encode())? .get((room_id.as_str(), event_type.as_str()).encode())?
@ -690,7 +690,7 @@ impl StateStore for SledStore {
async fn get_account_data_event( async fn get_account_data_event(
&self, &self,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyGlobalAccountDataEvent>>> {
self.get_account_data_event(event_type).await self.get_account_data_event(event_type).await
} }
@ -698,7 +698,7 @@ impl StateStore for SledStore {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyRoomAccountDataEvent>>> {
self.get_room_account_data_event(room_id, event_type).await self.get_room_account_data_event(room_id, event_type).await
} }
} }

View File

@ -22,7 +22,7 @@ async-trait = "0.1.42"
[dependencies.ruma] [dependencies.ruma]
version = "0.0.3" version = "0.0.3"
git = "https://github.com/ruma/ruma" git = "https://github.com/ruma/ruma"
rev = "a0f7e1b771d3294187bae0b2816fbcf6ceb40b88" rev = "3bdead1cf207e3ab9c8fcbfc454c054c726ba6f5"
features = ["client-api-c", "compat", "unstable-pre-spec"] features = ["client-api-c", "compat", "unstable-pre-spec"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View File

@ -1,6 +1,6 @@
use ruma::{ use ruma::{
api::client::r0::sync::sync_events::{ api::client::r0::sync::sync_events::{
AccountData, Ephemeral, InvitedRoom, Presence, State, ToDevice, Ephemeral, InvitedRoom, Presence, RoomAccountData, State, ToDevice,
}, },
serde::Raw, serde::Raw,
DeviceIdBox, DeviceIdBox,
@ -12,7 +12,8 @@ use super::{
api::r0::{ api::r0::{
push::get_notifications::Notification, push::get_notifications::Notification,
sync::sync_events::{ sync::sync_events::{
DeviceLists, UnreadNotificationsCount as RumaUnreadNotificationsCount, DeviceLists, GlobalAccountData,
UnreadNotificationsCount as RumaUnreadNotificationsCount,
}, },
}, },
events::{ events::{
@ -118,7 +119,7 @@ pub struct SyncResponse {
/// 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: GlobalAccountData,
/// 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.
@ -165,7 +166,7 @@ pub struct JoinedRoom {
/// given, or `full_state` is true). /// given, or `full_state` is true).
pub state: State, pub state: State,
/// The private data that this user has attached to this room. /// The private data that this user has attached to this room.
pub account_data: AccountData, pub account_data: RoomAccountData,
/// The ephemeral events in the room that aren't recorded in the timeline or state of the /// The ephemeral events in the room that aren't recorded in the timeline or state of the
/// room. e.g. typing. /// room. e.g. typing.
pub ephemeral: Ephemeral, pub ephemeral: Ephemeral,
@ -175,7 +176,7 @@ impl JoinedRoom {
pub fn new( pub fn new(
timeline: Timeline, timeline: Timeline,
state: State, state: State,
account_data: AccountData, account_data: RoomAccountData,
ephemeral: Ephemeral, ephemeral: Ephemeral,
unread_notifications: UnreadNotificationsCount, unread_notifications: UnreadNotificationsCount,
) -> Self { ) -> Self {
@ -220,11 +221,11 @@ pub struct LeftRoom {
/// given, or `full_state` is true). /// given, or `full_state` is true).
pub state: State, pub state: State,
/// The private data that this user has attached to this room. /// The private data that this user has attached to this room.
pub account_data: AccountData, pub account_data: RoomAccountData,
} }
impl LeftRoom { impl LeftRoom {
pub fn new(timeline: Timeline, state: State, account_data: AccountData) -> Self { pub fn new(timeline: Timeline, state: State, account_data: RoomAccountData) -> Self {
Self { Self {
timeline, timeline,
state, state,

View File

@ -13,7 +13,7 @@ pub use ruma::{
}, },
AuthScheme, EndpointError, IncomingResponse, OutgoingRequest, SendAccessToken, AuthScheme, EndpointError, IncomingResponse, OutgoingRequest, SendAccessToken,
}, },
assign, directory, encryption, events, identifiers, int, presence, push, assign, directory, encryption, events, identifiers, int, presence, push, receipt,
serde::{CanonicalJsonValue, Raw}, serde::{CanonicalJsonValue, Raw},
thirdparty, uint, Int, Outgoing, UInt, thirdparty, uint, Int, Outgoing, UInt,
}; };

View File

@ -33,7 +33,7 @@ use matrix_sdk_common::{
deserialized_responses::{AlgorithmInfo, EncryptionInfo, SyncRoomEvent, VerificationState}, deserialized_responses::{AlgorithmInfo, EncryptionInfo, SyncRoomEvent, VerificationState},
events::{ events::{
room::encrypted::{EncryptedEventContent, EncryptedEventScheme}, room::encrypted::{EncryptedEventContent, EncryptedEventScheme},
room_key::RoomKeyEventContent, room_key::RoomKeyToDeviceEventContent,
AnyMessageEventContent, AnyToDeviceEvent, SyncMessageEvent, ToDeviceEvent, AnyMessageEventContent, AnyToDeviceEvent, SyncMessageEvent, ToDeviceEvent,
}, },
identifiers::{ identifiers::{
@ -592,7 +592,7 @@ impl OlmMachine {
&self, &self,
sender_key: &str, sender_key: &str,
signing_key: &str, signing_key: &str,
event: &mut ToDeviceEvent<RoomKeyEventContent>, event: &mut ToDeviceEvent<RoomKeyToDeviceEventContent>,
) -> OlmResult<(Option<AnyToDeviceEvent>, Option<InboundGroupSession>)> { ) -> OlmResult<(Option<AnyToDeviceEvent>, Option<InboundGroupSession>)> {
match event.content.algorithm { match event.content.algorithm {
EventEncryptionAlgorithm::MegolmV1AesSha2 => { EventEncryptionAlgorithm::MegolmV1AesSha2 => {

View File

@ -5,8 +5,8 @@ use http::Response;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::sync::sync_events::Response as SyncResponse, api::r0::sync::sync_events::Response as SyncResponse,
events::{ events::{
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, presence::PresenceEvent, AnyGlobalAccountDataEvent, AnySyncEphemeralRoomEvent,
AnySyncStateEvent, AnySyncRoomEvent, AnySyncStateEvent,
}, },
identifiers::{room_id, RoomId}, identifiers::{room_id, RoomId},
IncomingResponse, IncomingResponse,
@ -93,7 +93,7 @@ pub struct EventBuilder {
/// The ephemeral room events that determine the state of a `Room`. /// The ephemeral room events that determine the state of a `Room`.
ephemeral: Vec<AnySyncEphemeralRoomEvent>, ephemeral: Vec<AnySyncEphemeralRoomEvent>,
/// The account data events that determine the state of a `Room`. /// The account data events that determine the state of a `Room`.
account_data: Vec<AnyBasicEvent>, account_data: Vec<AnyGlobalAccountDataEvent>,
/// Internal counter to enable the `prev_batch` and `next_batch` of each sync response to vary. /// Internal counter to enable the `prev_batch` and `next_batch` of each sync response to vary.
batch_counter: i64, batch_counter: i64,
} }
@ -123,7 +123,7 @@ impl EventBuilder {
_ => panic!("unknown account event {:?}", json), _ => panic!("unknown account event {:?}", json),
}; };
let event = serde_json::from_value::<AnyBasicEvent>(val.clone()).unwrap(); let event = serde_json::from_value::<AnyGlobalAccountDataEvent>(val.clone()).unwrap();
self.account_data.push(event); self.account_data.push(event);
self self
} }

View File

@ -11,11 +11,6 @@ lazy_static! {
], ],
"left": [] "left": []
}, },
"rooms": {
"invite": {},
"join": {
"!SVkFJHzfwvuaIEawgC:localhost": {
"summary": {},
"account_data": { "account_data": {
"events": [ "events": [
{ {
@ -28,6 +23,22 @@ lazy_static! {
} }
] ]
}, },
"rooms": {
"invite": {},
"join": {
"!SVkFJHzfwvuaIEawgC:localhost": {
"summary": {},
"account_data": {
"events": [
{
"content": {
"event_id": "$someplace:example.org"
},
"room_id": "!roomid:room.com",
"type": "m.fully_read"
}
]
},
"ephemeral": { "ephemeral": {
"events": [ "events": [
{ {
@ -43,13 +54,6 @@ lazy_static! {
"room_id": "!SVkFJHzfwvuaIEawgC:localhost", "room_id": "!SVkFJHzfwvuaIEawgC:localhost",
"type": "m.receipt" "type": "m.receipt"
}, },
{
"content": {
"event_id": "$someplace:example.org"
},
"room_id": "!roomid:room.com",
"type": "m.fully_read"
}
] ]
}, },
"state": { "state": {
@ -782,12 +786,6 @@ lazy_static! {
], ],
"left": [] "left": []
}, },
"rooms": {
"invite": {},
"join": {},
"leave": {
"!SVkFJHzfwvuaIEawgC:localhost": {
"summary": {},
"account_data": { "account_data": {
"events": [ "events": [
{ {
@ -800,6 +798,15 @@ lazy_static! {
} }
] ]
}, },
"rooms": {
"invite": {},
"join": {},
"leave": {
"!SVkFJHzfwvuaIEawgC:localhost": {
"summary": {},
"account_data": {
"events": []
},
"ephemeral": { "ephemeral": {
"events": [ "events": [
{ {