Merge branch 'master' into sas-verification

master
Damir Jelić 2020-07-26 21:20:53 +02:00
commit 7128505768
9 changed files with 44 additions and 52 deletions

View File

@ -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,
};

View File

@ -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
}

View File

@ -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<EventJson<MemberEventContent>>,
pub prev_content: Option<Raw<MemberEventContent>>,
}
/// Transform room event by hoisting `prev_content` field from `unsigned` to the top level.
@ -93,9 +94,7 @@ pub struct AdditionalUnsignedData {
///
/// [synapse-bug]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668>
/// [discussion]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668>
fn hoist_room_event_prev_content(
event: &EventJson<AnySyncRoomEvent>,
) -> Option<EventJson<AnySyncRoomEvent>> {
fn hoist_room_event_prev_content(event: &Raw<AnySyncRoomEvent>) -> Option<Raw<AnySyncRoomEvent>> {
let prev_content = serde_json::from_str::<AdditionalEventData>(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<AnySyncStateEvent>,
) -> Option<EventJson<AnySyncStateEvent>> {
event: &Raw<AnySyncStateEvent>,
) -> Option<Raw<AnySyncStateEvent>> {
let prev_content = serde_json::from_str::<AdditionalEventData>(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<AnyStrippedStateEvent>,
event: &Raw<AnyStrippedStateEvent>,
) -> Option<AdditionalUnsignedData> {
serde_json::from_str::<AdditionalEventData>(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<AnySyncRoomEvent>,
event: &mut Raw<AnySyncRoomEvent>,
) -> Result<bool> {
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<AnySyncRoomEvent>,
event: &Raw<AnySyncRoomEvent>,
) -> Result<bool> {
match event.deserialize() {
Ok(e) => {
@ -1797,7 +1796,7 @@ impl BaseClient {
pub(crate) async fn emit_unrecognized_event<T>(
&self,
room_id: &RoomId,
event: &EventJson<T>,
event: &Raw<T>,
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<AnySyncRoomEvent> = serde_json::from_value(json).unwrap();
let mut event: Raw<AnySyncRoomEvent> = serde_json::from_value(json).unwrap();
client
.receive_joined_timeline_event(&room_id, &mut event)
.await

View File

@ -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<AnySyncRoomEvent> = serde_json::from_value(json).unwrap();
let mut event: Raw<AnySyncRoomEvent> = serde_json::from_value(json).unwrap();
client
.receive_joined_timeline_event(&room_id, &mut event)
.await

View File

@ -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};

View File

@ -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"] }

View File

@ -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;

View File

@ -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<AnyToDeviceEvent>, String)> {
) -> OlmResult<(Raw<AnyToDeviceEvent>, 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<AnyToDeviceEvent>, String)> {
) -> OlmResult<(Raw<AnyToDeviceEvent>, 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::<AnyToDeviceEvent>(decrypted_json)?),
Raw::from(serde_json::from_value::<AnyToDeviceEvent>(decrypted_json)?),
signing_key.to_owned(),
))
}
@ -645,7 +645,7 @@ impl OlmMachine {
async fn decrypt_to_device_event(
&mut self,
event: &ToDeviceEvent<EncryptedEventContent>,
) -> OlmResult<EventJson<AnyToDeviceEvent>> {
) -> OlmResult<Raw<AnyToDeviceEvent>> {
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<RoomKeyEventContent>,
) -> OlmResult<Option<EventJson<AnyToDeviceEvent>>> {
) -> OlmResult<Option<Raw<AnyToDeviceEvent>>> {
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<AnyToDeviceEvent>,
) -> OlmResult<Option<EventJson<AnyToDeviceEvent>>> {
event: &Raw<AnyToDeviceEvent>,
) -> OlmResult<Option<Raw<AnyToDeviceEvent>>> {
let event = if let Ok(e) = event.deserialize() {
e
} else {
@ -1078,7 +1078,7 @@ impl OlmMachine {
&mut self,
event: &SyncMessageEvent<EncryptedEventContent>,
room_id: &RoomId,
) -> MegolmResult<EventJson<AnySyncRoomEvent>> {
) -> MegolmResult<Raw<AnySyncRoomEvent>> {
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<ToDeviceRequest>) -> EncryptedEventContent {
let to_device_request = &requests[0];
let content: EventJson<EncryptedEventContent> = serde_json::from_str(
let content: Raw<EncryptedEventContent> = serde_json::from_str(
to_device_request
.messages
.values()

View File

@ -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<EncryptedEventContent>,
) -> MegolmResult<(EventJson<AnySyncRoomEvent>, u32)> {
) -> MegolmResult<(Raw<AnySyncRoomEvent>, 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::<EventJson<AnySyncRoomEvent>>(decrypted_value)?,
serde_json::from_value::<Raw<AnySyncRoomEvent>>(decrypted_value)?,
message_index,
))
}