Upgrade ruma
parent
d4fe2fe0a2
commit
6a96368048
|
@ -26,6 +26,7 @@ use matrix_sdk_common::identifiers::ServerName;
|
||||||
use matrix_sdk_common::instant::{Duration, Instant};
|
use matrix_sdk_common::instant::{Duration, Instant};
|
||||||
use matrix_sdk_common::js_int::UInt;
|
use matrix_sdk_common::js_int::UInt;
|
||||||
use matrix_sdk_common::locks::RwLock;
|
use matrix_sdk_common::locks::RwLock;
|
||||||
|
use matrix_sdk_common::presence::PresenceState;
|
||||||
use matrix_sdk_common::uuid::Uuid;
|
use matrix_sdk_common::uuid::Uuid;
|
||||||
|
|
||||||
use futures_timer::Delay as sleep;
|
use futures_timer::Delay as sleep;
|
||||||
|
@ -1246,7 +1247,7 @@ impl Client {
|
||||||
filter: sync_settings.filter,
|
filter: sync_settings.filter,
|
||||||
since: sync_settings.token,
|
since: sync_settings.token,
|
||||||
full_state: sync_settings.full_state,
|
full_state: sync_settings.full_state,
|
||||||
set_presence: sync_events::SetPresence::Online,
|
set_presence: PresenceState::Online,
|
||||||
timeout: sync_settings.timeout,
|
timeout: sync_settings.timeout,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,7 @@ use matrix_sdk_common::{
|
||||||
},
|
},
|
||||||
uiaa::AuthData,
|
uiaa::AuthData,
|
||||||
},
|
},
|
||||||
events::{
|
events::room::{create::PreviousRoom, power_levels::PowerLevelsEventContent},
|
||||||
room::{create::PreviousRoom, power_levels::PowerLevelsEventContent},
|
|
||||||
EventJson,
|
|
||||||
},
|
|
||||||
identifiers::{DeviceId, RoomId, UserId},
|
identifiers::{DeviceId, RoomId, UserId},
|
||||||
js_int::UInt,
|
js_int::UInt,
|
||||||
};
|
};
|
||||||
|
@ -114,7 +111,7 @@ impl RoomBuilder {
|
||||||
|
|
||||||
/// Power level content to override in the default power level event.
|
/// Power level content to override in the default power level event.
|
||||||
pub fn power_level_override(&mut self, power: PowerLevelsEventContent) -> &mut Self {
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,9 @@ use crate::state::{AllRooms, ClientState, StateStore};
|
||||||
use crate::EventEmitter;
|
use crate::EventEmitter;
|
||||||
use matrix_sdk_common::events::{
|
use matrix_sdk_common::events::{
|
||||||
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent,
|
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent,
|
||||||
AnySyncRoomEvent, AnySyncStateEvent, EventJson,
|
AnySyncRoomEvent, AnySyncStateEvent,
|
||||||
};
|
};
|
||||||
|
use matrix_sdk_common::Raw;
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
use matrix_sdk_common::locks::Mutex;
|
use matrix_sdk_common::locks::Mutex;
|
||||||
|
@ -82,7 +83,7 @@ pub struct AdditionalEventData {
|
||||||
/// Represents the inner `prev_content` field
|
/// Represents the inner `prev_content` field
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
pub struct AdditionalUnsignedData {
|
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.
|
/// 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>
|
/// [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>
|
/// [discussion]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668>
|
||||||
fn hoist_room_event_prev_content(
|
fn hoist_room_event_prev_content(event: &Raw<AnySyncRoomEvent>) -> Option<Raw<AnySyncRoomEvent>> {
|
||||||
event: &EventJson<AnySyncRoomEvent>,
|
|
||||||
) -> Option<EventJson<AnySyncRoomEvent>> {
|
|
||||||
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
|
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
|
||||||
.map(|more_unsigned| more_unsigned.unsigned)
|
.map(|more_unsigned| more_unsigned.unsigned)
|
||||||
.map(|additional| additional.prev_content)
|
.map(|additional| additional.prev_content)
|
||||||
|
@ -112,7 +111,7 @@ fn hoist_room_event_prev_content(
|
||||||
member.prev_content = Some(prev)
|
member.prev_content = Some(prev)
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(EventJson::from(ev))
|
Some(Raw::from(ev))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
@ -122,8 +121,8 @@ fn hoist_room_event_prev_content(
|
||||||
///
|
///
|
||||||
/// See comment of `hoist_room_event_prev_content`.
|
/// See comment of `hoist_room_event_prev_content`.
|
||||||
fn hoist_state_event_prev_content(
|
fn hoist_state_event_prev_content(
|
||||||
event: &EventJson<AnySyncStateEvent>,
|
event: &Raw<AnySyncStateEvent>,
|
||||||
) -> Option<EventJson<AnySyncStateEvent>> {
|
) -> Option<Raw<AnySyncStateEvent>> {
|
||||||
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
|
let prev_content = serde_json::from_str::<AdditionalEventData>(event.json().get())
|
||||||
.map(|more_unsigned| more_unsigned.unsigned)
|
.map(|more_unsigned| more_unsigned.unsigned)
|
||||||
.map(|additional| additional.prev_content)
|
.map(|additional| additional.prev_content)
|
||||||
|
@ -134,14 +133,14 @@ fn hoist_state_event_prev_content(
|
||||||
match &mut ev {
|
match &mut ev {
|
||||||
AnySyncStateEvent::RoomMember(ref mut member) if member.prev_content.is_none() => {
|
AnySyncStateEvent::RoomMember(ref mut member) if member.prev_content.is_none() => {
|
||||||
member.prev_content = Some(prev_content.deserialize().ok()?);
|
member.prev_content = Some(prev_content.deserialize().ok()?);
|
||||||
Some(EventJson::from(ev))
|
Some(Raw::from(ev))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stripped_deserialize_prev_content(
|
fn stripped_deserialize_prev_content(
|
||||||
event: &EventJson<AnyStrippedStateEvent>,
|
event: &Raw<AnyStrippedStateEvent>,
|
||||||
) -> Option<AdditionalUnsignedData> {
|
) -> Option<AdditionalUnsignedData> {
|
||||||
serde_json::from_str::<AdditionalEventData>(event.json().get())
|
serde_json::from_str::<AdditionalEventData>(event.json().get())
|
||||||
.map(|more_unsigned| more_unsigned.unsigned)
|
.map(|more_unsigned| more_unsigned.unsigned)
|
||||||
|
@ -711,7 +710,7 @@ impl BaseClient {
|
||||||
pub async fn receive_joined_timeline_event(
|
pub async fn receive_joined_timeline_event(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event: &mut EventJson<AnySyncRoomEvent>,
|
event: &mut Raw<AnySyncRoomEvent>,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
match event.deserialize() {
|
match event.deserialize() {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
|
@ -823,7 +822,7 @@ impl BaseClient {
|
||||||
pub async fn receive_left_timeline_event(
|
pub async fn receive_left_timeline_event(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event: &EventJson<AnySyncRoomEvent>,
|
event: &Raw<AnySyncRoomEvent>,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
match event.deserialize() {
|
match event.deserialize() {
|
||||||
Ok(e) => {
|
Ok(e) => {
|
||||||
|
@ -1797,7 +1796,7 @@ impl BaseClient {
|
||||||
pub(crate) async fn emit_unrecognized_event<T>(
|
pub(crate) async fn emit_unrecognized_event<T>(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event: &EventJson<T>,
|
event: &Raw<T>,
|
||||||
room_state: RoomStateType,
|
room_state: RoomStateType,
|
||||||
) {
|
) {
|
||||||
let room = match room_state {
|
let room = match room_state {
|
||||||
|
@ -1834,11 +1833,7 @@ impl BaseClient {
|
||||||
mod test {
|
mod test {
|
||||||
use crate::identifiers::{RoomId, UserId};
|
use crate::identifiers::{RoomId, UserId};
|
||||||
#[cfg(feature = "messages")]
|
#[cfg(feature = "messages")]
|
||||||
use crate::{
|
use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw};
|
||||||
events::{AnySyncRoomEvent, EventJson},
|
|
||||||
identifiers::EventId,
|
|
||||||
BaseClientConfig, JsonStore,
|
|
||||||
};
|
|
||||||
use crate::{BaseClient, Session};
|
use crate::{BaseClient, Session};
|
||||||
use matrix_sdk_common_macros::async_trait;
|
use matrix_sdk_common_macros::async_trait;
|
||||||
use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson};
|
use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson};
|
||||||
|
@ -2391,7 +2386,7 @@ mod test {
|
||||||
"type": "m.room.redaction",
|
"type": "m.room.redaction",
|
||||||
"redacts": "$152037280074GZeOm:localhost"
|
"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
|
client
|
||||||
.receive_joined_timeline_event(&room_id, &mut event)
|
.receive_joined_timeline_event(&room_id, &mut event)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -1080,9 +1080,9 @@ impl Describe for MembershipChange {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::events::{room::encryption::EncryptionEventContent, EventJson, Unsigned};
|
use crate::events::{room::encryption::EncryptionEventContent, Unsigned};
|
||||||
use crate::identifiers::{EventId, UserId};
|
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 matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile};
|
||||||
|
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
@ -1645,7 +1645,7 @@ mod test {
|
||||||
"type": "m.room.redaction",
|
"type": "m.room.redaction",
|
||||||
"redacts": "$152037280074GZeOm:localhost"
|
"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
|
client
|
||||||
.receive_joined_timeline_event(&room_id, &mut event)
|
.receive_joined_timeline_event(&room_id, &mut event)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -16,13 +16,10 @@
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
events::{
|
events::{presence::PresenceEvent, room::member::MemberEventContent, SyncStateEvent},
|
||||||
presence::{PresenceEvent, PresenceState},
|
|
||||||
room::member::MemberEventContent,
|
|
||||||
SyncStateEvent,
|
|
||||||
},
|
|
||||||
identifiers::{RoomId, UserId},
|
identifiers::{RoomId, UserId},
|
||||||
js_int::{Int, UInt},
|
js_int::{Int, UInt},
|
||||||
|
presence::PresenceState,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ js_int = "0.1.8"
|
||||||
[dependencies.ruma]
|
[dependencies.ruma]
|
||||||
git = "https://github.com/ruma/ruma"
|
git = "https://github.com/ruma/ruma"
|
||||||
features = ["client-api"]
|
features = ["client-api"]
|
||||||
rev = "ea2992a4120d34495d6f07f141350d8f2a3429d3"
|
rev = "e047c647ddcb368e7eb1e05ae8823a9494273457"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
uuid = { version = "0.8.1", features = ["v4"] }
|
uuid = { version = "0.8.1", features = ["v4"] }
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub use ruma::{
|
||||||
error::{FromHttpRequestError, FromHttpResponseError, IntoHttpError, ServerError},
|
error::{FromHttpRequestError, FromHttpResponseError, IntoHttpError, ServerError},
|
||||||
Endpoint, EndpointError,
|
Endpoint, EndpointError,
|
||||||
},
|
},
|
||||||
events, identifiers, push,
|
events, identifiers, presence, push, Raw,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use uuid;
|
pub use uuid;
|
||||||
|
|
|
@ -29,15 +29,15 @@ use super::store::memorystore::MemoryStore;
|
||||||
use super::store::sqlite::SqliteStore;
|
use super::store::sqlite::SqliteStore;
|
||||||
use super::{device::Device, store::Result as StoreResult, CryptoStore};
|
use super::{device::Device, store::Result as StoreResult, CryptoStore};
|
||||||
|
|
||||||
use matrix_sdk_common::api;
|
|
||||||
use matrix_sdk_common::events::{
|
use matrix_sdk_common::events::{
|
||||||
forwarded_room_key::ForwardedRoomKeyEventContent, room::encrypted::EncryptedEventContent,
|
forwarded_room_key::ForwardedRoomKeyEventContent, room::encrypted::EncryptedEventContent,
|
||||||
room::message::MessageEventContent, room_key::RoomKeyEventContent,
|
room::message::MessageEventContent, room_key::RoomKeyEventContent,
|
||||||
room_key_request::RoomKeyRequestEventContent, Algorithm, AnySyncRoomEvent, AnyToDeviceEvent,
|
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::identifiers::{DeviceId, RoomId, UserId};
|
||||||
use matrix_sdk_common::uuid::Uuid;
|
use matrix_sdk_common::uuid::Uuid;
|
||||||
|
use matrix_sdk_common::{api, Raw};
|
||||||
|
|
||||||
use api::r0::keys;
|
use api::r0::keys;
|
||||||
use api::r0::{
|
use api::r0::{
|
||||||
|
@ -515,7 +515,7 @@ impl OlmMachine {
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
sender_key: &str,
|
sender_key: &str,
|
||||||
message: OlmMessage,
|
message: OlmMessage,
|
||||||
) -> OlmResult<(EventJson<AnyToDeviceEvent>, String)> {
|
) -> OlmResult<(Raw<AnyToDeviceEvent>, String)> {
|
||||||
// First try to decrypt using an existing session.
|
// First try to decrypt using an existing session.
|
||||||
let plaintext = if let Some(p) = self
|
let plaintext = if let Some(p) = self
|
||||||
.try_decrypt_olm_message(sender, sender_key, &message)
|
.try_decrypt_olm_message(sender, sender_key, &message)
|
||||||
|
@ -584,7 +584,7 @@ impl OlmMachine {
|
||||||
&self,
|
&self,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
plaintext: &str,
|
plaintext: &str,
|
||||||
) -> OlmResult<(EventJson<AnyToDeviceEvent>, String)> {
|
) -> OlmResult<(Raw<AnyToDeviceEvent>, String)> {
|
||||||
// TODO make the errors a bit more specific.
|
// TODO make the errors a bit more specific.
|
||||||
let decrypted_json: Value = serde_json::from_str(&plaintext)?;
|
let decrypted_json: Value = serde_json::from_str(&plaintext)?;
|
||||||
|
|
||||||
|
@ -629,7 +629,7 @@ impl OlmMachine {
|
||||||
.ok_or(EventError::MissingSigningKey)?;
|
.ok_or(EventError::MissingSigningKey)?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
EventJson::from(serde_json::from_value::<AnyToDeviceEvent>(decrypted_json)?),
|
Raw::from(serde_json::from_value::<AnyToDeviceEvent>(decrypted_json)?),
|
||||||
signing_key.to_owned(),
|
signing_key.to_owned(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -645,7 +645,7 @@ impl OlmMachine {
|
||||||
async fn decrypt_to_device_event(
|
async fn decrypt_to_device_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
event: &ToDeviceEvent<EncryptedEventContent>,
|
event: &ToDeviceEvent<EncryptedEventContent>,
|
||||||
) -> OlmResult<EventJson<AnyToDeviceEvent>> {
|
) -> OlmResult<Raw<AnyToDeviceEvent>> {
|
||||||
info!("Decrypting to-device event");
|
info!("Decrypting to-device event");
|
||||||
|
|
||||||
let content = if let EncryptedEventContent::OlmV1Curve25519AesSha2(c) = &event.content {
|
let content = if let EncryptedEventContent::OlmV1Curve25519AesSha2(c) = &event.content {
|
||||||
|
@ -709,7 +709,7 @@ impl OlmMachine {
|
||||||
sender_key: &str,
|
sender_key: &str,
|
||||||
signing_key: &str,
|
signing_key: &str,
|
||||||
event: &mut ToDeviceEvent<RoomKeyEventContent>,
|
event: &mut ToDeviceEvent<RoomKeyEventContent>,
|
||||||
) -> OlmResult<Option<EventJson<AnyToDeviceEvent>>> {
|
) -> OlmResult<Option<Raw<AnyToDeviceEvent>>> {
|
||||||
match event.content.algorithm {
|
match event.content.algorithm {
|
||||||
Algorithm::MegolmV1AesSha2 => {
|
Algorithm::MegolmV1AesSha2 => {
|
||||||
let session_key = GroupSessionKey(mem::take(&mut event.content.session_key));
|
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 _ = 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))
|
Ok(Some(event))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -968,8 +968,8 @@ impl OlmMachine {
|
||||||
&mut self,
|
&mut self,
|
||||||
sender_key: &str,
|
sender_key: &str,
|
||||||
signing_key: &str,
|
signing_key: &str,
|
||||||
event: &EventJson<AnyToDeviceEvent>,
|
event: &Raw<AnyToDeviceEvent>,
|
||||||
) -> OlmResult<Option<EventJson<AnyToDeviceEvent>>> {
|
) -> OlmResult<Option<Raw<AnyToDeviceEvent>>> {
|
||||||
let event = if let Ok(e) = event.deserialize() {
|
let event = if let Ok(e) = event.deserialize() {
|
||||||
e
|
e
|
||||||
} else {
|
} else {
|
||||||
|
@ -1078,7 +1078,7 @@ impl OlmMachine {
|
||||||
&mut self,
|
&mut self,
|
||||||
event: &SyncMessageEvent<EncryptedEventContent>,
|
event: &SyncMessageEvent<EncryptedEventContent>,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
) -> MegolmResult<EventJson<AnySyncRoomEvent>> {
|
) -> MegolmResult<Raw<AnySyncRoomEvent>> {
|
||||||
let content = match &event.content {
|
let content = match &event.content {
|
||||||
EncryptedEventContent::MegolmV1AesSha2(c) => c,
|
EncryptedEventContent::MegolmV1AesSha2(c) => c,
|
||||||
_ => return Err(EventError::UnsupportedAlgorithm.into()),
|
_ => return Err(EventError::UnsupportedAlgorithm.into()),
|
||||||
|
@ -1185,10 +1185,11 @@ mod test {
|
||||||
encrypted::EncryptedEventContent,
|
encrypted::EncryptedEventContent,
|
||||||
message::{MessageEventContent, TextMessageEventContent},
|
message::{MessageEventContent, TextMessageEventContent},
|
||||||
},
|
},
|
||||||
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventJson, EventType,
|
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent,
|
||||||
SyncMessageEvent, ToDeviceEvent, Unsigned,
|
ToDeviceEvent, Unsigned,
|
||||||
};
|
};
|
||||||
use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId};
|
use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId};
|
||||||
|
use matrix_sdk_common::Raw;
|
||||||
use matrix_sdk_test::test_json;
|
use matrix_sdk_test::test_json;
|
||||||
|
|
||||||
fn alice_id() -> UserId {
|
fn alice_id() -> UserId {
|
||||||
|
@ -1223,7 +1224,7 @@ mod test {
|
||||||
fn to_device_requests_to_content(requests: Vec<ToDeviceRequest>) -> EncryptedEventContent {
|
fn to_device_requests_to_content(requests: Vec<ToDeviceRequest>) -> EncryptedEventContent {
|
||||||
let to_device_request = &requests[0];
|
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
|
to_device_request
|
||||||
.messages
|
.messages
|
||||||
.values()
|
.values()
|
||||||
|
|
|
@ -38,9 +38,10 @@ pub use olm_rs::{
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
events::{
|
events::{
|
||||||
room::{encrypted::EncryptedEventContent, message::MessageEventContent},
|
room::{encrypted::EncryptedEventContent, message::MessageEventContent},
|
||||||
Algorithm, AnySyncRoomEvent, EventJson, EventType, SyncMessageEvent,
|
Algorithm, AnySyncRoomEvent, EventType, SyncMessageEvent,
|
||||||
},
|
},
|
||||||
identifiers::{DeviceId, RoomId},
|
identifiers::{DeviceId, RoomId},
|
||||||
|
Raw,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The private session key of a group session.
|
/// The private session key of a group session.
|
||||||
|
@ -181,7 +182,7 @@ impl InboundGroupSession {
|
||||||
pub async fn decrypt(
|
pub async fn decrypt(
|
||||||
&self,
|
&self,
|
||||||
event: &SyncMessageEvent<EncryptedEventContent>,
|
event: &SyncMessageEvent<EncryptedEventContent>,
|
||||||
) -> MegolmResult<(EventJson<AnySyncRoomEvent>, u32)> {
|
) -> MegolmResult<(Raw<AnySyncRoomEvent>, u32)> {
|
||||||
let content = match &event.content {
|
let content = match &event.content {
|
||||||
EncryptedEventContent::MegolmV1AesSha2(c) => c,
|
EncryptedEventContent::MegolmV1AesSha2(c) => c,
|
||||||
_ => return Err(EventError::UnsupportedAlgorithm.into()),
|
_ => return Err(EventError::UnsupportedAlgorithm.into()),
|
||||||
|
@ -212,7 +213,7 @@ impl InboundGroupSession {
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
serde_json::from_value::<EventJson<AnySyncRoomEvent>>(decrypted_value)?,
|
serde_json::from_value::<Raw<AnySyncRoomEvent>>(decrypted_value)?,
|
||||||
message_index,
|
message_index,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue