mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-16 03:55:42 -04:00
Upgrade Ruma
This commit is contained in:
@@ -24,8 +24,7 @@ base64 = "0.13.0"
|
||||
byteorder = "1.4.3"
|
||||
image = { version = "0.23.14", optional = true }
|
||||
qrcode = { version = "0.12.0", default-features = false }
|
||||
ruma-identifiers = "0.22.0"
|
||||
ruma-serde = "0.6.0"
|
||||
ruma-common = { git = "https://github.com/ruma/ruma", rev = "deea762b8" }
|
||||
rqrr = { version = "0.4.0", optional = true }
|
||||
thiserror = "1.0.25"
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ pub enum DecodingError {
|
||||
Mode(u8),
|
||||
/// The flow id is not a valid event ID.
|
||||
#[error(transparent)]
|
||||
Identifier(#[from] ruma_identifiers::Error),
|
||||
Identifier(#[from] ruma_common::IdParseError),
|
||||
#[error(transparent)]
|
||||
/// The QR code data does not contain all the necessary fields.
|
||||
Read(#[from] std::io::Error),
|
||||
|
||||
@@ -21,8 +21,7 @@ use byteorder::{BigEndian, ReadBytesExt};
|
||||
#[cfg(feature = "decode_image")]
|
||||
use image::{DynamicImage, GenericImage, GenericImageView, ImageBuffer, Luma};
|
||||
use qrcode::QrCode;
|
||||
use ruma_identifiers::EventId;
|
||||
use ruma_serde::Base64;
|
||||
use ruma_common::{serde::Base64, EventId};
|
||||
use vodozemac::Ed25519PublicKey;
|
||||
|
||||
#[cfg(feature = "decode_image")]
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::convert::TryInto;
|
||||
#[cfg(feature = "decode_image")]
|
||||
use image::{GenericImage, GenericImageView, Luma};
|
||||
use qrcode::{bits::Bits, EcLevel, QrCode, Version};
|
||||
use ruma_serde::Base64;
|
||||
use ruma_common::serde::Base64;
|
||||
use vodozemac::Ed25519PublicKey;
|
||||
|
||||
#[cfg(feature = "decode_image")]
|
||||
|
||||
@@ -29,7 +29,7 @@ http = "0.2"
|
||||
matrix-sdk = { version = "0.4", path = "../matrix-sdk", default-features = false, features = ["appservice"] }
|
||||
percent-encoding = "2.1.0"
|
||||
regex = "1"
|
||||
ruma = { version = "0.5.0", features = ["client-api-c", "appservice-api-s"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "deea762b8", features = ["client-api-c", "appservice-api-s"] }
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
serde_yaml = "0.8"
|
||||
|
||||
@@ -45,7 +45,7 @@ pub enum Error {
|
||||
HttpRequest(#[from] ruma::api::error::FromHttpRequestError),
|
||||
|
||||
#[error(transparent)]
|
||||
Identifier(#[from] ruma::identifiers::Error),
|
||||
Identifier(#[from] ruma::IdParseError),
|
||||
|
||||
#[error(transparent)]
|
||||
Http(#[from] http::Error),
|
||||
|
||||
@@ -103,7 +103,7 @@ use ruma::{
|
||||
},
|
||||
client::account::register,
|
||||
},
|
||||
assign, identifiers, DeviceId, ServerName, UserId,
|
||||
assign, DeviceId, IdParseError, ServerName, UserId,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use tracing::info;
|
||||
@@ -223,7 +223,7 @@ impl AppService {
|
||||
/// [AppService Registration]: https://matrix.org/docs/spec/application_service/r0.1.2#registration
|
||||
pub async fn new(
|
||||
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
|
||||
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
|
||||
server_name: impl TryInto<Box<ServerName>, Error = IdParseError>,
|
||||
registration: AppServiceRegistration,
|
||||
) -> Result<Self> {
|
||||
let appservice =
|
||||
@@ -237,7 +237,7 @@ impl AppService {
|
||||
/// for the [`Client`]
|
||||
pub async fn with_client_builder(
|
||||
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
|
||||
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
|
||||
server_name: impl TryInto<Box<ServerName>, Error = IdParseError>,
|
||||
registration: AppServiceRegistration,
|
||||
builder: ClientBuilder,
|
||||
) -> Result<Self> {
|
||||
|
||||
@@ -44,7 +44,7 @@ matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" }
|
||||
matrix-sdk-crypto = { version = "0.4.0", path = "../matrix-sdk-crypto", optional = true }
|
||||
pbkdf2 = { version = "0.10.0", default-features = false, optional = true }
|
||||
rand = { version = "0.8.4", optional = true }
|
||||
ruma = { version = "0.5.0", features = ["client-api-c", "signatures", "unstable-pre-spec"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "deea762b8", features = ["client-api-c", "signatures"] }
|
||||
serde = { version = "1.0.126", features = ["rc"] }
|
||||
serde_json = "1.0.64"
|
||||
sha2 = { version = "0.10.1", optional = true }
|
||||
|
||||
@@ -45,7 +45,7 @@ use ruma::{
|
||||
api::client::keys::claim_keys::v3::Request as KeysClaimRequest,
|
||||
events::{
|
||||
room::{encrypted::RoomEncryptedEventContent, history_visibility::HistoryVisibility},
|
||||
AnySyncMessageEvent, MessageEventContent,
|
||||
AnySyncMessageLikeEvent, EventContent, MessageLikeEventType,
|
||||
},
|
||||
DeviceId, TransactionId,
|
||||
};
|
||||
@@ -54,7 +54,7 @@ use ruma::{
|
||||
events::{
|
||||
room::member::MembershipState, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
|
||||
AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, AnySyncStateEvent,
|
||||
EventContent, GlobalAccountDataEventType, StateEventType,
|
||||
GlobalAccountDataEventType, StateEventType,
|
||||
},
|
||||
push::{Action, PushConditionRoomCtx, Ruleset},
|
||||
serde::Raw,
|
||||
@@ -300,7 +300,7 @@ impl BaseClient {
|
||||
},
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomEncrypted(
|
||||
AnySyncRoomEvent::MessageLike(AnySyncMessageLikeEvent::RoomEncrypted(
|
||||
encrypted,
|
||||
)) => {
|
||||
if let Some(olm) = self.olm_machine().await {
|
||||
@@ -367,7 +367,7 @@ impl BaseClient {
|
||||
room_info: &mut RoomInfo,
|
||||
) -> (
|
||||
BTreeMap<Box<UserId>, StrippedMemberEvent>,
|
||||
BTreeMap<String, BTreeMap<String, Raw<AnyStrippedStateEvent>>>,
|
||||
BTreeMap<StateEventType, BTreeMap<String, Raw<AnyStrippedStateEvent>>>,
|
||||
) {
|
||||
events.iter().fold(
|
||||
(BTreeMap::new(), BTreeMap::new()),
|
||||
@@ -387,7 +387,7 @@ impl BaseClient {
|
||||
Ok(e) => {
|
||||
room_info.handle_state_event(&e.content());
|
||||
state_events
|
||||
.entry(e.content().event_type().to_owned())
|
||||
.entry(e.event_type())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(e.state_key().to_owned(), raw_event.clone());
|
||||
}
|
||||
@@ -460,7 +460,7 @@ impl BaseClient {
|
||||
}
|
||||
} else {
|
||||
state_events
|
||||
.entry(event.content().event_type().to_owned())
|
||||
.entry(event.event_type())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(event.state_key().to_owned(), raw_event.clone());
|
||||
}
|
||||
@@ -522,7 +522,7 @@ impl BaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
account_data.insert(event.content().event_type().to_owned(), raw_event.clone());
|
||||
account_data.insert(event.event_type(), raw_event.clone());
|
||||
}
|
||||
|
||||
changes.account_data = account_data;
|
||||
@@ -1020,7 +1020,7 @@ impl BaseClient {
|
||||
pub async fn encrypt(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
content: impl MessageEventContent,
|
||||
content: impl EventContent<EventType = MessageLikeEventType>,
|
||||
) -> Result<RoomEncryptedEventContent> {
|
||||
match self.olm_machine().await {
|
||||
Some(o) => Ok(o.encrypt(room_id, content).await?),
|
||||
@@ -1156,7 +1156,7 @@ impl BaseClient {
|
||||
pub async fn get_push_rules(&self, changes: &StateChanges) -> Result<Ruleset> {
|
||||
if let Some(AnyGlobalAccountDataEvent::PushRules(event)) = changes
|
||||
.account_data
|
||||
.get(GlobalAccountDataEventType::PushRules.as_str())
|
||||
.get(&GlobalAccountDataEventType::PushRules)
|
||||
.and_then(|e| e.deserialize().ok())
|
||||
{
|
||||
Ok(event.content.global)
|
||||
@@ -1205,7 +1205,7 @@ impl BaseClient {
|
||||
let room_power_levels = if let Some(AnySyncStateEvent::RoomPowerLevels(event)) = changes
|
||||
.state
|
||||
.get(room_id)
|
||||
.and_then(|types| types.get(StateEventType::RoomPowerLevels.as_str()))
|
||||
.and_then(|types| types.get(&StateEventType::RoomPowerLevels))
|
||||
.and_then(|events| events.get(""))
|
||||
.and_then(|e| e.deserialize().ok())
|
||||
{
|
||||
@@ -1255,7 +1255,7 @@ impl BaseClient {
|
||||
if let Some(AnySyncStateEvent::RoomPowerLevels(event)) = changes
|
||||
.state
|
||||
.get(&**room_id)
|
||||
.and_then(|types| types.get(StateEventType::RoomPowerLevels.as_str()))
|
||||
.and_then(|types| types.get(&StateEventType::RoomPowerLevels))
|
||||
.and_then(|events| events.get(""))
|
||||
.and_then(|e| e.deserialize().ok())
|
||||
{
|
||||
|
||||
@@ -8,11 +8,11 @@ use ruma::{
|
||||
AudioMessageEventContent, FileMessageEventContent, ImageMessageEventContent,
|
||||
LocationMessageEventContent, VideoMessageEventContent,
|
||||
},
|
||||
EncryptedFile,
|
||||
MediaSource,
|
||||
},
|
||||
sticker::StickerEventContent,
|
||||
},
|
||||
MxcUri, UInt,
|
||||
UInt,
|
||||
};
|
||||
|
||||
const UNIQUE_SEPARATOR: &str = "_";
|
||||
@@ -64,20 +64,10 @@ impl UniqueKey for MediaThumbnailSize {
|
||||
}
|
||||
}
|
||||
|
||||
/// A request for media data.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MediaType {
|
||||
/// A media content URI.
|
||||
Uri(Box<MxcUri>),
|
||||
|
||||
/// An encrypted media content.
|
||||
Encrypted(Box<EncryptedFile>),
|
||||
}
|
||||
|
||||
impl UniqueKey for MediaType {
|
||||
impl UniqueKey for MediaSource {
|
||||
fn unique_key(&self) -> String {
|
||||
match self {
|
||||
Self::Uri(uri) => uri.to_string(),
|
||||
Self::Plain(uri) => uri.to_string(),
|
||||
Self::Encrypted(file) => file.url.to_string(),
|
||||
}
|
||||
}
|
||||
@@ -86,8 +76,8 @@ impl UniqueKey for MediaType {
|
||||
/// A request for media data.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MediaRequest {
|
||||
/// The type of the media file.
|
||||
pub media_type: MediaType,
|
||||
/// The source of the media file.
|
||||
pub source: MediaSource,
|
||||
|
||||
/// The requested format of the media data.
|
||||
pub format: MediaFormat,
|
||||
@@ -95,202 +85,84 @@ pub struct MediaRequest {
|
||||
|
||||
impl UniqueKey for MediaRequest {
|
||||
fn unique_key(&self) -> String {
|
||||
format!("{}{}{}", self.media_type.unique_key(), UNIQUE_SEPARATOR, self.format.unique_key())
|
||||
format!("{}{}{}", self.source.unique_key(), UNIQUE_SEPARATOR, self.format.unique_key())
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for media event content.
|
||||
pub trait MediaEventContent {
|
||||
/// Get the type of the file for `Self`.
|
||||
/// Get the source of the file for `Self`.
|
||||
///
|
||||
/// Returns `None` if `Self` has no file.
|
||||
fn file(&self) -> Option<MediaType>;
|
||||
fn source(&self) -> Option<MediaSource>;
|
||||
|
||||
/// Get the type of the thumbnail for `Self`.
|
||||
/// Get the source of the thumbnail for `Self`.
|
||||
///
|
||||
/// Returns `None` if `Self` has no thumbnail.
|
||||
fn thumbnail(&self) -> Option<MediaType>;
|
||||
fn thumbnail_source(&self) -> Option<MediaSource>;
|
||||
}
|
||||
|
||||
impl MediaEventContent for StickerEventContent {
|
||||
fn file(&self) -> Option<MediaType> {
|
||||
Some(MediaType::Uri(self.url.clone()))
|
||||
fn source(&self) -> Option<MediaSource> {
|
||||
Some(MediaSource::Plain(self.url.clone()))
|
||||
}
|
||||
|
||||
fn thumbnail(&self) -> Option<MediaType> {
|
||||
fn thumbnail_source(&self) -> Option<MediaSource> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl MediaEventContent for AudioMessageEventContent {
|
||||
fn file(&self) -> Option<MediaType> {
|
||||
self.file
|
||||
.as_ref()
|
||||
.map(|e| MediaType::Encrypted(e.clone()))
|
||||
.or_else(|| self.url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
fn source(&self) -> Option<MediaSource> {
|
||||
Some(self.source.clone())
|
||||
}
|
||||
|
||||
fn thumbnail(&self) -> Option<MediaType> {
|
||||
fn thumbnail_source(&self) -> Option<MediaSource> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl MediaEventContent for FileMessageEventContent {
|
||||
fn file(&self) -> Option<MediaType> {
|
||||
self.file
|
||||
.as_ref()
|
||||
.map(|e| MediaType::Encrypted(e.clone()))
|
||||
.or_else(|| self.url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
fn source(&self) -> Option<MediaSource> {
|
||||
Some(self.source.clone())
|
||||
}
|
||||
|
||||
fn thumbnail(&self) -> Option<MediaType> {
|
||||
self.info.as_ref().and_then(|info| {
|
||||
info.thumbnail_file
|
||||
.as_ref()
|
||||
.map(|file| MediaType::Encrypted(file.clone()))
|
||||
.or_else(|| info.thumbnail_url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
})
|
||||
fn thumbnail_source(&self) -> Option<MediaSource> {
|
||||
self.info.as_ref()?.thumbnail_source.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl MediaEventContent for ImageMessageEventContent {
|
||||
fn file(&self) -> Option<MediaType> {
|
||||
self.file
|
||||
.as_ref()
|
||||
.map(|e| MediaType::Encrypted(e.clone()))
|
||||
.or_else(|| self.url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
fn source(&self) -> Option<MediaSource> {
|
||||
Some(self.source.clone())
|
||||
}
|
||||
|
||||
fn thumbnail(&self) -> Option<MediaType> {
|
||||
fn thumbnail_source(&self) -> Option<MediaSource> {
|
||||
self.info
|
||||
.as_ref()
|
||||
.and_then(|info| {
|
||||
info.thumbnail_file
|
||||
.as_ref()
|
||||
.map(|file| MediaType::Encrypted(file.clone()))
|
||||
.or_else(|| info.thumbnail_url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
})
|
||||
.or_else(|| self.url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
.and_then(|info| info.thumbnail_source.clone())
|
||||
.or_else(|| Some(self.source.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl MediaEventContent for VideoMessageEventContent {
|
||||
fn file(&self) -> Option<MediaType> {
|
||||
self.file
|
||||
.as_ref()
|
||||
.map(|e| MediaType::Encrypted(e.clone()))
|
||||
.or_else(|| self.url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
fn source(&self) -> Option<MediaSource> {
|
||||
Some(self.source.clone())
|
||||
}
|
||||
|
||||
fn thumbnail(&self) -> Option<MediaType> {
|
||||
fn thumbnail_source(&self) -> Option<MediaSource> {
|
||||
self.info
|
||||
.as_ref()
|
||||
.and_then(|info| {
|
||||
info.thumbnail_file
|
||||
.as_ref()
|
||||
.map(|file| MediaType::Encrypted(file.clone()))
|
||||
.or_else(|| info.thumbnail_url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
})
|
||||
.or_else(|| self.url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
.and_then(|info| info.thumbnail_source.clone())
|
||||
.or_else(|| Some(self.source.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
impl MediaEventContent for LocationMessageEventContent {
|
||||
fn file(&self) -> Option<MediaType> {
|
||||
fn source(&self) -> Option<MediaSource> {
|
||||
None
|
||||
}
|
||||
|
||||
fn thumbnail(&self) -> Option<MediaType> {
|
||||
self.info.as_ref().and_then(|info| {
|
||||
info.thumbnail_file
|
||||
.as_ref()
|
||||
.map(|file| MediaType::Encrypted(file.clone()))
|
||||
.or_else(|| info.thumbnail_url.as_ref().map(|uri| MediaType::Uri(uri.clone())))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "encryption", test))]
|
||||
pub(crate) mod test {
|
||||
use ruma::events::room::{
|
||||
message::{FileInfo, LocationInfo, VideoInfo},
|
||||
ImageInfo,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn encrypted_test_data() -> (Box<MxcUri>, EncryptedFile) {
|
||||
let c = &mut std::io::Cursor::new("some content");
|
||||
let reader = crate::crypto::AttachmentEncryptor::new(c);
|
||||
|
||||
let keys = reader.finish();
|
||||
let file: EncryptedFile = ruma::events::room::EncryptedFileInit {
|
||||
url: "foobar".into(),
|
||||
key: keys.web_key,
|
||||
iv: keys.iv,
|
||||
hashes: keys.hashes,
|
||||
v: keys.version,
|
||||
}
|
||||
.into();
|
||||
let url = file.url.clone();
|
||||
(url, file)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_audio_content_prefer_crypt_type() {
|
||||
let (u, f) = encrypted_test_data();
|
||||
let mut c = AudioMessageEventContent::encrypted("foo".to_owned(), f);
|
||||
c.url = Some(u);
|
||||
assert!(matches!(c.file(), Some(MediaType::Encrypted(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_file_content_prefer_crypt_type() {
|
||||
let (u, f) = encrypted_test_data();
|
||||
let mut c = FileMessageEventContent::encrypted("foo".to_owned(), f.clone());
|
||||
c.url = Some(u.clone());
|
||||
let mut info = FileInfo::default();
|
||||
info.thumbnail_url = Some(u);
|
||||
info.thumbnail_file = Some(Box::new(f));
|
||||
c.info = Some(Box::new(info));
|
||||
assert!(matches!(c.file(), Some(MediaType::Encrypted(_))));
|
||||
assert!(matches!(c.thumbnail(), Some(MediaType::Encrypted(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_image_content_prefer_crypt_type() {
|
||||
let (u, f) = encrypted_test_data();
|
||||
let mut c = ImageMessageEventContent::encrypted("foo".to_owned(), f.clone());
|
||||
c.url = Some(u.clone());
|
||||
let mut info = ImageInfo::default();
|
||||
info.thumbnail_url = Some(u);
|
||||
info.thumbnail_file = Some(Box::new(f));
|
||||
c.info = Some(Box::new(info));
|
||||
assert!(matches!(c.file(), Some(MediaType::Encrypted(_))));
|
||||
assert!(matches!(c.thumbnail(), Some(MediaType::Encrypted(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_video_content_prefer_crypt_type() {
|
||||
let (u, f) = encrypted_test_data();
|
||||
let mut c = VideoMessageEventContent::encrypted("foo".to_owned(), f.clone());
|
||||
c.url = Some(u.clone());
|
||||
let mut info = VideoInfo::default();
|
||||
info.thumbnail_url = Some(u);
|
||||
info.thumbnail_file = Some(Box::new(f));
|
||||
c.info = Some(Box::new(info));
|
||||
assert!(matches!(c.file(), Some(MediaType::Encrypted(_))));
|
||||
assert!(matches!(c.thumbnail(), Some(MediaType::Encrypted(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_location_content_prefer_crypt_type() {
|
||||
let (u, f) = encrypted_test_data();
|
||||
let mut c = LocationMessageEventContent::new("foo".to_owned(), "27,37".to_owned());
|
||||
let mut info = LocationInfo::default();
|
||||
info.thumbnail_url = Some(u);
|
||||
info.thumbnail_file = Some(Box::new(f));
|
||||
c.info = Some(Box::new(info));
|
||||
assert!(matches!(c.thumbnail(), Some(MediaType::Encrypted(_))));
|
||||
fn thumbnail_source(&self) -> Option<MediaSource> {
|
||||
self.info.as_ref()?.thumbnail_source.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,8 @@ use ruma::{
|
||||
events::{
|
||||
receipt::Receipt,
|
||||
room::{
|
||||
create::{RoomCreateEventContent, RoomType as CreateRoomType},
|
||||
encryption::RoomEncryptionEventContent,
|
||||
guest_access::GuestAccess,
|
||||
history_visibility::HistoryVisibility,
|
||||
join_rules::JoinRule,
|
||||
create::RoomCreateEventContent, encryption::RoomEncryptionEventContent,
|
||||
guest_access::GuestAccess, history_visibility::HistoryVisibility, join_rules::JoinRule,
|
||||
tombstone::RoomTombstoneEventContent,
|
||||
},
|
||||
tag::Tags,
|
||||
@@ -36,6 +33,7 @@ use ruma::{
|
||||
StateEventType,
|
||||
},
|
||||
receipt::ReceiptType,
|
||||
room::RoomType as CreateRoomType,
|
||||
EventId, MxcUri, RoomAliasId, RoomId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -46,15 +46,16 @@ macro_rules! statestore_integration_tests {
|
||||
},
|
||||
device_id, event_id,
|
||||
events::{
|
||||
presence::PresenceEvent, EventContent,
|
||||
presence::PresenceEvent,
|
||||
room::{
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
power_levels::RoomPowerLevelsEventContent,
|
||||
MediaSource,
|
||||
},
|
||||
AnyEphemeralRoomEventContent, AnySyncEphemeralRoomEvent,
|
||||
AnyStrippedStateEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
|
||||
AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType,
|
||||
StateEventType, Unsigned,
|
||||
StateEventType, StateUnsigned,
|
||||
},
|
||||
mxc_uri,
|
||||
receipt::ReceiptType,
|
||||
@@ -70,7 +71,7 @@ macro_rules! statestore_integration_tests {
|
||||
http::Response,
|
||||
RoomType, Session,
|
||||
deserialized_responses::{MemberEvent, StrippedMemberEvent, RoomEvent, SyncRoomEvent, TimelineSlice},
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSize, MediaType},
|
||||
media::{MediaFormat, MediaRequest, MediaThumbnailSize},
|
||||
store::{
|
||||
Store,
|
||||
StateStore,
|
||||
@@ -216,7 +217,7 @@ macro_rules! statestore_integration_tests {
|
||||
changes.stripped_state.insert(
|
||||
stripped_room_id.to_owned(),
|
||||
BTreeMap::from([(
|
||||
stripped_name_event.content().event_type().to_owned(),
|
||||
stripped_name_event.event_type(),
|
||||
BTreeMap::from([(
|
||||
stripped_name_event.state_key().to_owned(),
|
||||
stripped_name_raw.clone(),
|
||||
@@ -245,7 +246,6 @@ macro_rules! statestore_integration_tests {
|
||||
"type": "m.room.power_levels",
|
||||
"origin_server_ts": 0u64,
|
||||
"state_key": "",
|
||||
"unsigned": Unsigned::default(),
|
||||
});
|
||||
|
||||
serde_json::from_value(event).unwrap()
|
||||
@@ -262,8 +262,7 @@ macro_rules! statestore_integration_tests {
|
||||
sender: user_id.to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch(198u32.into()),
|
||||
state_key: user_id.to_owned(),
|
||||
prev_content: None,
|
||||
unsigned: Unsigned::default(),
|
||||
unsigned: StateUnsigned::default(),
|
||||
}
|
||||
|
||||
}
|
||||
@@ -454,11 +453,13 @@ macro_rules! statestore_integration_tests {
|
||||
let uri = mxc_uri!("mxc://localhost/media");
|
||||
let content: Vec<u8> = "somebinarydata".into();
|
||||
|
||||
let request_file =
|
||||
MediaRequest { media_type: MediaType::Uri(uri.to_owned()), format: MediaFormat::File };
|
||||
let request_file = MediaRequest {
|
||||
source: MediaSource::Plain(uri.to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
|
||||
let request_thumbnail = MediaRequest {
|
||||
media_type: MediaType::Uri(uri.to_owned()),
|
||||
source: MediaSource::Plain(uri.to_owned()),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSize {
|
||||
method: Method::Crop,
|
||||
width: uint!(100),
|
||||
|
||||
@@ -28,7 +28,7 @@ use ruma::{
|
||||
receipt::Receipt,
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
|
||||
AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType,
|
||||
AnySyncMessageLikeEvent, AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType,
|
||||
RoomAccountDataEventType, StateEventType,
|
||||
},
|
||||
receipt::ReceiptType,
|
||||
@@ -54,18 +54,21 @@ use crate::{
|
||||
pub struct MemoryStore {
|
||||
sync_token: Arc<RwLock<Option<String>>>,
|
||||
filters: Arc<DashMap<String, String>>,
|
||||
account_data: Arc<DashMap<String, Raw<AnyGlobalAccountDataEvent>>>,
|
||||
account_data: Arc<DashMap<GlobalAccountDataEventType, Raw<AnyGlobalAccountDataEvent>>>,
|
||||
members: Arc<DashMap<Box<RoomId>, DashMap<Box<UserId>, MemberEvent>>>,
|
||||
profiles: Arc<DashMap<Box<RoomId>, DashMap<Box<UserId>, RoomMemberEventContent>>>,
|
||||
display_names: Arc<DashMap<Box<RoomId>, DashMap<String, BTreeSet<Box<UserId>>>>>,
|
||||
joined_user_ids: Arc<DashMap<Box<RoomId>, DashSet<Box<UserId>>>>,
|
||||
invited_user_ids: Arc<DashMap<Box<RoomId>, DashSet<Box<UserId>>>>,
|
||||
room_info: Arc<DashMap<Box<RoomId>, RoomInfo>>,
|
||||
room_state: Arc<DashMap<Box<RoomId>, DashMap<String, DashMap<String, Raw<AnySyncStateEvent>>>>>,
|
||||
room_account_data: Arc<DashMap<Box<RoomId>, DashMap<String, Raw<AnyRoomAccountDataEvent>>>>,
|
||||
room_state:
|
||||
Arc<DashMap<Box<RoomId>, DashMap<StateEventType, DashMap<String, Raw<AnySyncStateEvent>>>>>,
|
||||
room_account_data:
|
||||
Arc<DashMap<Box<RoomId>, DashMap<RoomAccountDataEventType, Raw<AnyRoomAccountDataEvent>>>>,
|
||||
stripped_room_infos: Arc<DashMap<Box<RoomId>, RoomInfo>>,
|
||||
stripped_room_state:
|
||||
Arc<DashMap<Box<RoomId>, DashMap<String, DashMap<String, Raw<AnyStrippedStateEvent>>>>>,
|
||||
stripped_room_state: Arc<
|
||||
DashMap<Box<RoomId>, DashMap<StateEventType, DashMap<String, Raw<AnyStrippedStateEvent>>>>,
|
||||
>,
|
||||
stripped_members: Arc<DashMap<Box<RoomId>, DashMap<Box<UserId>, StrippedMemberEvent>>>,
|
||||
presence: Arc<DashMap<Box<UserId>, Raw<PresenceEvent>>>,
|
||||
room_user_receipts:
|
||||
@@ -194,7 +197,7 @@ impl MemoryStore {
|
||||
}
|
||||
|
||||
for (event_type, event) in &changes.account_data {
|
||||
self.account_data.insert(event_type.to_string(), event.clone());
|
||||
self.account_data.insert(event_type.clone(), event.clone());
|
||||
}
|
||||
|
||||
for (room, events) in &changes.room_account_data {
|
||||
@@ -202,7 +205,7 @@ impl MemoryStore {
|
||||
self.room_account_data
|
||||
.entry(room.clone())
|
||||
.or_insert_with(DashMap::new)
|
||||
.insert(event_type.to_string(), event.clone());
|
||||
.insert(event_type.clone(), event.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +215,7 @@ impl MemoryStore {
|
||||
self.room_state
|
||||
.entry(room.clone())
|
||||
.or_insert_with(DashMap::new)
|
||||
.entry(event_type.to_owned())
|
||||
.entry(event_type.clone())
|
||||
.or_insert_with(DashMap::new)
|
||||
.insert(state_key.to_owned(), event.clone());
|
||||
}
|
||||
@@ -246,7 +249,7 @@ impl MemoryStore {
|
||||
self.stripped_room_state
|
||||
.entry(room.clone())
|
||||
.or_insert_with(DashMap::new)
|
||||
.entry(event_type.to_owned())
|
||||
.entry(event_type.clone())
|
||||
.or_insert_with(DashMap::new)
|
||||
.insert(state_key.to_owned(), event.clone());
|
||||
}
|
||||
@@ -357,9 +360,9 @@ impl MemoryStore {
|
||||
let mut room_version = None;
|
||||
for event in &timeline.events {
|
||||
// Redact events already in store only on sync response
|
||||
if let Ok(AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomRedaction(
|
||||
redaction,
|
||||
))) = event.event.deserialize()
|
||||
if let Ok(AnySyncRoomEvent::MessageLike(
|
||||
AnySyncMessageLikeEvent::RoomRedaction(redaction),
|
||||
)) = event.event.deserialize()
|
||||
{
|
||||
let pos = data.event_id_to_position.get(&redaction.redacts).copied();
|
||||
|
||||
@@ -412,9 +415,10 @@ impl MemoryStore {
|
||||
event_type: StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Option<Raw<AnySyncStateEvent>>> {
|
||||
Ok(self.room_state.get(room_id).and_then(|e| {
|
||||
e.get(event_type.as_ref()).and_then(|s| s.get(state_key).map(|e| e.clone()))
|
||||
}))
|
||||
Ok(self
|
||||
.room_state
|
||||
.get(room_id)
|
||||
.and_then(|e| e.get(&event_type).and_then(|s| s.get(state_key).map(|e| e.clone()))))
|
||||
}
|
||||
|
||||
async fn get_state_events(
|
||||
@@ -426,7 +430,7 @@ impl MemoryStore {
|
||||
.room_state
|
||||
.get(room_id)
|
||||
.and_then(|e| {
|
||||
e.get(event_type.as_ref()).map(|s| s.iter().map(|e| e.clone()).collect::<Vec<_>>())
|
||||
e.get(&event_type).map(|s| s.iter().map(|e| e.clone()).collect::<Vec<_>>())
|
||||
})
|
||||
.unwrap_or_default())
|
||||
}
|
||||
@@ -480,7 +484,7 @@ impl MemoryStore {
|
||||
&self,
|
||||
event_type: GlobalAccountDataEventType,
|
||||
) -> Result<Option<Raw<AnyGlobalAccountDataEvent>>> {
|
||||
Ok(self.account_data.get(event_type.as_ref()).map(|e| e.clone()))
|
||||
Ok(self.account_data.get(&event_type).map(|e| e.clone()))
|
||||
}
|
||||
|
||||
async fn get_room_account_data_event(
|
||||
@@ -488,10 +492,7 @@ impl MemoryStore {
|
||||
room_id: &RoomId,
|
||||
event_type: RoomAccountDataEventType,
|
||||
) -> Result<Option<Raw<AnyRoomAccountDataEvent>>> {
|
||||
Ok(self
|
||||
.room_account_data
|
||||
.get(room_id)
|
||||
.and_then(|m| m.get(event_type.as_ref()).map(|e| e.clone())))
|
||||
Ok(self.room_account_data.get(room_id).and_then(|m| m.get(&event_type).map(|e| e.clone())))
|
||||
}
|
||||
|
||||
async fn get_user_room_receipt_event(
|
||||
|
||||
@@ -43,8 +43,7 @@ use ruma::{
|
||||
receipt::{Receipt, ReceiptEventContent},
|
||||
room::member::RoomMemberEventContent,
|
||||
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
|
||||
AnySyncStateEvent, EventContent, GlobalAccountDataEventType, RoomAccountDataEventType,
|
||||
StateEventType,
|
||||
AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
|
||||
},
|
||||
receipt::ReceiptType,
|
||||
serde::Raw,
|
||||
@@ -81,7 +80,7 @@ pub enum StoreError {
|
||||
/// An error happened while deserializing a Matrix identifier, e.g. an user
|
||||
/// id.
|
||||
#[error(transparent)]
|
||||
Identifier(#[from] ruma::identifiers::Error),
|
||||
Identifier(#[from] ruma::IdParseError),
|
||||
/// The store is locked with a passphrase and an incorrect passphrase was
|
||||
/// given.
|
||||
#[error("The store failed to be unlocked")]
|
||||
@@ -479,7 +478,7 @@ pub struct StateChanges {
|
||||
/// associated user account.
|
||||
pub session: Option<Session>,
|
||||
/// A mapping of event type string to `AnyBasicEvent`.
|
||||
pub account_data: BTreeMap<String, Raw<AnyGlobalAccountDataEvent>>,
|
||||
pub account_data: BTreeMap<GlobalAccountDataEventType, Raw<AnyGlobalAccountDataEvent>>,
|
||||
/// A mapping of `UserId` to `PresenceEvent`.
|
||||
pub presence: BTreeMap<Box<UserId>, Raw<PresenceEvent>>,
|
||||
|
||||
@@ -492,9 +491,11 @@ pub struct StateChanges {
|
||||
/// A mapping of `RoomId` to a map of event type string to a state key and
|
||||
/// `AnySyncStateEvent`.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub state: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeMap<String, Raw<AnySyncStateEvent>>>>,
|
||||
pub state:
|
||||
BTreeMap<Box<RoomId>, BTreeMap<StateEventType, BTreeMap<String, Raw<AnySyncStateEvent>>>>,
|
||||
/// A mapping of `RoomId` to a map of event type string to `AnyBasicEvent`.
|
||||
pub room_account_data: BTreeMap<Box<RoomId>, BTreeMap<String, Raw<AnyRoomAccountDataEvent>>>,
|
||||
pub room_account_data:
|
||||
BTreeMap<Box<RoomId>, BTreeMap<RoomAccountDataEventType, Raw<AnyRoomAccountDataEvent>>>,
|
||||
/// A map of `RoomId` to `RoomInfo`.
|
||||
pub room_infos: BTreeMap<Box<RoomId>, RoomInfo>,
|
||||
/// A map of `RoomId` to `ReceiptEventContent`.
|
||||
@@ -503,8 +504,10 @@ pub struct StateChanges {
|
||||
/// A mapping of `RoomId` to a map of event type to a map of state key to
|
||||
/// `AnyStrippedStateEvent`.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub stripped_state:
|
||||
BTreeMap<Box<RoomId>, BTreeMap<String, BTreeMap<String, Raw<AnyStrippedStateEvent>>>>,
|
||||
pub stripped_state: BTreeMap<
|
||||
Box<RoomId>,
|
||||
BTreeMap<StateEventType, BTreeMap<String, Raw<AnyStrippedStateEvent>>>,
|
||||
>,
|
||||
/// A mapping of `RoomId` to a map of users and their `StrippedMemberEvent`.
|
||||
pub stripped_members: BTreeMap<Box<RoomId>, BTreeMap<Box<UserId>, StrippedMemberEvent>>,
|
||||
/// A map of `RoomId` to `RoomInfo` for stripped rooms (e.g. for invites or
|
||||
@@ -547,7 +550,7 @@ impl StateChanges {
|
||||
event: AnyGlobalAccountDataEvent,
|
||||
raw_event: Raw<AnyGlobalAccountDataEvent>,
|
||||
) {
|
||||
self.account_data.insert(event.content().event_type().to_owned(), raw_event);
|
||||
self.account_data.insert(event.event_type(), raw_event);
|
||||
}
|
||||
|
||||
/// Update the `StateChanges` struct with the given room with a new
|
||||
@@ -561,7 +564,7 @@ impl StateChanges {
|
||||
self.room_account_data
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(event.content().event_type().to_owned(), raw_event);
|
||||
.insert(event.event_type(), raw_event);
|
||||
}
|
||||
|
||||
/// Update the `StateChanges` struct with the given room with a new
|
||||
@@ -586,7 +589,7 @@ impl StateChanges {
|
||||
self.state
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.entry(event.content().event_type().to_owned())
|
||||
.entry(event.event_type())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(event.state_key().to_owned(), raw_event);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1.50"
|
||||
ruma = { version = "0.5.0", features = ["client-api-c"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "deea762b8", features = ["client-api-c"] }
|
||||
serde = "1.0.126"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
||||
@@ -12,7 +12,7 @@ use ruma::{
|
||||
room::member::{
|
||||
RoomMemberEvent, RoomMemberEventContent, StrippedRoomMemberEvent, SyncRoomMemberEvent,
|
||||
},
|
||||
AnyRoomEvent, AnySyncRoomEvent, Unsigned,
|
||||
AnyRoomEvent, AnySyncRoomEvent, StateUnsigned,
|
||||
},
|
||||
serde::Raw,
|
||||
DeviceId, DeviceKeyAlgorithm, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
@@ -301,21 +301,19 @@ pub struct MemberEvent {
|
||||
pub content: RoomMemberEventContent,
|
||||
pub event_id: Box<EventId>,
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
pub prev_content: Option<RoomMemberEventContent>,
|
||||
pub sender: Box<UserId>,
|
||||
pub state_key: Box<UserId>,
|
||||
pub unsigned: Unsigned,
|
||||
pub unsigned: StateUnsigned<RoomMemberEventContent>,
|
||||
}
|
||||
|
||||
impl TryFrom<SyncRoomMemberEvent> for MemberEvent {
|
||||
type Error = ruma::identifiers::Error;
|
||||
type Error = ruma::IdParseError;
|
||||
|
||||
fn try_from(event: SyncRoomMemberEvent) -> Result<Self, Self::Error> {
|
||||
Ok(MemberEvent {
|
||||
content: event.content,
|
||||
event_id: event.event_id,
|
||||
origin_server_ts: event.origin_server_ts,
|
||||
prev_content: event.prev_content,
|
||||
sender: event.sender,
|
||||
state_key: event.state_key.try_into()?,
|
||||
unsigned: event.unsigned,
|
||||
@@ -324,14 +322,13 @@ impl TryFrom<SyncRoomMemberEvent> for MemberEvent {
|
||||
}
|
||||
|
||||
impl TryFrom<RoomMemberEvent> for MemberEvent {
|
||||
type Error = ruma::identifiers::Error;
|
||||
type Error = ruma::IdParseError;
|
||||
|
||||
fn try_from(event: RoomMemberEvent) -> Result<Self, Self::Error> {
|
||||
Ok(MemberEvent {
|
||||
content: event.content,
|
||||
event_id: event.event_id,
|
||||
origin_server_ts: event.origin_server_ts,
|
||||
prev_content: event.prev_content,
|
||||
sender: event.sender,
|
||||
state_key: event.state_key.try_into()?,
|
||||
unsigned: event.unsigned,
|
||||
@@ -347,7 +344,6 @@ impl From<MemberEvent> for SyncRoomMemberEvent {
|
||||
sender: other.sender,
|
||||
origin_server_ts: other.origin_server_ts,
|
||||
state_key: other.state_key.to_string(),
|
||||
prev_content: other.prev_content,
|
||||
unsigned: other.unsigned,
|
||||
}
|
||||
}
|
||||
@@ -362,7 +358,7 @@ pub struct StrippedMemberEvent {
|
||||
}
|
||||
|
||||
impl TryFrom<StrippedRoomMemberEvent> for StrippedMemberEvent {
|
||||
type Error = ruma::identifiers::Error;
|
||||
type Error = ruma::IdParseError;
|
||||
|
||||
fn try_from(event: StrippedRoomMemberEvent) -> Result<Self, Self::Error> {
|
||||
Ok(StrippedMemberEvent {
|
||||
@@ -399,25 +395,27 @@ mod test {
|
||||
use ruma::{
|
||||
event_id,
|
||||
events::{
|
||||
room::message::RoomMessageEventContent, AnyMessageEvent, AnySyncMessageEvent,
|
||||
AnySyncRoomEvent, MessageEvent,
|
||||
room::message::RoomMessageEventContent, AnyMessageLikeEvent, AnySyncMessageLikeEvent,
|
||||
AnySyncRoomEvent, MessageLikeEvent, MessageLikeUnsigned,
|
||||
},
|
||||
room_id, user_id, MilliSecondsSinceUnixEpoch,
|
||||
room_id,
|
||||
serde::Raw,
|
||||
user_id, MilliSecondsSinceUnixEpoch,
|
||||
};
|
||||
|
||||
use super::{Raw, RoomEvent, SyncRoomEvent, Unsigned};
|
||||
use super::{RoomEvent, SyncRoomEvent};
|
||||
|
||||
#[test]
|
||||
fn room_event_to_sync_room_event() {
|
||||
let content = RoomMessageEventContent::text_plain("foobar");
|
||||
|
||||
let event = MessageEvent {
|
||||
let event = MessageLikeEvent {
|
||||
content,
|
||||
event_id: event_id!("$xxxxx:example.org").to_owned(),
|
||||
room_id: room_id!("!someroom:example.com").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||
sender: user_id!("@carl:example.com").to_owned(),
|
||||
unsigned: Unsigned::default(),
|
||||
unsigned: MessageLikeUnsigned::default(),
|
||||
};
|
||||
|
||||
let room_event =
|
||||
@@ -427,8 +425,8 @@ mod test {
|
||||
|
||||
let converted_event: AnySyncRoomEvent = converted_room_event.event.deserialize().unwrap();
|
||||
|
||||
let event: AnyMessageEvent = event.into();
|
||||
let sync_event: AnySyncMessageEvent = event.into();
|
||||
let event: AnyMessageLikeEvent = event.into();
|
||||
let sync_event: AnySyncMessageLikeEvent = event.into();
|
||||
let sync_event: AnySyncRoomEvent = sync_event.into();
|
||||
|
||||
// There is no PartialEq implementation for AnySyncRoomEvent, so we
|
||||
|
||||
@@ -60,7 +60,8 @@ rev = "16fb254aa3325c61ef949314c81c35f91d0664e1"
|
||||
features = ["js"]
|
||||
|
||||
[dependencies.ruma]
|
||||
version = "0.5.0"
|
||||
git = "https://github.com/ruma/ruma"
|
||||
rev = "deea762b8"
|
||||
features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"]
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use ruma::{identifiers::Error as IdentifierError, DeviceId, RoomId, UserId};
|
||||
use ruma::{DeviceId, IdParseError, RoomId, UserId};
|
||||
use serde_json::Error as SerdeError;
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -150,7 +150,7 @@ pub enum SignatureError {
|
||||
|
||||
/// The ID of the signing key isn't a valid key ID.
|
||||
#[error("the ID of the signing key is invalid")]
|
||||
InvalidKeyId(#[from] IdentifierError),
|
||||
InvalidKeyId(#[from] IdParseError),
|
||||
|
||||
/// The signing key that should create or check a signature is missing.
|
||||
#[error("the signing key is missing from the object that signed the message")]
|
||||
|
||||
@@ -41,7 +41,7 @@ use ruma::{
|
||||
},
|
||||
room_key::ToDeviceRoomKeyEvent,
|
||||
secret::request::SecretName,
|
||||
AnyRoomEvent, AnyToDeviceEvent, MessageEventContent,
|
||||
AnyRoomEvent, AnyToDeviceEvent, EventContent, MessageLikeEventType,
|
||||
},
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, RoomId, TransactionId,
|
||||
UInt, UserId,
|
||||
@@ -682,12 +682,12 @@ impl OlmMachine {
|
||||
pub async fn encrypt(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
content: impl MessageEventContent,
|
||||
content: impl EventContent<EventType = MessageLikeEventType>,
|
||||
) -> MegolmResult<RoomEncryptedEventContent> {
|
||||
let event_type = content.event_type();
|
||||
let event_type = content.event_type().to_string();
|
||||
let content = serde_json::to_value(&content)?;
|
||||
|
||||
self.group_session_manager.encrypt(room_id, content, event_type).await
|
||||
self.group_session_manager.encrypt(room_id, content, &event_type).await
|
||||
}
|
||||
|
||||
/// Encrypt a json [`Value`] content for the given room.
|
||||
@@ -774,7 +774,7 @@ impl OlmMachine {
|
||||
trace!(
|
||||
sender = decrypted.sender.as_str(),
|
||||
sender_key = decrypted.sender_key.as_str(),
|
||||
event_type = event.event_type(),
|
||||
event_type = %event.event_type(),
|
||||
"Received a decrypted to-device event"
|
||||
);
|
||||
|
||||
@@ -923,7 +923,7 @@ impl OlmMachine {
|
||||
|
||||
trace!(
|
||||
sender = event.sender().as_str(),
|
||||
event_type = event.event_type(),
|
||||
event_type = %event.event_type(),
|
||||
"Received a to-device event"
|
||||
);
|
||||
|
||||
@@ -1085,7 +1085,7 @@ impl OlmMachine {
|
||||
"Successfully decrypted a room event"
|
||||
);
|
||||
|
||||
if let AnyRoomEvent::Message(e) = e {
|
||||
if let AnyRoomEvent::MessageLike(e) = e {
|
||||
self.verification_machine.receive_any_event(&e).await?;
|
||||
}
|
||||
}
|
||||
@@ -1558,8 +1558,9 @@ pub(crate) mod test {
|
||||
encrypted::ToDeviceRoomEncryptedEventContent,
|
||||
message::{MessageType, RoomMessageEventContent},
|
||||
},
|
||||
AnyMessageEvent, AnyMessageEventContent, AnyRoomEvent, AnyToDeviceEvent,
|
||||
AnyToDeviceEventContent, MessageEvent, SyncMessageEvent, ToDeviceEvent, Unsigned,
|
||||
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyRoomEvent, AnyToDeviceEvent,
|
||||
AnyToDeviceEventContent, MessageLikeEvent, MessageLikeUnsigned, SyncMessageLikeEvent,
|
||||
ToDeviceEvent,
|
||||
},
|
||||
room_id,
|
||||
serde::Raw,
|
||||
@@ -1975,22 +1976,22 @@ pub(crate) mod test {
|
||||
let content = RoomMessageEventContent::text_plain(plaintext);
|
||||
|
||||
let encrypted_content = alice
|
||||
.encrypt(room_id, AnyMessageEventContent::RoomMessage(content.clone()))
|
||||
.encrypt(room_id, AnyMessageLikeEventContent::RoomMessage(content.clone()))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let event = SyncMessageEvent {
|
||||
let event = SyncMessageLikeEvent {
|
||||
event_id: event_id!("$xxxxx:example.org").to_owned(),
|
||||
origin_server_ts: milli_seconds_since_unix_epoch(),
|
||||
sender: alice.user_id().to_owned(),
|
||||
content: encrypted_content,
|
||||
unsigned: Unsigned::default(),
|
||||
unsigned: MessageLikeUnsigned::default(),
|
||||
};
|
||||
|
||||
let decrypted_event =
|
||||
bob.decrypt_room_event(&event, room_id).await.unwrap().event.deserialize().unwrap();
|
||||
|
||||
if let AnyRoomEvent::Message(AnyMessageEvent::RoomMessage(MessageEvent {
|
||||
if let AnyRoomEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(MessageLikeEvent {
|
||||
sender,
|
||||
content,
|
||||
..
|
||||
|
||||
@@ -66,7 +66,7 @@ pub(crate) mod test {
|
||||
events::{
|
||||
forwarded_room_key::ToDeviceForwardedRoomKeyEventContent,
|
||||
room::message::{Relation, Replacement, RoomMessageEventContent},
|
||||
AnyMessageEvent, AnyRoomEvent, AnySyncMessageEvent, AnySyncRoomEvent,
|
||||
AnyMessageLikeEvent, AnyRoomEvent, AnySyncMessageLikeEvent, AnySyncRoomEvent,
|
||||
},
|
||||
room_id, user_id, DeviceId, UserId,
|
||||
};
|
||||
@@ -246,7 +246,9 @@ pub(crate) mod test {
|
||||
let event: AnySyncRoomEvent = serde_json::from_str(&event).unwrap();
|
||||
|
||||
let event =
|
||||
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomEncrypted(event)) = event {
|
||||
if let AnySyncRoomEvent::MessageLike(AnySyncMessageLikeEvent::RoomEncrypted(event)) =
|
||||
event
|
||||
{
|
||||
event
|
||||
} else {
|
||||
panic!("Invalid event type")
|
||||
@@ -254,7 +256,7 @@ pub(crate) mod test {
|
||||
|
||||
let decrypted = inbound.decrypt(&event).await.unwrap().0;
|
||||
|
||||
if let AnyRoomEvent::Message(AnyMessageEvent::RoomMessage(e)) =
|
||||
if let AnyRoomEvent::MessageLike(AnyMessageLikeEvent::RoomMessage(e)) =
|
||||
decrypted.deserialize().unwrap()
|
||||
{
|
||||
assert_matches!(e.content.relates_to, Some(Relation::Replacement(_)));
|
||||
|
||||
@@ -29,7 +29,9 @@ use ruma::{
|
||||
message::send_message_event::v3::Response as RoomMessageResponse,
|
||||
to_device::send_event_to_device::v3::Response as ToDeviceResponse,
|
||||
},
|
||||
events::{AnyMessageEventContent, AnyToDeviceEventContent, EventContent, ToDeviceEventType},
|
||||
events::{
|
||||
AnyMessageLikeEventContent, AnyToDeviceEventContent, EventContent, ToDeviceEventType,
|
||||
},
|
||||
serde::Raw,
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
DeviceId, RoomId, TransactionId, UserId,
|
||||
@@ -88,7 +90,7 @@ impl ToDeviceRequest {
|
||||
if recipient_devices.is_empty() {
|
||||
Self::new(recipient, DeviceIdOrAllDevices::AllDevices, content)
|
||||
} else {
|
||||
let event_type = content.event_type().into();
|
||||
let event_type = content.event_type();
|
||||
let device_messages = recipient_devices
|
||||
.into_iter()
|
||||
.map(|d| {
|
||||
@@ -109,7 +111,7 @@ impl ToDeviceRequest {
|
||||
content: AnyToDeviceEventContent,
|
||||
txn_id: Box<TransactionId>,
|
||||
) -> Self {
|
||||
let event_type = ToDeviceEventType::from(content.event_type());
|
||||
let event_type = content.event_type();
|
||||
let raw_content = Raw::new(&content).expect("Failed to serialize to-device event");
|
||||
|
||||
let user_messages = iter::once((recipient_device.into(), raw_content)).collect();
|
||||
@@ -365,7 +367,7 @@ pub struct RoomMessageRequest {
|
||||
pub txn_id: Box<TransactionId>,
|
||||
|
||||
/// The event content to send.
|
||||
pub content: AnyMessageEventContent,
|
||||
pub content: AnyMessageLikeEventContent,
|
||||
}
|
||||
|
||||
/// A request that will back up a batch of room keys to the server.
|
||||
|
||||
@@ -58,8 +58,7 @@ use matrix_sdk_common::{async_trait, locks::Mutex, AsyncTraitDeps};
|
||||
pub use memorystore::MemoryStore;
|
||||
pub use pickle_key::{EncryptedPickleKey, PickleKey};
|
||||
use ruma::{
|
||||
events::secret::request::SecretName, identifiers::Error as IdentifierValidationError, DeviceId,
|
||||
RoomId, TransactionId, UserId,
|
||||
events::secret::request::SecretName, DeviceId, IdParseError, RoomId, TransactionId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Error as SerdeError;
|
||||
@@ -595,7 +594,7 @@ pub enum CryptoStoreError {
|
||||
|
||||
/// A Matrix identifier failed to be validated.
|
||||
#[error(transparent)]
|
||||
IdentifierValidation(#[from] IdentifierValidationError),
|
||||
IdentifierValidation(#[from] IdParseError),
|
||||
|
||||
/// The store failed to (de)serialize a data type.
|
||||
#[error(transparent)]
|
||||
|
||||
@@ -40,7 +40,7 @@ use ruma::{
|
||||
VerificationMethod,
|
||||
},
|
||||
room::message::{KeyVerificationRequestEventContent, MessageType},
|
||||
AnyMessageEvent, AnyMessageEventContent, AnyToDeviceEvent, AnyToDeviceEventContent,
|
||||
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyToDeviceEvent, AnyToDeviceEventContent,
|
||||
},
|
||||
serde::{Base64, CanonicalJsonValue},
|
||||
DeviceId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
@@ -50,7 +50,7 @@ use super::FlowId;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AnyEvent<'a> {
|
||||
Room(&'a AnyMessageEvent),
|
||||
Room(&'a AnyMessageLikeEvent),
|
||||
ToDevice(&'a AnyToDeviceEvent),
|
||||
}
|
||||
|
||||
@@ -79,37 +79,41 @@ impl AnyEvent<'_> {
|
||||
pub fn verification_content(&self) -> Option<AnyVerificationContent<'_>> {
|
||||
match self {
|
||||
AnyEvent::Room(e) => match e {
|
||||
AnyMessageEvent::CallAnswer(_)
|
||||
| AnyMessageEvent::CallInvite(_)
|
||||
| AnyMessageEvent::CallHangup(_)
|
||||
| AnyMessageEvent::CallCandidates(_)
|
||||
| AnyMessageEvent::Reaction(_)
|
||||
| AnyMessageEvent::RoomEncrypted(_)
|
||||
| AnyMessageEvent::RoomMessageFeedback(_)
|
||||
| AnyMessageEvent::RoomRedaction(_)
|
||||
| AnyMessageEvent::Sticker(_) => None,
|
||||
AnyMessageEvent::RoomMessage(m) => {
|
||||
AnyMessageLikeEvent::CallAnswer(_)
|
||||
| AnyMessageLikeEvent::CallInvite(_)
|
||||
| AnyMessageLikeEvent::CallHangup(_)
|
||||
| AnyMessageLikeEvent::CallCandidates(_)
|
||||
| AnyMessageLikeEvent::Reaction(_)
|
||||
| AnyMessageLikeEvent::RoomEncrypted(_)
|
||||
| AnyMessageLikeEvent::RoomMessageFeedback(_)
|
||||
| AnyMessageLikeEvent::RoomRedaction(_)
|
||||
| AnyMessageLikeEvent::Sticker(_) => None,
|
||||
AnyMessageLikeEvent::RoomMessage(m) => {
|
||||
if let MessageType::VerificationRequest(v) = &m.content.msgtype {
|
||||
Some(RequestContent::from(v).into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationReady(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationReady(e) => {
|
||||
Some(ReadyContent::from(&e.content).into())
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationStart(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationStart(e) => {
|
||||
Some(StartContent::from(&e.content).into())
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationCancel(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationCancel(e) => {
|
||||
Some(CancelContent::from(&e.content).into())
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationAccept(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationAccept(e) => {
|
||||
Some(AcceptContent::from(&e.content).into())
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationKey(e) => Some(KeyContent::from(&e.content).into()),
|
||||
AnyMessageEvent::KeyVerificationMac(e) => Some(MacContent::from(&e.content).into()),
|
||||
AnyMessageEvent::KeyVerificationDone(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationKey(e) => {
|
||||
Some(KeyContent::from(&e.content).into())
|
||||
}
|
||||
AnyMessageLikeEvent::KeyVerificationMac(e) => {
|
||||
Some(MacContent::from(&e.content).into())
|
||||
}
|
||||
AnyMessageLikeEvent::KeyVerificationDone(e) => {
|
||||
Some(DoneContent::from(&e.content).into())
|
||||
}
|
||||
_ => None,
|
||||
@@ -150,8 +154,8 @@ impl AnyEvent<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a AnyMessageEvent> for AnyEvent<'a> {
|
||||
fn from(e: &'a AnyMessageEvent) -> Self {
|
||||
impl<'a> From<&'a AnyMessageLikeEvent> for AnyEvent<'a> {
|
||||
fn from(e: &'a AnyMessageLikeEvent) -> Self {
|
||||
Self::Room(e)
|
||||
}
|
||||
}
|
||||
@@ -173,40 +177,40 @@ impl TryFrom<&AnyEvent<'_>> for FlowId {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&AnyMessageEvent> for FlowId {
|
||||
impl TryFrom<&AnyMessageLikeEvent> for FlowId {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: &AnyMessageEvent) -> Result<Self, Self::Error> {
|
||||
fn try_from(value: &AnyMessageLikeEvent) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
AnyMessageEvent::CallAnswer(_)
|
||||
| AnyMessageEvent::CallInvite(_)
|
||||
| AnyMessageEvent::CallHangup(_)
|
||||
| AnyMessageEvent::CallCandidates(_)
|
||||
| AnyMessageEvent::Reaction(_)
|
||||
| AnyMessageEvent::RoomEncrypted(_)
|
||||
| AnyMessageEvent::RoomMessageFeedback(_)
|
||||
| AnyMessageEvent::RoomRedaction(_)
|
||||
| AnyMessageEvent::Sticker(_) => Err(()),
|
||||
AnyMessageEvent::KeyVerificationReady(e) => {
|
||||
AnyMessageLikeEvent::CallAnswer(_)
|
||||
| AnyMessageLikeEvent::CallInvite(_)
|
||||
| AnyMessageLikeEvent::CallHangup(_)
|
||||
| AnyMessageLikeEvent::CallCandidates(_)
|
||||
| AnyMessageLikeEvent::Reaction(_)
|
||||
| AnyMessageLikeEvent::RoomEncrypted(_)
|
||||
| AnyMessageLikeEvent::RoomMessageFeedback(_)
|
||||
| AnyMessageLikeEvent::RoomRedaction(_)
|
||||
| AnyMessageLikeEvent::Sticker(_) => Err(()),
|
||||
AnyMessageLikeEvent::KeyVerificationReady(e) => {
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::RoomMessage(e) => Ok(FlowId::from((&*e.room_id, &*e.event_id))),
|
||||
AnyMessageEvent::KeyVerificationStart(e) => {
|
||||
AnyMessageLikeEvent::RoomMessage(e) => Ok(FlowId::from((&*e.room_id, &*e.event_id))),
|
||||
AnyMessageLikeEvent::KeyVerificationStart(e) => {
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationCancel(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationCancel(e) => {
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationAccept(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationAccept(e) => {
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationKey(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationKey(e) => {
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationMac(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationMac(e) => {
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationDone(e) => {
|
||||
AnyMessageLikeEvent::KeyVerificationDone(e) => {
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
_ => Err(()),
|
||||
@@ -363,7 +367,7 @@ macro_rules! try_from_outgoing_content {
|
||||
fn try_from(value: &'a OutgoingContent) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
OutgoingContent::Room(_, c) => {
|
||||
if let AnyMessageEventContent::$enum_variant(c) = c {
|
||||
if let AnyMessageLikeEventContent::$enum_variant(c) = c {
|
||||
Ok(Self::Room(c))
|
||||
} else {
|
||||
Err(())
|
||||
@@ -396,7 +400,7 @@ impl<'a> TryFrom<&'a OutgoingContent> for RequestContent<'a> {
|
||||
fn try_from(value: &'a OutgoingContent) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
OutgoingContent::Room(_, c) => {
|
||||
if let AnyMessageEventContent::RoomMessage(m) = c {
|
||||
if let AnyMessageLikeEventContent::RoomMessage(m) = c {
|
||||
if let MessageType::VerificationRequest(c) = &m.msgtype {
|
||||
Ok(Self::Room(c))
|
||||
} else {
|
||||
@@ -675,7 +679,7 @@ impl OwnedAcceptContent {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OutgoingContent {
|
||||
Room(Box<RoomId>, AnyMessageEventContent),
|
||||
Room(Box<RoomId>, AnyMessageLikeEventContent),
|
||||
ToDevice(AnyToDeviceEventContent),
|
||||
}
|
||||
|
||||
@@ -683,7 +687,7 @@ impl From<OwnedStartContent> for OutgoingContent {
|
||||
fn from(content: OwnedStartContent) -> Self {
|
||||
match content {
|
||||
OwnedStartContent::Room(r, c) => {
|
||||
(r, AnyMessageEventContent::KeyVerificationStart(c)).into()
|
||||
(r, AnyMessageLikeEventContent::KeyVerificationStart(c)).into()
|
||||
}
|
||||
OwnedStartContent::ToDevice(c) => {
|
||||
AnyToDeviceEventContent::KeyVerificationStart(c).into()
|
||||
@@ -698,8 +702,8 @@ impl From<AnyToDeviceEventContent> for OutgoingContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(Box<RoomId>, AnyMessageEventContent)> for OutgoingContent {
|
||||
fn from(content: (Box<RoomId>, AnyMessageEventContent)) -> Self {
|
||||
impl From<(Box<RoomId>, AnyMessageLikeEventContent)> for OutgoingContent {
|
||||
fn from(content: (Box<RoomId>, AnyMessageLikeEventContent)) -> Self {
|
||||
OutgoingContent::Room(content.0, content.1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ use ruma::{
|
||||
},
|
||||
Relation,
|
||||
},
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
AnyMessageLikeEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
DeviceId, DeviceKeyId, EventId, RoomId, TransactionId, UserId,
|
||||
};
|
||||
@@ -256,9 +256,9 @@ impl Done {
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.to_owned(),
|
||||
AnyMessageEventContent::KeyVerificationDone(KeyVerificationDoneEventContent::new(
|
||||
Relation::new(e.to_owned()),
|
||||
)),
|
||||
AnyMessageLikeEventContent::KeyVerificationDone(
|
||||
KeyVerificationDoneEventContent::new(Relation::new(e.to_owned())),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
@@ -341,7 +341,7 @@ impl Cancelled {
|
||||
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.clone(),
|
||||
AnyMessageEventContent::KeyVerificationCancel(
|
||||
AnyMessageLikeEventContent::KeyVerificationCancel(
|
||||
KeyVerificationCancelEventContent::new(
|
||||
self.reason.to_owned(),
|
||||
self.cancel_code.clone(),
|
||||
|
||||
@@ -31,7 +31,7 @@ use ruma::{
|
||||
},
|
||||
Relation,
|
||||
},
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
AnyMessageLikeEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
serde::Base64,
|
||||
DeviceId, RoomId, TransactionId, UserId,
|
||||
@@ -763,9 +763,9 @@ impl QrState<Confirmed> {
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.to_owned(),
|
||||
AnyMessageEventContent::KeyVerificationDone(KeyVerificationDoneEventContent::new(
|
||||
Relation::new(e.to_owned()),
|
||||
)),
|
||||
AnyMessageLikeEventContent::KeyVerificationDone(
|
||||
KeyVerificationDoneEventContent::new(Relation::new(e.to_owned())),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use ruma::{
|
||||
Relation, VerificationMethod,
|
||||
},
|
||||
room::message::KeyVerificationRequestEventContent,
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
AnyMessageLikeEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
DeviceId, RoomId, TransactionId, UserId,
|
||||
@@ -912,7 +912,7 @@ impl RequestState<Requested> {
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.to_owned(),
|
||||
AnyMessageEventContent::KeyVerificationReady(
|
||||
AnyMessageLikeEventContent::KeyVerificationReady(
|
||||
KeyVerificationReadyEventContent::new(
|
||||
state.store.account.device_id().to_owned(),
|
||||
methods,
|
||||
|
||||
@@ -21,7 +21,7 @@ use ruma::{
|
||||
mac::{KeyVerificationMacEventContent, ToDeviceKeyVerificationMacEventContent},
|
||||
Relation,
|
||||
},
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
AnyMessageLikeEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
serde::Base64,
|
||||
DeviceKeyAlgorithm, DeviceKeyId, UserId,
|
||||
@@ -347,15 +347,15 @@ pub fn get_mac_content(sas: &EstablishedSas, ids: &SasIds, flow_id: &FlowId) ->
|
||||
ToDeviceKeyVerificationMacEventContent::new(s.clone(), mac, keys),
|
||||
)
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.clone(),
|
||||
AnyMessageEventContent::KeyVerificationMac(KeyVerificationMacEventContent::new(
|
||||
mac,
|
||||
keys,
|
||||
Relation::new(e.clone()),
|
||||
)),
|
||||
)
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => {
|
||||
(
|
||||
r.clone(),
|
||||
AnyMessageLikeEventContent::KeyVerificationMac(
|
||||
KeyVerificationMacEventContent::new(mac, keys, Relation::new(e.clone())),
|
||||
),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ use ruma::{
|
||||
api::client::keys::upload_signatures::v3::Request as SignatureUploadRequest,
|
||||
events::{
|
||||
key::verification::{cancel::CancelCode, ShortAuthenticationString},
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
AnyMessageLikeEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
DeviceId, EventId, RoomId, TransactionId, UserId,
|
||||
};
|
||||
@@ -336,7 +336,7 @@ impl Sas {
|
||||
OwnedAcceptContent::Room(room_id, content) => RoomMessageRequest {
|
||||
room_id,
|
||||
txn_id: TransactionId::new(),
|
||||
content: AnyMessageEventContent::KeyVerificationAccept(content),
|
||||
content: AnyMessageLikeEventContent::KeyVerificationAccept(content),
|
||||
}
|
||||
.into(),
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ use ruma::{
|
||||
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
|
||||
ShortAuthenticationString, VerificationMethod,
|
||||
},
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
AnyMessageLikeEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
serde::Base64,
|
||||
DeviceId, EventId, RoomId, TransactionId, UserId,
|
||||
@@ -848,10 +848,12 @@ impl SasState<Accepted> {
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.clone(),
|
||||
AnyMessageEventContent::KeyVerificationKey(KeyVerificationKeyEventContent::new(
|
||||
Base64::new(self.our_public_key.to_vec()),
|
||||
Relation::new(e.clone()),
|
||||
)),
|
||||
AnyMessageLikeEventContent::KeyVerificationKey(
|
||||
KeyVerificationKeyEventContent::new(
|
||||
Base64::new(self.our_public_key.to_vec()),
|
||||
Relation::new(e.clone()),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
@@ -874,10 +876,12 @@ impl SasState<KeyReceived> {
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.clone(),
|
||||
AnyMessageEventContent::KeyVerificationKey(KeyVerificationKeyEventContent::new(
|
||||
Base64::new(self.our_public_key.to_vec()),
|
||||
Relation::new(e.clone()),
|
||||
)),
|
||||
AnyMessageLikeEventContent::KeyVerificationKey(
|
||||
KeyVerificationKeyEventContent::new(
|
||||
Base64::new(self.our_public_key.to_vec()),
|
||||
Relation::new(e.clone()),
|
||||
),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
@@ -1177,9 +1181,9 @@ impl SasState<WaitingForDone> {
|
||||
.into(),
|
||||
FlowId::InRoom(r, e) => (
|
||||
r.clone(),
|
||||
AnyMessageEventContent::KeyVerificationDone(KeyVerificationDoneEventContent::new(
|
||||
Relation::new(e.clone()),
|
||||
)),
|
||||
AnyMessageLikeEventContent::KeyVerificationDone(
|
||||
KeyVerificationDoneEventContent::new(Relation::new(e.clone())),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
use matrix_sdk_base::ruma::events::StateEventType;
|
||||
use matrix_sdk_base::ruma::events::{GlobalAccountDataEventType, StateEventType};
|
||||
use matrix_sdk_common::ruma::{
|
||||
receipt::ReceiptType, DeviceId, EventId, MxcUri, RoomId, TransactionId, UserId,
|
||||
};
|
||||
@@ -135,9 +135,15 @@ impl SafeEncode for TransactionId {
|
||||
}
|
||||
}
|
||||
|
||||
impl SafeEncode for GlobalAccountDataEventType {
|
||||
fn as_encoded_string(&self) -> String {
|
||||
self.to_string().as_encoded_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl SafeEncode for StateEventType {
|
||||
fn as_encoded_string(&self) -> String {
|
||||
self.as_str().as_encoded_string()
|
||||
self.to_string().as_encoded_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ use matrix_sdk_common::{
|
||||
presence::PresenceEvent,
|
||||
receipt::Receipt,
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageEvent,
|
||||
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageLikeEvent,
|
||||
AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType,
|
||||
RoomAccountDataEventType, StateEventType,
|
||||
},
|
||||
@@ -388,7 +388,7 @@ impl IndexeddbStore {
|
||||
let store = tx.object_store(KEYS::ROOM_ACCOUNT_DATA)?;
|
||||
for (room, events) in &changes.room_account_data {
|
||||
for (event_type, event) in events {
|
||||
let key = (room, event_type).encode();
|
||||
let key = (room, event_type.to_string().as_str()).encode();
|
||||
store.put_key_val(&key, &self.serialize_event(&event)?)?;
|
||||
}
|
||||
}
|
||||
@@ -637,9 +637,9 @@ impl IndexeddbStore {
|
||||
});
|
||||
for event in &timeline.events {
|
||||
// Redact events already in store only on sync response
|
||||
if let Ok(AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomRedaction(
|
||||
redaction,
|
||||
))) = event.event.deserialize()
|
||||
if let Ok(AnySyncRoomEvent::MessageLike(
|
||||
AnySyncMessageLikeEvent::RoomRedaction(redaction),
|
||||
)) = event.event.deserialize()
|
||||
{
|
||||
let redacts_key = (room_id, &redaction.redacts).encode();
|
||||
if let Some(position_key) =
|
||||
@@ -866,7 +866,7 @@ impl IndexeddbStore {
|
||||
self.inner
|
||||
.transaction_on_one_with_mode(KEYS::ACCOUNT_DATA, IdbTransactionMode::Readonly)?
|
||||
.object_store(KEYS::ACCOUNT_DATA)?
|
||||
.get(&JsValue::from_str(event_type.as_str()))?
|
||||
.get(&JsValue::from_str(&event_type.to_string()))?
|
||||
.await?
|
||||
.map(|f| self.deserialize_event(f).map_err::<SerializationError, _>(|e| e))
|
||||
.transpose()
|
||||
@@ -880,7 +880,7 @@ impl IndexeddbStore {
|
||||
self.inner
|
||||
.transaction_on_one_with_mode(KEYS::ROOM_ACCOUNT_DATA, IdbTransactionMode::Readonly)?
|
||||
.object_store(KEYS::ROOM_ACCOUNT_DATA)?
|
||||
.get(&(room_id.as_str(), event_type.as_str()).encode())?
|
||||
.get(&(room_id.as_str(), &event_type.to_string()).encode())?
|
||||
.await?
|
||||
.map(|f| self.deserialize_event(f).map_err::<SerializationError, _>(|e| e))
|
||||
.transpose()
|
||||
@@ -938,7 +938,7 @@ impl IndexeddbStore {
|
||||
}
|
||||
|
||||
async fn add_media_content(&self, request: &MediaRequest, data: Vec<u8>) -> Result<()> {
|
||||
let key = (&request.media_type.unique_key(), &request.format.unique_key()).encode();
|
||||
let key = (&request.source.unique_key(), &request.format.unique_key()).encode();
|
||||
let tx =
|
||||
self.inner.transaction_on_one_with_mode(KEYS::MEDIA, IdbTransactionMode::Readwrite)?;
|
||||
|
||||
@@ -948,7 +948,7 @@ impl IndexeddbStore {
|
||||
}
|
||||
|
||||
async fn get_media_content(&self, request: &MediaRequest) -> Result<Option<Vec<u8>>> {
|
||||
let key = (&request.media_type.unique_key(), &request.format.unique_key()).encode();
|
||||
let key = (&request.source.unique_key(), &request.format.unique_key()).encode();
|
||||
self.inner
|
||||
.transaction_on_one_with_mode(KEYS::MEDIA, IdbTransactionMode::Readonly)?
|
||||
.object_store(KEYS::MEDIA)?
|
||||
@@ -992,7 +992,7 @@ impl IndexeddbStore {
|
||||
}
|
||||
|
||||
async fn remove_media_content(&self, request: &MediaRequest) -> Result<()> {
|
||||
let key = (&request.media_type.unique_key(), &request.format.unique_key()).encode();
|
||||
let key = (&request.source.unique_key(), &request.format.unique_key()).encode();
|
||||
let tx =
|
||||
self.inner.transaction_on_one_with_mode(KEYS::MEDIA, IdbTransactionMode::Readwrite)?;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ use matrix_sdk_common::{
|
||||
presence::PresenceEvent,
|
||||
receipt::Receipt,
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageEvent,
|
||||
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncMessageLikeEvent,
|
||||
AnySyncRoomEvent, AnySyncStateEvent, GlobalAccountDataEventType,
|
||||
RoomAccountDataEventType, StateEventType,
|
||||
},
|
||||
@@ -81,7 +81,7 @@ pub enum SledStoreError {
|
||||
#[error(transparent)]
|
||||
TransactionError(#[from] sled::Error),
|
||||
#[error(transparent)]
|
||||
Identifier(#[from] ruma::identifiers::Error),
|
||||
Identifier(#[from] ruma::IdParseError),
|
||||
#[error(transparent)]
|
||||
Task(#[from] tokio::task::JoinError),
|
||||
}
|
||||
@@ -194,19 +194,19 @@ impl EncodeKey for (&str, &str, &str, &str) {
|
||||
|
||||
impl EncodeKey for StateEventType {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
self.as_str().encode()
|
||||
self.to_string().encode()
|
||||
}
|
||||
}
|
||||
|
||||
impl EncodeKey for GlobalAccountDataEventType {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
self.as_str().encode()
|
||||
self.to_string().encode()
|
||||
}
|
||||
}
|
||||
|
||||
/* impl EncodeKey for RoomAccountDataEventType {
|
||||
fn encode(&self) -> Vec<u8> {
|
||||
self.as_str().encode()
|
||||
self.to_string().encode()
|
||||
}
|
||||
} */
|
||||
|
||||
@@ -534,7 +534,7 @@ impl SledStore {
|
||||
for (room, events) in &changes.room_account_data {
|
||||
for (event_type, event) in events {
|
||||
room_account_data.insert(
|
||||
(room.as_str(), event_type.as_str()).encode(),
|
||||
(room.as_str(), event_type.to_string().as_str()).encode(),
|
||||
self.serialize_event(&event)
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
)?;
|
||||
@@ -545,7 +545,11 @@ impl SledStore {
|
||||
for (event_type, events) in event_types {
|
||||
for (state_key, event) in events {
|
||||
state.insert(
|
||||
(room.as_str(), event_type.as_str(), state_key.as_str())
|
||||
(
|
||||
room.as_str(),
|
||||
event_type.to_string().as_str(),
|
||||
state_key.as_str(),
|
||||
)
|
||||
.encode(),
|
||||
self.serialize_event(&event)
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
@@ -592,7 +596,11 @@ impl SledStore {
|
||||
for (event_type, events) in event_types {
|
||||
for (state_key, event) in events {
|
||||
stripped_state.insert(
|
||||
(room.as_str(), event_type.as_str(), state_key.as_str())
|
||||
(
|
||||
room.as_str(),
|
||||
event_type.to_string().as_str(),
|
||||
state_key.as_str(),
|
||||
)
|
||||
.encode(),
|
||||
self.serialize_event(&event)
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
@@ -682,7 +690,7 @@ impl SledStore {
|
||||
state_key: &str,
|
||||
) -> Result<Option<Raw<AnySyncStateEvent>>> {
|
||||
let db = self.clone();
|
||||
let key = (room_id.as_str(), event_type.as_str(), state_key).encode();
|
||||
let key = (room_id.as_str(), event_type.to_string().as_str(), state_key).encode();
|
||||
spawn_blocking(move || {
|
||||
db.room_state.get(key)?.map(|e| db.deserialize_event(&e)).transpose()
|
||||
})
|
||||
@@ -695,7 +703,7 @@ impl SledStore {
|
||||
event_type: StateEventType,
|
||||
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
||||
let db = self.clone();
|
||||
let key = (room_id.as_str(), event_type.as_str()).encode();
|
||||
let key = (room_id.as_str(), event_type.to_string().as_str()).encode();
|
||||
spawn_blocking(move || {
|
||||
db.room_state
|
||||
.scan_prefix(key)
|
||||
@@ -854,7 +862,7 @@ impl SledStore {
|
||||
event_type: RoomAccountDataEventType,
|
||||
) -> Result<Option<Raw<AnyRoomAccountDataEvent>>> {
|
||||
let db = self.clone();
|
||||
let key = (room_id.as_str(), event_type.as_str()).encode();
|
||||
let key = (room_id.as_str(), event_type.to_string().as_str()).encode();
|
||||
spawn_blocking(move || {
|
||||
db.room_account_data.get(key)?.map(|m| db.deserialize_event(&m)).transpose()
|
||||
})
|
||||
@@ -904,8 +912,7 @@ impl SledStore {
|
||||
|
||||
async fn add_media_content(&self, request: &MediaRequest, data: Vec<u8>) -> Result<()> {
|
||||
self.media.insert(
|
||||
(request.media_type.unique_key().as_str(), request.format.unique_key().as_str())
|
||||
.encode(),
|
||||
(request.source.unique_key().as_str(), request.format.unique_key().as_str()).encode(),
|
||||
data,
|
||||
)?;
|
||||
|
||||
@@ -916,8 +923,8 @@ impl SledStore {
|
||||
|
||||
async fn get_media_content(&self, request: &MediaRequest) -> Result<Option<Vec<u8>>> {
|
||||
let db = self.clone();
|
||||
let key = (request.media_type.unique_key().as_str(), request.format.unique_key().as_str())
|
||||
.encode();
|
||||
let key =
|
||||
(request.source.unique_key().as_str(), request.format.unique_key().as_str()).encode();
|
||||
|
||||
spawn_blocking(move || Ok(db.media.get(key)?.map(|m| m.to_vec()))).await?
|
||||
}
|
||||
@@ -937,8 +944,7 @@ impl SledStore {
|
||||
|
||||
async fn remove_media_content(&self, request: &MediaRequest) -> Result<()> {
|
||||
self.media.remove(
|
||||
(request.media_type.unique_key().as_str(), request.format.unique_key().as_str())
|
||||
.encode(),
|
||||
(request.source.unique_key().as_str(), request.format.unique_key().as_str()).encode(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
@@ -1229,9 +1235,9 @@ impl SledStore {
|
||||
if timeline.sync {
|
||||
for event in &timeline.events {
|
||||
// Redact events already in store only on sync response
|
||||
if let Ok(AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomRedaction(
|
||||
redaction,
|
||||
))) = event.event.deserialize()
|
||||
if let Ok(AnySyncRoomEvent::MessageLike(
|
||||
AnySyncMessageLikeEvent::RoomRedaction(redaction),
|
||||
)) = event.event.deserialize()
|
||||
{
|
||||
let redacts_key = (room_id.as_ref(), redaction.redacts.as_ref()).encode();
|
||||
if let Some(position_key) =
|
||||
|
||||
@@ -18,6 +18,6 @@ appservice = []
|
||||
http = "0.2.4"
|
||||
lazy_static = "1.4.0"
|
||||
matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix-sdk-test-macros" }
|
||||
ruma = { version = "0.5.0", features = ["client-api-c"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "deea762b8", features = ["client-api-c"] }
|
||||
serde = "1.0.126"
|
||||
serde_json = "1.0.64"
|
||||
|
||||
@@ -103,8 +103,9 @@ version = "0.11.3"
|
||||
default_features = false
|
||||
|
||||
[dependencies.ruma]
|
||||
version = "0.5.0"
|
||||
features = ["client-api-c", "compat", "rand", "unstable-msc2448", "unstable-pre-spec"]
|
||||
git = "https://github.com/ruma/ruma"
|
||||
rev = "deea762b8"
|
||||
features = ["client-api-c", "compat", "rand", "unstable-msc2448"]
|
||||
|
||||
[dependencies.tokio-stream]
|
||||
version = "0.1.6"
|
||||
|
||||
@@ -13,7 +13,7 @@ use matrix_sdk::{
|
||||
encryption::verification::{SasVerification, Verification},
|
||||
ruma::{
|
||||
events::{
|
||||
room::message::MessageType, AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent,
|
||||
room::message::MessageType, AnySyncMessageLikeEvent, AnySyncRoomEvent, AnyToDeviceEvent,
|
||||
},
|
||||
UserId,
|
||||
},
|
||||
@@ -133,9 +133,9 @@ async fn login(
|
||||
for event in
|
||||
room_info.timeline.events.iter().filter_map(|e| e.event.deserialize().ok())
|
||||
{
|
||||
if let AnySyncRoomEvent::Message(event) = event {
|
||||
if let AnySyncRoomEvent::MessageLike(event) = event {
|
||||
match event {
|
||||
AnySyncMessageEvent::RoomMessage(m) => {
|
||||
AnySyncMessageLikeEvent::RoomMessage(m) => {
|
||||
if let MessageType::VerificationRequest(_) = &m.content.msgtype
|
||||
{
|
||||
let request = client
|
||||
@@ -150,7 +150,7 @@ async fn login(
|
||||
.expect("Can't accept verification request");
|
||||
}
|
||||
}
|
||||
AnySyncMessageEvent::KeyVerificationKey(e) => {
|
||||
AnySyncMessageLikeEvent::KeyVerificationKey(e) => {
|
||||
if let Some(Verification::SasV1(sas)) = client
|
||||
.encryption()
|
||||
.get_verification(
|
||||
@@ -162,7 +162,7 @@ async fn login(
|
||||
tokio::spawn(wait_for_confirmation((*client).clone(), sas));
|
||||
}
|
||||
}
|
||||
AnySyncMessageEvent::KeyVerificationMac(e) => {
|
||||
AnySyncMessageLikeEvent::KeyVerificationMac(e) => {
|
||||
if let Some(Verification::SasV1(sas)) = client
|
||||
.encryption()
|
||||
.get_verification(
|
||||
|
||||
@@ -6,7 +6,7 @@ use matrix_sdk::{
|
||||
room::message::{
|
||||
MessageType, RoomMessageEventContent, SyncRoomMessageEvent, TextMessageEventContent,
|
||||
},
|
||||
AnyMessageEventContent, AnySyncMessageEvent, AnySyncRoomEvent,
|
||||
AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnySyncRoomEvent,
|
||||
},
|
||||
RoomId,
|
||||
},
|
||||
@@ -37,9 +37,9 @@ impl WasmBot {
|
||||
console::log_1(&format!("Received message event {:?}", &msg_body).into());
|
||||
|
||||
if msg_body.contains("!party") {
|
||||
let content = AnyMessageEventContent::RoomMessage(RoomMessageEventContent::text_plain(
|
||||
"🎉🎊🥳 let's PARTY!! 🥳🎊🎉",
|
||||
));
|
||||
let content = AnyMessageLikeEventContent::RoomMessage(
|
||||
RoomMessageEventContent::text_plain("🎉🎊🥳 let's PARTY!! 🥳🎊🎉"),
|
||||
);
|
||||
|
||||
println!("sending");
|
||||
|
||||
@@ -59,7 +59,7 @@ impl WasmBot {
|
||||
|
||||
for (room_id, room) in response.rooms.join {
|
||||
for event in room.timeline.events {
|
||||
if let Ok(AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(ev))) =
|
||||
if let Ok(AnySyncRoomEvent::Message(AnySyncMessageLikeEvent::RoomMessage(ev))) =
|
||||
event.event.deserialize()
|
||||
{
|
||||
self.on_room_message(&room_id, &ev).await
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
use matrix_sdk_base::media::{MediaFormat, MediaRequest, MediaType};
|
||||
use matrix_sdk_base::media::{MediaFormat, MediaRequest};
|
||||
use mime::Mime;
|
||||
use ruma::{
|
||||
api::client::{
|
||||
@@ -30,6 +30,7 @@ use ruma::{
|
||||
uiaa::AuthData,
|
||||
},
|
||||
assign,
|
||||
events::room::MediaSource,
|
||||
thirdparty::Medium,
|
||||
ClientSecret, MxcUri, SessionId, UInt,
|
||||
};
|
||||
@@ -167,7 +168,7 @@ impl Account {
|
||||
/// ```
|
||||
pub async fn get_avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(url) = self.get_avatar_url().await? {
|
||||
let request = MediaRequest { media_type: MediaType::Uri(url), format };
|
||||
let request = MediaRequest { source: MediaSource::Plain(url), format };
|
||||
Ok(Some(self.client.get_media_content(&request, true).await?))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::io::Read;
|
||||
#[cfg(feature = "image_proc")]
|
||||
use std::io::{BufRead, Cursor, Seek};
|
||||
use std::{io::Read, time::Duration};
|
||||
|
||||
#[cfg(feature = "image_proc")]
|
||||
use image::GenericImageView;
|
||||
@@ -46,8 +46,8 @@ pub struct BaseImageInfo {
|
||||
/// Base metadata about a video.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BaseVideoInfo {
|
||||
/// The duration of the video in milliseconds.
|
||||
pub duration: Option<UInt>,
|
||||
/// The duration of the video.
|
||||
pub duration: Option<Duration>,
|
||||
/// The height of the video in pixels.
|
||||
pub height: Option<UInt>,
|
||||
/// The width of the video in pixels.
|
||||
@@ -61,8 +61,8 @@ pub struct BaseVideoInfo {
|
||||
/// Base metadata about an audio clip.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BaseAudioInfo {
|
||||
/// The duration of the audio clip in milliseconds.
|
||||
pub duration: Option<UInt>,
|
||||
/// The duration of the audio clip.
|
||||
pub duration: Option<Duration>,
|
||||
/// The file size of the audio clip in bytes.
|
||||
pub size: Option<UInt>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use matrix_sdk_base::{locks::RwLock, store::StoreConfig, BaseClient, StateStore}
|
||||
use ruma::{
|
||||
api::{
|
||||
client::{
|
||||
discover::{discover_homeserver, get_supported_versions},
|
||||
discovery::{discover_homeserver, get_supported_versions},
|
||||
Error,
|
||||
},
|
||||
error::FromHttpResponseError,
|
||||
|
||||
@@ -27,7 +27,7 @@ use dashmap::DashMap;
|
||||
use futures_core::stream::Stream;
|
||||
use matrix_sdk_base::{
|
||||
deserialized_responses::SyncResponse,
|
||||
media::{MediaEventContent, MediaFormat, MediaRequest, MediaThumbnailSize, MediaType},
|
||||
media::{MediaEventContent, MediaFormat, MediaRequest, MediaThumbnailSize},
|
||||
BaseClient, Session, Store,
|
||||
};
|
||||
use matrix_sdk_common::{
|
||||
@@ -41,9 +41,9 @@ use ruma::{
|
||||
api::{
|
||||
client::{
|
||||
account::{register, whoami},
|
||||
capabilities::{get_capabilities, Capabilities},
|
||||
device::{delete_devices, get_devices},
|
||||
directory::{get_public_rooms, get_public_rooms_filtered},
|
||||
discovery::get_capabilities::{self, Capabilities},
|
||||
filter::{create_filter::v3::Request as FilterUploadRequest, FilterDefinition},
|
||||
media::{create_content, get_content, get_content_thumbnail},
|
||||
membership::{join_room_by_id, join_room_by_id_or_alias},
|
||||
@@ -57,6 +57,7 @@ use ruma::{
|
||||
MatrixVersion, OutgoingRequest, SendAccessToken,
|
||||
},
|
||||
assign,
|
||||
events::room::MediaSource,
|
||||
presence::PresenceState,
|
||||
DeviceId, MxcUri, RoomId, RoomOrAliasId, ServerName, UInt, UserId,
|
||||
};
|
||||
@@ -377,7 +378,7 @@ impl Client {
|
||||
/// // Custom events work exactly the same way, you just need to declare
|
||||
/// // the content struct and use the EventContent derive macro on it.
|
||||
/// #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
/// #[ruma_event(type = "org.shiny_new_2fa.token", kind = Message)]
|
||||
/// #[ruma_event(type = "org.shiny_new_2fa.token", kind = MessageLike)]
|
||||
/// struct TokenEventContent {
|
||||
/// token: String,
|
||||
/// #[serde(rename = "exp")]
|
||||
@@ -1930,8 +1931,8 @@ impl Client {
|
||||
if let Some(content) = content {
|
||||
Ok(content)
|
||||
} else {
|
||||
let content: Vec<u8> = match &request.media_type {
|
||||
MediaType::Encrypted(file) => {
|
||||
let content: Vec<u8> = match &request.source {
|
||||
MediaSource::Encrypted(file) => {
|
||||
let content: Vec<u8> =
|
||||
self.send(get_content::v3::Request::from_url(&file.url)?, None).await?.file;
|
||||
|
||||
@@ -1951,7 +1952,7 @@ impl Client {
|
||||
|
||||
content
|
||||
}
|
||||
MediaType::Uri(uri) => {
|
||||
MediaSource::Plain(uri) => {
|
||||
if let MediaFormat::Thumbnail(size) = &request.format {
|
||||
self.send(
|
||||
get_content_thumbnail::v3::Request::from_url(
|
||||
@@ -2016,10 +2017,10 @@ impl Client {
|
||||
event_content: impl MediaEventContent,
|
||||
use_cache: bool,
|
||||
) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(media_type) = event_content.file() {
|
||||
if let Some(source) = event_content.source() {
|
||||
Ok(Some(
|
||||
self.get_media_content(
|
||||
&MediaRequest { media_type, format: MediaFormat::File },
|
||||
&MediaRequest { source, format: MediaFormat::File },
|
||||
use_cache,
|
||||
)
|
||||
.await?,
|
||||
@@ -2038,9 +2039,8 @@ impl Client {
|
||||
///
|
||||
/// * `event_content` - The media event content.
|
||||
pub async fn remove_file(&self, event_content: impl MediaEventContent) -> Result<()> {
|
||||
if let Some(media_type) = event_content.file() {
|
||||
self.remove_media_content(&MediaRequest { media_type, format: MediaFormat::File })
|
||||
.await?
|
||||
if let Some(source) = event_content.source() {
|
||||
self.remove_media_content(&MediaRequest { source, format: MediaFormat::File }).await?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -2070,10 +2070,10 @@ impl Client {
|
||||
size: MediaThumbnailSize,
|
||||
use_cache: bool,
|
||||
) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(media_type) = event_content.thumbnail() {
|
||||
if let Some(source) = event_content.thumbnail_source() {
|
||||
Ok(Some(
|
||||
self.get_media_content(
|
||||
&MediaRequest { media_type, format: MediaFormat::Thumbnail(size) },
|
||||
&MediaRequest { source, format: MediaFormat::Thumbnail(size) },
|
||||
use_cache,
|
||||
)
|
||||
.await?,
|
||||
@@ -2099,9 +2099,9 @@ impl Client {
|
||||
event_content: impl MediaEventContent,
|
||||
size: MediaThumbnailSize,
|
||||
) -> Result<()> {
|
||||
if let Some(media_type) = event_content.file() {
|
||||
if let Some(source) = event_content.source() {
|
||||
self.remove_media_content(&MediaRequest {
|
||||
media_type,
|
||||
source,
|
||||
format: MediaFormat::Thumbnail(size),
|
||||
})
|
||||
.await?
|
||||
@@ -2126,7 +2126,7 @@ impl Client {
|
||||
info: Option<AttachmentInfo>,
|
||||
thumbnail: Option<Thumbnail<'_, T>>,
|
||||
) -> Result<ruma::events::room::message::MessageType> {
|
||||
let (thumbnail_url, thumbnail_info) = if let Some(thumbnail) = thumbnail {
|
||||
let (thumbnail_source, thumbnail_info) = if let Some(thumbnail) = thumbnail {
|
||||
let response = self.upload(thumbnail.content_type, thumbnail.reader).await?;
|
||||
let url = response.content_uri;
|
||||
|
||||
@@ -2136,7 +2136,7 @@ impl Client {
|
||||
{ mimetype: Some(thumbnail.content_type.as_ref().to_owned()) }
|
||||
);
|
||||
|
||||
(Some(url), Some(Box::new(thumbnail_info)))
|
||||
(Some(MediaSource::Plain(url)), Some(Box::new(thumbnail_info)))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
@@ -2152,8 +2152,8 @@ impl Client {
|
||||
info.map(room::ImageInfo::from).unwrap_or_default(),
|
||||
{
|
||||
mimetype: Some(content_type.as_ref().to_owned()),
|
||||
thumbnail_url,
|
||||
thumbnail_info
|
||||
thumbnail_source,
|
||||
thumbnail_info,
|
||||
}
|
||||
);
|
||||
message::MessageType::Image(message::ImageMessageEventContent::plain(
|
||||
@@ -2180,7 +2180,7 @@ impl Client {
|
||||
info.map(message::VideoInfo::from).unwrap_or_default(),
|
||||
{
|
||||
mimetype: Some(content_type.as_ref().to_owned()),
|
||||
thumbnail_url,
|
||||
thumbnail_source,
|
||||
thumbnail_info
|
||||
}
|
||||
);
|
||||
@@ -2195,7 +2195,7 @@ impl Client {
|
||||
info.map(message::FileInfo::from).unwrap_or_default(),
|
||||
{
|
||||
mimetype: Some(content_type.as_ref().to_owned()),
|
||||
thumbnail_url,
|
||||
thumbnail_source,
|
||||
thumbnail_info
|
||||
}
|
||||
);
|
||||
@@ -2218,7 +2218,7 @@ pub(crate) mod test {
|
||||
|
||||
use std::{collections::BTreeMap, convert::TryInto, io::Cursor, str::FromStr, time::Duration};
|
||||
|
||||
use matrix_sdk_base::media::{MediaFormat, MediaRequest, MediaThumbnailSize, MediaType};
|
||||
use matrix_sdk_base::media::{MediaFormat, MediaRequest, MediaThumbnailSize};
|
||||
use matrix_sdk_common::deserialized_responses::SyncRoomEvent;
|
||||
use matrix_sdk_test::{test_json, EventBuilder, EventsJson};
|
||||
use mockito::{mock, Matcher};
|
||||
@@ -2245,7 +2245,7 @@ pub(crate) mod test {
|
||||
events::{
|
||||
room::{
|
||||
message::{ImageMessageEventContent, RoomMessageEventContent},
|
||||
ImageInfo,
|
||||
ImageInfo, MediaSource,
|
||||
},
|
||||
AnySyncStateEvent, StateEventType,
|
||||
},
|
||||
@@ -2584,7 +2584,7 @@ pub(crate) mod test {
|
||||
.create();
|
||||
|
||||
if let Err(err) = client.login("example", "wordpass", None, None).await {
|
||||
if let crate::Error::Http(HttpError::ClientApi(FromHttpResponseError::Http(
|
||||
if let crate::Error::Http(HttpError::ClientApi(FromHttpResponseError::Server(
|
||||
ServerError::Known(client_api::Error { kind, message, status_code }),
|
||||
))) = err
|
||||
{
|
||||
@@ -2621,7 +2621,7 @@ pub(crate) mod test {
|
||||
});
|
||||
|
||||
if let Err(err) = client.register(user).await {
|
||||
if let HttpError::UiaaError(FromHttpResponseError::Http(ServerError::Known(
|
||||
if let HttpError::UiaaError(FromHttpResponseError::Server(ServerError::Known(
|
||||
UiaaResponse::MatrixError(client_api::Error { kind, message, status_code }),
|
||||
))) = err
|
||||
{
|
||||
@@ -3177,7 +3177,7 @@ pub(crate) mod test {
|
||||
let config = AttachmentConfig::new().info(AttachmentInfo::Video(BaseVideoInfo {
|
||||
height: Some(uint!(600)),
|
||||
width: Some(uint!(800)),
|
||||
duration: Some(uint!(3600)),
|
||||
duration: Some(Duration::from_millis(3600)),
|
||||
size: None,
|
||||
blurhash: None,
|
||||
}));
|
||||
@@ -3558,7 +3558,7 @@ pub(crate) mod test {
|
||||
let client = logged_in_client().await;
|
||||
|
||||
let request = MediaRequest {
|
||||
media_type: MediaType::Uri(mxc_uri!("mxc://localhost/textfile").to_owned()),
|
||||
source: MediaSource::Plain(mxc_uri!("mxc://localhost/textfile").to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,9 @@ use ruma::{
|
||||
uiaa::AuthData,
|
||||
},
|
||||
assign,
|
||||
events::{AnyMessageEvent, AnyRoomEvent, AnySyncMessageEvent, GlobalAccountDataEventType},
|
||||
events::{
|
||||
AnyMessageLikeEvent, AnyRoomEvent, AnySyncMessageLikeEvent, GlobalAccountDataEventType,
|
||||
},
|
||||
serde::Raw,
|
||||
DeviceId, TransactionId, UserId,
|
||||
};
|
||||
@@ -70,13 +72,13 @@ impl Client {
|
||||
#[cfg(feature = "encryption")]
|
||||
pub(crate) async fn decrypt_room_event(&self, event: Raw<AnyRoomEvent>) -> RoomEvent {
|
||||
if let Some(machine) = self.olm_machine().await {
|
||||
if let Ok(AnyRoomEvent::Message(event)) = event.deserialize() {
|
||||
if let AnyMessageEvent::RoomEncrypted(_) = event {
|
||||
if let Ok(AnyRoomEvent::MessageLike(event)) = event.deserialize() {
|
||||
if let AnyMessageLikeEvent::RoomEncrypted(_) = event {
|
||||
let room_id = event.room_id();
|
||||
// Turn the AnyMessageEvent into a AnySyncMessageEvent
|
||||
// Turn the AnyMessageLikeEvent into a AnySyncMessageLikeEvent
|
||||
let event = event.clone().into();
|
||||
|
||||
if let AnySyncMessageEvent::RoomEncrypted(e) = event {
|
||||
if let AnySyncMessageLikeEvent::RoomEncrypted(e) = event {
|
||||
if let Ok(decrypted) = machine.decrypt_room_event(&e, room_id).await {
|
||||
return decrypted;
|
||||
}
|
||||
@@ -120,7 +122,7 @@ impl Client {
|
||||
info: Option<AttachmentInfo>,
|
||||
thumbnail: Option<Thumbnail<'_, T>>,
|
||||
) -> Result<ruma::events::room::message::MessageType> {
|
||||
let (thumbnail_file, thumbnail_info) = if let Some(thumbnail) = thumbnail {
|
||||
let (thumbnail_source, thumbnail_info) = if let Some(thumbnail) = thumbnail {
|
||||
let mut reader = matrix_sdk_base::crypto::AttachmentEncryptor::new(thumbnail.reader);
|
||||
|
||||
let response = self.upload(thumbnail.content_type, &mut reader).await?;
|
||||
@@ -143,7 +145,7 @@ impl Client {
|
||||
{ mimetype: Some(thumbnail.content_type.as_ref().to_owned()) }
|
||||
);
|
||||
|
||||
(Some(Box::new(file)), Some(Box::new(thumbnail_info)))
|
||||
(Some(MediaSource::Encrypted(Box::new(file))), Some(Box::new(thumbnail_info)))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
@@ -164,14 +166,14 @@ impl Client {
|
||||
.into()
|
||||
};
|
||||
|
||||
use ruma::events::room::{self, message};
|
||||
use ruma::events::room::{self, message, MediaSource};
|
||||
Ok(match content_type.type_() {
|
||||
mime::IMAGE => {
|
||||
let info = assign!(
|
||||
info.map(room::ImageInfo::from).unwrap_or_default(),
|
||||
{
|
||||
mimetype: Some(content_type.as_ref().to_owned()),
|
||||
thumbnail_file,
|
||||
thumbnail_source,
|
||||
thumbnail_info
|
||||
}
|
||||
);
|
||||
@@ -199,7 +201,7 @@ impl Client {
|
||||
info.map(message::VideoInfo::from).unwrap_or_default(),
|
||||
{
|
||||
mimetype: Some(content_type.as_ref().to_owned()),
|
||||
thumbnail_file,
|
||||
thumbnail_source,
|
||||
thumbnail_info
|
||||
}
|
||||
);
|
||||
@@ -214,7 +216,7 @@ impl Client {
|
||||
info.map(message::FileInfo::from).unwrap_or_default(),
|
||||
{
|
||||
mimetype: Some(content_type.as_ref().to_owned()),
|
||||
thumbnail_file,
|
||||
thumbnail_source,
|
||||
thumbnail_info
|
||||
}
|
||||
);
|
||||
@@ -234,13 +236,10 @@ impl Client {
|
||||
) -> Result<ruma::api::client::config::set_global_account_data::v3::Response> {
|
||||
let own_user =
|
||||
self.user_id().await.ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
let data = serde_json::value::to_raw_value(&content)?;
|
||||
|
||||
let request = ruma::api::client::config::set_global_account_data::v3::Request::new(
|
||||
&data,
|
||||
ruma::events::EventContent::event_type(&content),
|
||||
&own_user,
|
||||
);
|
||||
&content, &own_user,
|
||||
)?;
|
||||
|
||||
Ok(self.send(request, None).await?)
|
||||
}
|
||||
@@ -376,11 +375,9 @@ impl Client {
|
||||
&self,
|
||||
request: &ToDeviceRequest,
|
||||
) -> HttpResult<ToDeviceResponse> {
|
||||
let request = RumaToDeviceRequest::new_raw(
|
||||
request.event_type.as_str(),
|
||||
&request.txn_id,
|
||||
request.messages.clone(),
|
||||
);
|
||||
let event_type = request.event_type.to_string();
|
||||
let request =
|
||||
RumaToDeviceRequest::new_raw(&event_type, &request.txn_id, request.messages.clone());
|
||||
|
||||
self.send(request, None).await
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ use ruma::{
|
||||
error::{FromHttpResponseError, IntoHttpError, MatrixError as RumaApiError, ServerError},
|
||||
},
|
||||
events::tag::InvalidUserTagName,
|
||||
identifiers::Error as IdentifierError,
|
||||
IdParseError,
|
||||
};
|
||||
use serde_json::Error as JsonError;
|
||||
use thiserror::Error;
|
||||
@@ -149,7 +149,7 @@ pub enum Error {
|
||||
|
||||
/// An error encountered when trying to parse an identifier.
|
||||
#[error(transparent)]
|
||||
Identifier(#[from] IdentifierError),
|
||||
Identifier(#[from] IdParseError),
|
||||
|
||||
/// An error encountered when trying to parse a url.
|
||||
#[error(transparent)]
|
||||
@@ -211,7 +211,7 @@ impl HttpError {
|
||||
/// This method is an convenience method to get to the info the server
|
||||
/// returned on the first, failed request.
|
||||
pub fn uiaa_response(&self) -> Option<&UiaaInfo> {
|
||||
if let HttpError::UiaaError(FromHttpResponseError::Http(ServerError::Known(
|
||||
if let HttpError::UiaaError(FromHttpResponseError::Server(ServerError::Known(
|
||||
UiaaError::AuthResponse(i),
|
||||
))) = self
|
||||
{
|
||||
@@ -235,9 +235,9 @@ impl Error {
|
||||
/// This method is an convenience method to get to the info the server
|
||||
/// returned on the first, failed request.
|
||||
pub fn uiaa_response(&self) -> Option<&UiaaInfo> {
|
||||
if let Error::Http(HttpError::UiaaError(FromHttpResponseError::Http(ServerError::Known(
|
||||
UiaaError::AuthResponse(i),
|
||||
)))) = self
|
||||
if let Error::Http(HttpError::UiaaError(FromHttpResponseError::Server(
|
||||
ServerError::Known(UiaaError::AuthResponse(i)),
|
||||
))) = self
|
||||
{
|
||||
Some(i)
|
||||
} else {
|
||||
|
||||
@@ -390,35 +390,37 @@ mod static_events {
|
||||
use ruma::events::{
|
||||
self,
|
||||
presence::{PresenceEvent, PresenceEventContent},
|
||||
StaticEventContent,
|
||||
EphemeralRoomEventType, EventContent, GlobalAccountDataEventType, MessageLikeEventType,
|
||||
RedactedEventContent, RoomAccountDataEventType, StateEventType, StaticEventContent,
|
||||
ToDeviceEventType,
|
||||
};
|
||||
|
||||
use super::{EventKind, SyncEvent};
|
||||
|
||||
impl<C> SyncEvent for events::GlobalAccountDataEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::GlobalAccountDataEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = GlobalAccountDataEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::GlobalAccountData, C::TYPE);
|
||||
}
|
||||
|
||||
impl<C> SyncEvent for events::RoomAccountDataEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::RoomAccountDataEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = RoomAccountDataEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::RoomAccountData, C::TYPE);
|
||||
}
|
||||
|
||||
impl<C> SyncEvent for events::SyncEphemeralRoomEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::EphemeralRoomEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = EphemeralRoomEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::EphemeralRoomData, C::TYPE);
|
||||
}
|
||||
|
||||
impl<C> SyncEvent for events::SyncMessageEvent<C>
|
||||
impl<C> SyncEvent for events::SyncMessageLikeEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::MessageEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = MessageLikeEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::Message { redacted: false }, C::TYPE);
|
||||
}
|
||||
@@ -432,28 +434,28 @@ mod static_events {
|
||||
|
||||
impl<C> SyncEvent for events::SyncStateEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::StateEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = StateEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::State { redacted: false }, C::TYPE);
|
||||
}
|
||||
|
||||
impl<C> SyncEvent for events::StrippedStateEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::StateEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = StateEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::StrippedState, C::TYPE);
|
||||
}
|
||||
|
||||
impl<C> SyncEvent for events::InitialStateEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::StateEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = StateEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::InitialState, C::TYPE);
|
||||
}
|
||||
|
||||
impl<C> SyncEvent for events::ToDeviceEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::ToDeviceEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = ToDeviceEventType>,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::ToDevice, C::TYPE);
|
||||
}
|
||||
@@ -462,9 +464,11 @@ mod static_events {
|
||||
const ID: (EventKind, &'static str) = (EventKind::Presence, PresenceEventContent::TYPE);
|
||||
}
|
||||
|
||||
impl<C> SyncEvent for events::RedactedSyncMessageEvent<C>
|
||||
impl<C> SyncEvent for events::RedactedSyncMessageLikeEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::RedactedMessageEventContent,
|
||||
C: StaticEventContent
|
||||
+ EventContent<EventType = MessageLikeEventType>
|
||||
+ RedactedEventContent,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::Message { redacted: true }, C::TYPE);
|
||||
}
|
||||
@@ -478,7 +482,7 @@ mod static_events {
|
||||
|
||||
impl<C> SyncEvent for events::RedactedSyncStateEvent<C>
|
||||
where
|
||||
C: StaticEventContent + events::RedactedStateEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = StateEventType> + RedactedEventContent,
|
||||
{
|
||||
const ID: (EventKind, &'static str) = (EventKind::State { redacted: true }, C::TYPE);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ use ruma::{
|
||||
},
|
||||
assign,
|
||||
events::{
|
||||
room::history_visibility::HistoryVisibility,
|
||||
room::{history_visibility::HistoryVisibility, MediaSource},
|
||||
tag::{TagInfo, TagName},
|
||||
AnyStateEvent, AnySyncStateEvent, StateEventContent, StateEventType, StaticEventContent,
|
||||
AnyStateEvent, AnySyncStateEvent, EventContent, StateEventType, StaticEventContent,
|
||||
SyncStateEvent,
|
||||
},
|
||||
serde::Raw,
|
||||
@@ -26,7 +26,7 @@ use ruma::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
media::{MediaFormat, MediaRequest, MediaType},
|
||||
media::{MediaFormat, MediaRequest},
|
||||
room::RoomType,
|
||||
BaseRoom, Client, HttpError, HttpResult, Result, RoomMember,
|
||||
};
|
||||
@@ -131,7 +131,7 @@ impl Common {
|
||||
/// ```
|
||||
pub async fn avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(url) = self.avatar_url() {
|
||||
let request = MediaRequest { media_type: MediaType::Uri(url.clone()), format };
|
||||
let request = MediaRequest { source: MediaSource::Plain(url.clone()), format };
|
||||
Ok(Some(self.client.get_media_content(&request, true).await?))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -661,7 +661,7 @@ impl Common {
|
||||
/// ```
|
||||
pub async fn get_state_events_static<C>(&self) -> Result<Vec<Raw<SyncStateEvent<C>>>>
|
||||
where
|
||||
C: StaticEventContent + StateEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = StateEventType>,
|
||||
{
|
||||
// FIXME: Could be more efficient, if we had streaming store accessor functions
|
||||
Ok(self.get_state_events(C::TYPE.into()).await?.into_iter().map(Raw::cast).collect())
|
||||
@@ -701,7 +701,7 @@ impl Common {
|
||||
state_key: &str,
|
||||
) -> Result<Option<Raw<SyncStateEvent<C>>>>
|
||||
where
|
||||
C: StaticEventContent + StateEventContent,
|
||||
C: StaticEventContent + EventContent<EventType = StateEventType>,
|
||||
{
|
||||
Ok(self.get_state_event(C::TYPE.into(), state_key).await?.map(Raw::cast))
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ use ruma::{
|
||||
typing::create_typing_event::v3::{Request as TypingRequest, Typing},
|
||||
},
|
||||
assign,
|
||||
events::{room::message::RoomMessageEventContent, MessageEventContent, StateEventContent},
|
||||
events::{
|
||||
room::message::RoomMessageEventContent, EventContent, MessageLikeEventType, StateEventType,
|
||||
},
|
||||
receipt::ReceiptType,
|
||||
serde::Raw,
|
||||
EventId, TransactionId, UserId,
|
||||
@@ -402,8 +404,8 @@ impl Joined {
|
||||
/// earlier transaction ID.
|
||||
/// * On the receiving side, the field is used for recognizing our own
|
||||
/// messages when they arrive down the sync: the server includes the
|
||||
/// ID in the [`Unsigned`] field [`transaction_id`] of the
|
||||
/// corresponding [`SyncMessageEvent`], but only for the *sending*
|
||||
/// ID in the [`MessageLikeUnsigned`] field [`transaction_id`] of the
|
||||
/// corresponding [`SyncMessageLikeEvent`], but only for the *sending*
|
||||
/// device. Other devices will not see it. This is then used to ignore
|
||||
/// events sent by our own device and/or to implement local echo.
|
||||
///
|
||||
@@ -438,7 +440,7 @@ impl Joined {
|
||||
///
|
||||
/// // Custom events work too:
|
||||
/// #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
/// #[ruma_event(type = "org.shiny_new_2fa.token", kind = Message)]
|
||||
/// #[ruma_event(type = "org.shiny_new_2fa.token", kind = MessageLike)]
|
||||
/// struct TokenEventContent {
|
||||
/// token: String,
|
||||
/// #[serde(rename = "exp")]
|
||||
@@ -461,18 +463,18 @@ impl Joined {
|
||||
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
|
||||
/// ```
|
||||
///
|
||||
/// [`SyncMessageEvent`]: ruma::events::SyncMessageEvent
|
||||
/// [`Unsigned`]: ruma::events::Unsigned
|
||||
/// [`transaction_id`]: ruma::events::Unsigned#structfield.transaction_id
|
||||
/// [`SyncMessageLikeEvent`]: ruma::events::SyncMessageLikeEvent
|
||||
/// [`MessageLikeUnsigned`]: ruma::events::MessageLikeUnsigned
|
||||
/// [`transaction_id`]: ruma::events::MessageLikeUnsigned#structfield.transaction_id
|
||||
pub async fn send(
|
||||
&self,
|
||||
content: impl MessageEventContent,
|
||||
content: impl EventContent<EventType = MessageLikeEventType>,
|
||||
txn_id: Option<&TransactionId>,
|
||||
) -> Result<send_message_event::v3::Response> {
|
||||
let event_type = content.event_type();
|
||||
let event_type = content.event_type().to_string();
|
||||
let content = serde_json::to_value(&content)?;
|
||||
|
||||
self.send_raw(content, event_type, txn_id).await
|
||||
self.send_raw(content, &event_type, txn_id).await
|
||||
}
|
||||
|
||||
/// Send a room message to this room from a json `Value`.
|
||||
@@ -500,8 +502,8 @@ impl Joined {
|
||||
/// earlier transaction ID.
|
||||
/// * On the receiving side, the field is used for recognizing our own
|
||||
/// messages when they arrive down the sync: the server includes the
|
||||
/// ID in the [`Unsigned`] field [`transaction_id`] of the
|
||||
/// corresponding [`SyncMessageEvent`], but only for the *sending*
|
||||
/// ID in the [`StateUnsigned`] field [`transaction_id`] of the
|
||||
/// corresponding [`SyncMessageLikeEvent`], but only for the *sending*
|
||||
/// device. Other devices will not see it. This is then used to ignore
|
||||
/// events sent by our own device and/or to implement local echo.
|
||||
///
|
||||
@@ -529,9 +531,9 @@ impl Joined {
|
||||
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
|
||||
/// ```
|
||||
///
|
||||
/// [`SyncMessageEvent`]: ruma::events::SyncMessageEvent
|
||||
/// [`Unsigned`]: ruma::events::Unsigned
|
||||
/// [`transaction_id`]: ruma::events::Unsigned#structfield.transaction_id
|
||||
/// [`SyncMessageLikeEvent`]: ruma::events::SyncMessageLikeEvent
|
||||
/// [`StateUnsigned`]: ruma::events::StateUnsigned
|
||||
/// [`transaction_id`]: ruma::events::StateUnsigned#structfield.transaction_id
|
||||
pub async fn send_raw(
|
||||
&self,
|
||||
content: Value,
|
||||
@@ -583,7 +585,7 @@ impl Joined {
|
||||
let request = send_message_event::v3::Request::new_raw(
|
||||
self.inner.room_id(),
|
||||
&txn_id,
|
||||
event_type,
|
||||
event_type.into(),
|
||||
content,
|
||||
);
|
||||
|
||||
@@ -806,7 +808,7 @@ impl Joined {
|
||||
/// ```
|
||||
pub async fn send_state_event(
|
||||
&self,
|
||||
content: impl StateEventContent,
|
||||
content: impl EventContent<EventType = StateEventType>,
|
||||
state_key: &str,
|
||||
) -> Result<send_state_event::v3::Response> {
|
||||
let request =
|
||||
@@ -857,7 +859,7 @@ impl Joined {
|
||||
let content = Raw::new(&content)?.cast();
|
||||
let request = send_state_event::v3::Request::new_raw(
|
||||
self.inner.room_id(),
|
||||
event_type,
|
||||
event_type.into(),
|
||||
state_key,
|
||||
content,
|
||||
);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use ruma::events::room::MediaSource;
|
||||
|
||||
use crate::{
|
||||
media::{MediaFormat, MediaRequest, MediaType},
|
||||
media::{MediaFormat, MediaRequest},
|
||||
BaseRoomMember, Client, Result,
|
||||
};
|
||||
|
||||
@@ -61,7 +63,7 @@ impl RoomMember {
|
||||
/// ```
|
||||
pub async fn avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(url) = self.avatar_url() {
|
||||
let request = MediaRequest { media_type: MediaType::Uri(url.to_owned()), format };
|
||||
let request = MediaRequest { source: MediaSource::Plain(url.to_owned()), format };
|
||||
Ok(Some(self.client.get_media_content(&request, true).await?))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
Reference in New Issue
Block a user