From 6a963680485a339cd0f408613a09f0bb9e13a10b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 26 Jul 2020 16:58:27 +0200 Subject: [PATCH] Upgrade ruma --- matrix_sdk/src/client.rs | 3 +- matrix_sdk/src/request_builder.rs | 7 ++--- matrix_sdk_base/src/client.rs | 33 +++++++++------------ matrix_sdk_base/src/models/room.rs | 6 ++-- matrix_sdk_base/src/models/room_member.rs | 7 ++--- matrix_sdk_common/Cargo.toml | 2 +- matrix_sdk_common/src/lib.rs | 2 +- matrix_sdk_crypto/src/machine.rs | 29 +++++++++--------- matrix_sdk_crypto/src/olm/group_sessions.rs | 7 +++-- 9 files changed, 44 insertions(+), 52 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index a1b77b09..4fc63f81 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -26,6 +26,7 @@ use matrix_sdk_common::identifiers::ServerName; use matrix_sdk_common::instant::{Duration, Instant}; use matrix_sdk_common::js_int::UInt; use matrix_sdk_common::locks::RwLock; +use matrix_sdk_common::presence::PresenceState; use matrix_sdk_common::uuid::Uuid; use futures_timer::Delay as sleep; @@ -1246,7 +1247,7 @@ impl Client { filter: sync_settings.filter, since: sync_settings.token, full_state: sync_settings.full_state, - set_presence: sync_events::SetPresence::Online, + set_presence: PresenceState::Online, timeout: sync_settings.timeout, }; diff --git a/matrix_sdk/src/request_builder.rs b/matrix_sdk/src/request_builder.rs index 308e2b70..88ba1d5f 100644 --- a/matrix_sdk/src/request_builder.rs +++ b/matrix_sdk/src/request_builder.rs @@ -11,10 +11,7 @@ use matrix_sdk_common::{ }, uiaa::AuthData, }, - events::{ - room::{create::PreviousRoom, power_levels::PowerLevelsEventContent}, - EventJson, - }, + events::room::{create::PreviousRoom, power_levels::PowerLevelsEventContent}, identifiers::{DeviceId, RoomId, UserId}, js_int::UInt, }; @@ -114,7 +111,7 @@ impl RoomBuilder { /// Power level content to override in the default power level event. pub fn power_level_override(&mut self, power: PowerLevelsEventContent) -> &mut Self { - self.req.power_level_content_override = Some(EventJson::from(power)); + self.req.power_level_content_override = Some(power.into()); self } diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index 444dff9a..375a6195 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -39,8 +39,9 @@ use crate::state::{AllRooms, ClientState, StateStore}; use crate::EventEmitter; use matrix_sdk_common::events::{ AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, - AnySyncRoomEvent, AnySyncStateEvent, EventJson, + AnySyncRoomEvent, AnySyncStateEvent, }; +use matrix_sdk_common::Raw; #[cfg(feature = "encryption")] use matrix_sdk_common::locks::Mutex; @@ -82,7 +83,7 @@ pub struct AdditionalEventData { /// Represents the inner `prev_content` field #[derive(serde::Deserialize)] pub struct AdditionalUnsignedData { - pub prev_content: Option>, + pub prev_content: Option>, } /// Transform room event by hoisting `prev_content` field from `unsigned` to the top level. @@ -93,9 +94,7 @@ pub struct AdditionalUnsignedData { /// /// [synapse-bug]: /// [discussion]: -fn hoist_room_event_prev_content( - event: &EventJson, -) -> Option> { +fn hoist_room_event_prev_content(event: &Raw) -> Option> { let prev_content = serde_json::from_str::(event.json().get()) .map(|more_unsigned| more_unsigned.unsigned) .map(|additional| additional.prev_content) @@ -112,7 +111,7 @@ fn hoist_room_event_prev_content( member.prev_content = Some(prev) } - Some(EventJson::from(ev)) + Some(Raw::from(ev)) } _ => None, } @@ -122,8 +121,8 @@ fn hoist_room_event_prev_content( /// /// See comment of `hoist_room_event_prev_content`. fn hoist_state_event_prev_content( - event: &EventJson, -) -> Option> { + event: &Raw, +) -> Option> { let prev_content = serde_json::from_str::(event.json().get()) .map(|more_unsigned| more_unsigned.unsigned) .map(|additional| additional.prev_content) @@ -134,14 +133,14 @@ fn hoist_state_event_prev_content( match &mut ev { AnySyncStateEvent::RoomMember(ref mut member) if member.prev_content.is_none() => { member.prev_content = Some(prev_content.deserialize().ok()?); - Some(EventJson::from(ev)) + Some(Raw::from(ev)) } _ => None, } } fn stripped_deserialize_prev_content( - event: &EventJson, + event: &Raw, ) -> Option { serde_json::from_str::(event.json().get()) .map(|more_unsigned| more_unsigned.unsigned) @@ -711,7 +710,7 @@ impl BaseClient { pub async fn receive_joined_timeline_event( &self, room_id: &RoomId, - event: &mut EventJson, + event: &mut Raw, ) -> Result { match event.deserialize() { #[allow(unused_mut)] @@ -823,7 +822,7 @@ impl BaseClient { pub async fn receive_left_timeline_event( &self, room_id: &RoomId, - event: &EventJson, + event: &Raw, ) -> Result { match event.deserialize() { Ok(e) => { @@ -1797,7 +1796,7 @@ impl BaseClient { pub(crate) async fn emit_unrecognized_event( &self, room_id: &RoomId, - event: &EventJson, + event: &Raw, room_state: RoomStateType, ) { let room = match room_state { @@ -1834,11 +1833,7 @@ impl BaseClient { mod test { use crate::identifiers::{RoomId, UserId}; #[cfg(feature = "messages")] - use crate::{ - events::{AnySyncRoomEvent, EventJson}, - identifiers::EventId, - BaseClientConfig, JsonStore, - }; + use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw}; use crate::{BaseClient, Session}; use matrix_sdk_common_macros::async_trait; use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson}; @@ -2391,7 +2386,7 @@ mod test { "type": "m.room.redaction", "redacts": "$152037280074GZeOm:localhost" }); - let mut event: EventJson = serde_json::from_value(json).unwrap(); + let mut event: Raw = serde_json::from_value(json).unwrap(); client .receive_joined_timeline_event(&room_id, &mut event) .await diff --git a/matrix_sdk_base/src/models/room.rs b/matrix_sdk_base/src/models/room.rs index d61cc674..e0e194d4 100644 --- a/matrix_sdk_base/src/models/room.rs +++ b/matrix_sdk_base/src/models/room.rs @@ -1080,9 +1080,9 @@ impl Describe for MembershipChange { #[cfg(test)] mod test { use super::*; - use crate::events::{room::encryption::EncryptionEventContent, EventJson, Unsigned}; + use crate::events::{room::encryption::EncryptionEventContent, Unsigned}; use crate::identifiers::{EventId, UserId}; - use crate::{BaseClient, Session}; + use crate::{BaseClient, Raw, Session}; use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile}; use std::time::SystemTime; @@ -1645,7 +1645,7 @@ mod test { "type": "m.room.redaction", "redacts": "$152037280074GZeOm:localhost" }); - let mut event: EventJson = serde_json::from_value(json).unwrap(); + let mut event: Raw = serde_json::from_value(json).unwrap(); client .receive_joined_timeline_event(&room_id, &mut event) .await diff --git a/matrix_sdk_base/src/models/room_member.rs b/matrix_sdk_base/src/models/room_member.rs index e4121a53..9baf8482 100644 --- a/matrix_sdk_base/src/models/room_member.rs +++ b/matrix_sdk_base/src/models/room_member.rs @@ -16,13 +16,10 @@ use std::convert::TryFrom; use matrix_sdk_common::{ - events::{ - presence::{PresenceEvent, PresenceState}, - room::member::MemberEventContent, - SyncStateEvent, - }, + events::{presence::PresenceEvent, room::member::MemberEventContent, SyncStateEvent}, identifiers::{RoomId, UserId}, js_int::{Int, UInt}, + presence::PresenceState, }; use serde::{Deserialize, Serialize}; diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 5ea6efbf..3041413f 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -17,7 +17,7 @@ js_int = "0.1.8" [dependencies.ruma] git = "https://github.com/ruma/ruma" features = ["client-api"] -rev = "ea2992a4120d34495d6f07f141350d8f2a3429d3" +rev = "e047c647ddcb368e7eb1e05ae8823a9494273457" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] uuid = { version = "0.8.1", features = ["v4"] } diff --git a/matrix_sdk_common/src/lib.rs b/matrix_sdk_common/src/lib.rs index a63ccb64..155c6ec4 100644 --- a/matrix_sdk_common/src/lib.rs +++ b/matrix_sdk_common/src/lib.rs @@ -7,7 +7,7 @@ pub use ruma::{ error::{FromHttpRequestError, FromHttpResponseError, IntoHttpError, ServerError}, Endpoint, EndpointError, }, - events, identifiers, push, + events, identifiers, presence, push, Raw, }; pub use uuid; diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 383b348f..b569e429 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -29,15 +29,15 @@ use super::store::memorystore::MemoryStore; use super::store::sqlite::SqliteStore; use super::{device::Device, store::Result as StoreResult, CryptoStore}; -use matrix_sdk_common::api; use matrix_sdk_common::events::{ forwarded_room_key::ForwardedRoomKeyEventContent, room::encrypted::EncryptedEventContent, room::message::MessageEventContent, room_key::RoomKeyEventContent, room_key_request::RoomKeyRequestEventContent, Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, - EventJson, EventType, SyncMessageEvent, ToDeviceEvent, + EventType, SyncMessageEvent, ToDeviceEvent, }; use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; use matrix_sdk_common::uuid::Uuid; +use matrix_sdk_common::{api, Raw}; use api::r0::keys; use api::r0::{ @@ -515,7 +515,7 @@ impl OlmMachine { sender: &UserId, sender_key: &str, message: OlmMessage, - ) -> OlmResult<(EventJson, String)> { + ) -> OlmResult<(Raw, String)> { // First try to decrypt using an existing session. let plaintext = if let Some(p) = self .try_decrypt_olm_message(sender, sender_key, &message) @@ -584,7 +584,7 @@ impl OlmMachine { &self, sender: &UserId, plaintext: &str, - ) -> OlmResult<(EventJson, String)> { + ) -> OlmResult<(Raw, String)> { // TODO make the errors a bit more specific. let decrypted_json: Value = serde_json::from_str(&plaintext)?; @@ -629,7 +629,7 @@ impl OlmMachine { .ok_or(EventError::MissingSigningKey)?; Ok(( - EventJson::from(serde_json::from_value::(decrypted_json)?), + Raw::from(serde_json::from_value::(decrypted_json)?), signing_key.to_owned(), )) } @@ -645,7 +645,7 @@ impl OlmMachine { async fn decrypt_to_device_event( &mut self, event: &ToDeviceEvent, - ) -> OlmResult> { + ) -> OlmResult> { info!("Decrypting to-device event"); let content = if let EncryptedEventContent::OlmV1Curve25519AesSha2(c) = &event.content { @@ -709,7 +709,7 @@ impl OlmMachine { sender_key: &str, signing_key: &str, event: &mut ToDeviceEvent, - ) -> OlmResult>> { + ) -> OlmResult>> { match event.content.algorithm { Algorithm::MegolmV1AesSha2 => { let session_key = GroupSessionKey(mem::take(&mut event.content.session_key)); @@ -722,7 +722,7 @@ impl OlmMachine { )?; let _ = self.store.save_inbound_group_session(session).await?; - let event = EventJson::from(AnyToDeviceEvent::RoomKey(event.clone())); + let event = Raw::from(AnyToDeviceEvent::RoomKey(event.clone())); Ok(Some(event)) } _ => { @@ -968,8 +968,8 @@ impl OlmMachine { &mut self, sender_key: &str, signing_key: &str, - event: &EventJson, - ) -> OlmResult>> { + event: &Raw, + ) -> OlmResult>> { let event = if let Ok(e) = event.deserialize() { e } else { @@ -1078,7 +1078,7 @@ impl OlmMachine { &mut self, event: &SyncMessageEvent, room_id: &RoomId, - ) -> MegolmResult> { + ) -> MegolmResult> { let content = match &event.content { EncryptedEventContent::MegolmV1AesSha2(c) => c, _ => return Err(EventError::UnsupportedAlgorithm.into()), @@ -1185,10 +1185,11 @@ mod test { encrypted::EncryptedEventContent, message::{MessageEventContent, TextMessageEventContent}, }, - AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventJson, EventType, - SyncMessageEvent, ToDeviceEvent, Unsigned, + AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, + ToDeviceEvent, Unsigned, }; use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId}; + use matrix_sdk_common::Raw; use matrix_sdk_test::test_json; fn alice_id() -> UserId { @@ -1223,7 +1224,7 @@ mod test { fn to_device_requests_to_content(requests: Vec) -> EncryptedEventContent { let to_device_request = &requests[0]; - let content: EventJson = serde_json::from_str( + let content: Raw = serde_json::from_str( to_device_request .messages .values() diff --git a/matrix_sdk_crypto/src/olm/group_sessions.rs b/matrix_sdk_crypto/src/olm/group_sessions.rs index c7b8bc62..10c61904 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions.rs @@ -38,9 +38,10 @@ pub use olm_rs::{ use matrix_sdk_common::{ events::{ room::{encrypted::EncryptedEventContent, message::MessageEventContent}, - Algorithm, AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent, + Algorithm, AnySyncRoomEvent, EventType, SyncMessageEvent, }, identifiers::{DeviceId, RoomId}, + Raw, }; /// The private session key of a group session. @@ -181,7 +182,7 @@ impl InboundGroupSession { pub async fn decrypt( &self, event: &SyncMessageEvent, - ) -> MegolmResult<(EventJson, u32)> { + ) -> MegolmResult<(Raw, u32)> { let content = match &event.content { EncryptedEventContent::MegolmV1AesSha2(c) => c, _ => return Err(EventError::UnsupportedAlgorithm.into()), @@ -212,7 +213,7 @@ impl InboundGroupSession { ); Ok(( - serde_json::from_value::>(decrypted_value)?, + serde_json::from_value::>(decrypted_value)?, message_index, )) }