From 15540e84e3feb4a1e681861de489cb98b39b40f4 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 15 May 2021 16:03:22 +0200 Subject: [PATCH] Upgrade ruma --- matrix_sdk_base/src/client.rs | 14 ++++++-------- matrix_sdk_base/src/store/sled_store/mod.rs | 6 +++--- matrix_sdk_common/Cargo.toml | 2 +- matrix_sdk_common/src/deserialized_responses.rs | 5 +++-- matrix_sdk_common/src/lib.rs | 2 +- matrix_sdk_crypto/src/machine.rs | 5 ++--- .../src/olm/group_sessions/inbound.rs | 15 ++------------- matrix_sdk_crypto/src/verification/requests.rs | 5 +++-- 8 files changed, 21 insertions(+), 33 deletions(-) diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index e3555ea4..d24a2f1c 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -20,7 +20,6 @@ use std::{ path::{Path, PathBuf}, result::Result as StdResult, sync::Arc, - time::SystemTime, }; #[cfg(feature = "encryption")] @@ -49,7 +48,7 @@ use matrix_sdk_common::{ instant::Instant, locks::RwLock, push::{Action, PushConditionRoomCtx, Ruleset}, - Raw, UInt, + MilliSecondsSinceUnixEpoch, Raw, UInt, }; #[cfg(feature = "encryption")] use matrix_sdk_crypto::{ @@ -100,8 +99,7 @@ pub struct AdditionalUnsignedData { pub fn hoist_and_deserialize_state_event( event: &Raw, ) -> StdResult { - let prev_content = - serde_json::from_str::(event.json().get())?.unsigned.prev_content; + let prev_content = event.deserialize_as::()?.unsigned.prev_content; let mut ev = event.deserialize()?; @@ -117,8 +115,7 @@ pub fn hoist_and_deserialize_state_event( fn hoist_member_event( event: &Raw>, ) -> StdResult, serde_json::Error> { - let prev_content = - serde_json::from_str::(event.json().get())?.unsigned.prev_content; + let prev_content = event.deserialize_as::()?.unsigned.prev_content; let mut e = event.deserialize()?; @@ -132,7 +129,8 @@ fn hoist_member_event( fn hoist_room_event_prev_content( event: &Raw, ) -> StdResult { - let prev_content = serde_json::from_str::(event.json().get()) + let prev_content = event + .deserialize_as::() .map(|more_unsigned| more_unsigned.unsigned) .map(|additional| additional.prev_content)? .and_then(|p| p.deserialize().ok()); @@ -515,7 +513,7 @@ impl BaseClient { event.event.clone(), false, room_id.clone(), - SystemTime::now(), + MilliSecondsSinceUnixEpoch::now(), ), ); } diff --git a/matrix_sdk_base/src/store/sled_store/mod.rs b/matrix_sdk_base/src/store/sled_store/mod.rs index 74ad0175..cace1128 100644 --- a/matrix_sdk_base/src/store/sled_store/mod.rs +++ b/matrix_sdk_base/src/store/sled_store/mod.rs @@ -681,7 +681,7 @@ impl StateStore for SledStore { #[cfg(test)] mod test { - use std::{convert::TryFrom, time::SystemTime}; + use std::convert::TryFrom; use matrix_sdk_common::{ events::{ @@ -692,7 +692,7 @@ mod test { AnySyncStateEvent, EventType, Unsigned, }, identifiers::{room_id, user_id, EventId, UserId}, - Raw, + MilliSecondsSinceUnixEpoch, Raw, }; use matrix_sdk_test::async_test; use serde_json::json; @@ -733,7 +733,7 @@ mod test { event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(), content, sender: user_id(), - origin_server_ts: SystemTime::now(), + origin_server_ts: MilliSecondsSinceUnixEpoch::now(), state_key: user_id(), prev_content: None, unsigned: Unsigned::default(), diff --git a/matrix_sdk_common/Cargo.toml b/matrix_sdk_common/Cargo.toml index 5206e11d..f2169f20 100644 --- a/matrix_sdk_common/Cargo.toml +++ b/matrix_sdk_common/Cargo.toml @@ -22,7 +22,7 @@ async-trait = "0.1.42" [dependencies.ruma] version = "0.0.3" git = "https://github.com/ruma/ruma" -rev = "3bdead1cf207e3ab9c8fcbfc454c054c726ba6f5" +rev = "e1ab817e0bef78cb8241d6d3c1ced7d6b414c7f6" features = ["client-api-c", "compat", "unstable-pre-spec"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/matrix_sdk_common/src/deserialized_responses.rs b/matrix_sdk_common/src/deserialized_responses.rs index 3acc4b4d..6582b0d2 100644 --- a/matrix_sdk_common/src/deserialized_responses.rs +++ b/matrix_sdk_common/src/deserialized_responses.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime}; +use std::{collections::BTreeMap, convert::TryFrom}; use ruma::{ api::client::r0::sync::sync_events::{ @@ -22,6 +22,7 @@ use super::{ SyncStateEvent, Unsigned, }, identifiers::{DeviceKeyAlgorithm, EventId, RoomId, UserId}, + MilliSecondsSinceUnixEpoch, }; /// A change in ambiguity of room members that an `m.room.member` event @@ -249,7 +250,7 @@ impl Timeline { pub struct MemberEvent { pub content: MemberEventContent, pub event_id: EventId, - pub origin_server_ts: SystemTime, + pub origin_server_ts: MilliSecondsSinceUnixEpoch, pub prev_content: Option, pub sender: UserId, pub state_key: UserId, diff --git a/matrix_sdk_common/src/lib.rs b/matrix_sdk_common/src/lib.rs index 5c91e21f..c45a082d 100644 --- a/matrix_sdk_common/src/lib.rs +++ b/matrix_sdk_common/src/lib.rs @@ -15,7 +15,7 @@ pub use ruma::{ }, assign, directory, encryption, events, identifiers, int, presence, push, receipt, serde::{CanonicalJsonValue, Raw}, - thirdparty, uint, Int, Outgoing, UInt, + thirdparty, uint, Int, MilliSecondsSinceUnixEpoch, Outgoing, SecondsSinceUnixEpoch, UInt, }; pub use uuid; diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 869bafbd..59e70b13 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -1204,7 +1204,6 @@ pub(crate) mod test { collections::BTreeMap, convert::{TryFrom, TryInto}, sync::Arc, - time::SystemTime, }; use http::Response; @@ -1221,7 +1220,7 @@ pub(crate) mod test { identifiers::{ event_id, room_id, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId, }, - IncomingResponse, Raw, + IncomingResponse, MilliSecondsSinceUnixEpoch, Raw, }; use matrix_sdk_test::test_json; use serde_json::json; @@ -1668,7 +1667,7 @@ pub(crate) mod test { let event = SyncMessageEvent { event_id: event_id!("$xxxxx:example.org"), - origin_server_ts: SystemTime::now(), + origin_server_ts: MilliSecondsSinceUnixEpoch::now(), sender: alice.user_id().clone(), content: encrypted_content, unsigned: Unsigned::default(), diff --git a/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs b/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs index cb81ad73..957fbed8 100644 --- a/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs +++ b/matrix_sdk_crypto/src/olm/group_sessions/inbound.rs @@ -12,12 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{ - collections::BTreeMap, - convert::{TryFrom, TryInto}, - fmt, mem, - sync::Arc, -}; +use std::{collections::BTreeMap, convert::TryFrom, fmt, mem, sync::Arc}; use matrix_sdk_common::{ events::{ @@ -310,13 +305,7 @@ impl InboundGroupSession { let mut decrypted_value = serde_json::from_str::(&plaintext)?; let decrypted_object = decrypted_value.as_object_mut().ok_or(EventError::NotAnObject)?; - // TODO better number conversion here. - let server_ts = event - .origin_server_ts - .duration_since(std::time::SystemTime::UNIX_EPOCH) - .unwrap_or_default() - .as_millis(); - let server_ts: i64 = server_ts.try_into().unwrap_or_default(); + let server_ts: i64 = event.origin_server_ts.0.into(); decrypted_object.insert("sender".to_owned(), event.sender.to_string().into()); decrypted_object.insert("event_id".to_owned(), event.event_id.to_string().into()); diff --git a/matrix_sdk_crypto/src/verification/requests.rs b/matrix_sdk_crypto/src/verification/requests.rs index 7f3ffcb4..097279d8 100644 --- a/matrix_sdk_crypto/src/verification/requests.rs +++ b/matrix_sdk_crypto/src/verification/requests.rs @@ -436,12 +436,13 @@ struct Passive { #[cfg(test)] mod test { - use std::{convert::TryFrom, time::SystemTime}; + use std::convert::TryFrom; use matrix_sdk_common::{ api::r0::message::send_message_event::Response as RoomMessageResponse, events::{SyncMessageEvent, Unsigned}, identifiers::{event_id, room_id, DeviceIdBox, UserId}, + MilliSecondsSinceUnixEpoch, }; use matrix_sdk_test::async_test; @@ -566,7 +567,7 @@ mod test { content: c, event_id: event_id.clone(), sender: bob_id(), - origin_server_ts: SystemTime::now(), + origin_server_ts: MilliSecondsSinceUnixEpoch::now(), unsigned: Unsigned::default(), } } else {