From 92df7b22ec4592bafca14822ea9c0bcb09dd8ae9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 17 Jul 2023 17:33:37 +0200 Subject: [PATCH] Rename room::Common to Room MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and export it at the matrix_sdk crate root. --- bindings/matrix-sdk-ffi/src/room.rs | 2 +- .../src/room_list_service/room.rs | 6 +- crates/matrix-sdk-ui/src/timeline/builder.rs | 6 +- crates/matrix-sdk-ui/src/timeline/inner.rs | 11 ++- crates/matrix-sdk-ui/src/timeline/mod.rs | 19 +++-- crates/matrix-sdk-ui/src/timeline/queue.rs | 12 +-- .../src/timeline/read_receipts.rs | 6 +- crates/matrix-sdk-ui/src/timeline/traits.rs | 8 +- crates/matrix-sdk/src/client/mod.rs | 77 +++++++++---------- crates/matrix-sdk/src/docs/encryption.md | 2 +- .../src/encryption/identities/users.rs | 6 +- crates/matrix-sdk/src/encryption/mod.rs | 4 +- .../matrix-sdk/src/event_handler/context.rs | 4 +- crates/matrix-sdk/src/event_handler/mod.rs | 25 +++--- crates/matrix-sdk/src/lib.rs | 1 + crates/matrix-sdk/src/room/futures.rs | 8 +- crates/matrix-sdk/src/room/messages.rs | 2 +- crates/matrix-sdk/src/room/mod.rs | 22 +++--- crates/matrix-sdk/src/sliding_sync/room.rs | 2 +- crates/matrix-sdk/src/sync.rs | 8 +- examples/appservice_autojoin/src/main.rs | 8 +- examples/autojoin/src/main.rs | 4 +- examples/command_bot/src/main.rs | 5 +- examples/custom_events/src/main.rs | 9 +-- examples/getting_started/src/main.rs | 7 +- examples/image_bot/src/main.rs | 5 +- examples/login/src/main.rs | 5 +- examples/persist_session/src/main.rs | 5 +- .../src/tests/repeated_join.rs | 5 +- 29 files changed, 134 insertions(+), 150 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 845dddab7..74f84d379 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -7,7 +7,7 @@ use matrix_sdk::{ AttachmentConfig, AttachmentInfo, BaseAudioInfo, BaseFileInfo, BaseImageInfo, BaseThumbnailInfo, BaseVideoInfo, Thumbnail, }, - room::{Common as SdkRoom, Receipts}, + room::{Receipts, Room as SdkRoom}, ruma::{ api::client::{receipt::create_receipt::v3::ReceiptType, room::report_content}, events::{ diff --git a/crates/matrix-sdk-ui/src/room_list_service/room.rs b/crates/matrix-sdk-ui/src/room_list_service/room.rs index 78ffac83a..54dedb895 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/room.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/room.rs @@ -46,7 +46,7 @@ struct RoomInner { sliding_sync_room: SlidingSyncRoom, /// The underlying client room. - room: matrix_sdk::room::Common, + room: matrix_sdk::Room, /// The timeline of the room. timeline: AsyncOnceCell>, @@ -89,8 +89,8 @@ impl Room { }) } - /// Get the underlying [`matrix_sdk::room::Common`]. - pub fn inner_room(&self) -> &matrix_sdk::room::Common { + /// Get the underlying [`matrix_sdk::Room`]. + pub fn inner_room(&self) -> &matrix_sdk::Room { &self.inner.room } diff --git a/crates/matrix-sdk-ui/src/timeline/builder.rs b/crates/matrix-sdk-ui/src/timeline/builder.rs index c2ff7618f..f1e7bcea9 100644 --- a/crates/matrix-sdk-ui/src/timeline/builder.rs +++ b/crates/matrix-sdk-ui/src/timeline/builder.rs @@ -18,7 +18,7 @@ use async_std::sync::Mutex; use eyeball::SharedObservable; use imbl::Vector; use matrix_sdk::{ - deserialized_responses::SyncTimelineEvent, executor::spawn, room, sync::RoomUpdate, + deserialized_responses::SyncTimelineEvent, executor::spawn, sync::RoomUpdate, Room, }; use ruma::events::{ receipt::{ReceiptThread, ReceiptType}, @@ -40,14 +40,14 @@ use super::{ #[must_use] #[derive(Debug)] pub struct TimelineBuilder { - room: room::Common, + room: Room, prev_token: Option, events: Vector, settings: TimelineInnerSettings, } impl TimelineBuilder { - pub(super) fn new(room: &room::Common) -> Self { + pub(super) fn new(room: &Room) -> Self { Self { room: room.clone(), prev_token: None, diff --git a/crates/matrix-sdk-ui/src/timeline/inner.rs b/crates/matrix-sdk-ui/src/timeline/inner.rs index 6e01d4989..09b157475 100644 --- a/crates/matrix-sdk-ui/src/timeline/inner.rs +++ b/crates/matrix-sdk-ui/src/timeline/inner.rs @@ -26,9 +26,8 @@ use itertools::Itertools; use matrix_sdk::crypto::OlmMachine; use matrix_sdk::{ deserialized_responses::{SyncTimelineEvent, TimelineEvent}, - room, sync::{JoinedRoom, Timeline}, - Error, Result, + Error, Result, Room, }; #[cfg(test)] use ruma::events::receipt::ReceiptEventContent; @@ -74,7 +73,7 @@ use super::{ use crate::events::SyncTimelineEventWithoutContent; #[derive(Clone, Debug)] -pub(super) struct TimelineInner { +pub(super) struct TimelineInner { state: Arc>, room_data_provider: P, settings: TimelineInnerSettings, @@ -743,7 +742,7 @@ impl TimelineInner

{ #[instrument(skip(self, room), fields(room_id = ?room.room_id()))] pub(super) async fn retry_event_decryption( &self, - room: &room::Common, + room: &Room, session_ids: Option>, ) { self.retry_event_decryption_inner(room.to_owned(), session_ids).await @@ -945,7 +944,7 @@ impl TimelineInner

{ } impl TimelineInner { - pub(super) fn room(&self) -> &room::Common { + pub(super) fn room(&self) -> &Room { &self.room_data_provider } @@ -1254,7 +1253,7 @@ async fn fetch_replied_to_event( item: &EventTimelineItem, message: &Message, in_reply_to: &EventId, - room: &room::Common, + room: &Room, ) -> Result>, super::Error> { if let Some((_, item)) = rfind_event_by_id(&state.items, in_reply_to) { let details = match item.content() { diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 1708d3bf2..b66b463d5 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -27,7 +27,7 @@ use matrix_sdk::{ attachment::AttachmentConfig, event_handler::EventHandlerHandle, executor::JoinHandle, - room::{self, MessagesOptions, Receipts}, + room::{MessagesOptions, Receipts, Room}, Client, Result, }; use matrix_sdk_base::RoomState; @@ -102,7 +102,7 @@ const DEFAULT_SANITIZER_MODE: HtmlSanitizerMode = HtmlSanitizerMode::Compat; /// messages. #[derive(Debug)] pub struct Timeline { - inner: TimelineInner, + inner: TimelineInner, start_token: Arc>>, start_token_condvar: Arc, @@ -128,11 +128,11 @@ impl From<&Annotation> for AnnotationKey { } impl Timeline { - pub(crate) fn builder(room: &room::Common) -> TimelineBuilder { + pub(crate) fn builder(room: &Room) -> TimelineBuilder { TimelineBuilder::new(room) } - fn room(&self) -> &room::Common { + fn room(&self) -> &Room { self.inner.room() } @@ -573,10 +573,9 @@ impl Timeline { /// Get the latest read receipt for the given user. /// - /// Contrary to [`Common::user_receipt()`](room::Common::user_receipt) that - /// only keeps track of read receipts received from the homeserver, this - /// keeps also track of implicit read receipts in this timeline, i.e. - /// when a room member sends an event. + /// Contrary to [`Room::user_receipt()`] that only keeps track of read + /// receipts received from the homeserver, this keeps also track of implicit + /// read receipts in this timeline, i.e. when a room member sends an event. #[instrument(skip(self))] pub async fn latest_user_read_receipt( &self, @@ -587,7 +586,7 @@ impl Timeline { /// Send the given receipt. /// - /// This uses [`room::Common::send_single_receipt`] internally, but checks + /// This uses [`Room::send_single_receipt`] internally, but checks /// first if the receipt points to an event in this timeline that is more /// recent than the current ones, to avoid unnecessary requests. #[instrument(skip(self))] @@ -606,7 +605,7 @@ impl Timeline { /// Send the given receipts. /// - /// This uses [`room::Common::send_multiple_receipts`] internally, but + /// This uses [`Room::send_multiple_receipts`] internally, but /// checks first if the receipts point to events in this timeline that /// are more recent than the current ones, to avoid unnecessary /// requests. diff --git a/crates/matrix-sdk-ui/src/timeline/queue.rs b/crates/matrix-sdk-ui/src/timeline/queue.rs index e1bf5e84b..22e8413ad 100644 --- a/crates/matrix-sdk-ui/src/timeline/queue.rs +++ b/crates/matrix-sdk-ui/src/timeline/queue.rs @@ -24,7 +24,7 @@ use std::{ use futures_util::future::Either; use matrix_sdk::{ executor::{spawn, JoinError, JoinHandle}, - room, + Room, }; use matrix_sdk_base::RoomState; use ruma::{events::AnyMessageLikeEventContent, OwnedTransactionId}; @@ -46,7 +46,7 @@ pub(super) struct LocalMessage { #[instrument(skip_all, fields(room_id = ?room.room_id()))] pub(super) async fn send_queued_messages( timeline_inner: TimelineInner, - room: room::Common, + room: Room, mut msg_receiver: Receiver, ) { let mut queue = VecDeque::new(); @@ -98,7 +98,7 @@ pub(super) async fn send_queued_messages( async fn handle_message( msg: LocalMessage, - room: room::Common, + room: Room, send_task: &mut SendMessageTask, queue: &mut VecDeque, timeline_inner: &TimelineInner, @@ -160,7 +160,7 @@ enum SendMessageResult { Success { /// The joined room object, used to start sending of the next message /// in the queue, if it isn't empty. - room: room::Common, + room: Room, }, /// Sending failed, and the local echo was updated to indicate this. SendingFailed, @@ -186,7 +186,7 @@ enum SendMessageTask { /// The transaction ID of the message that is being sent. txn_id: OwnedTransactionId, /// Handle to the task itself. - join_handle: JoinHandle>, + join_handle: JoinHandle>, }, } @@ -196,7 +196,7 @@ impl SendMessageTask { matches!(self, Self::Idle) } - fn start(&mut self, room: room::Common, timeline_inner: TimelineInner, msg: LocalMessage) { + fn start(&mut self, room: Room, timeline_inner: TimelineInner, msg: LocalMessage) { debug!("Spawning message-sending task"); let txn_id = msg.txn_id.clone(); let join_handle = spawn(async move { diff --git a/crates/matrix-sdk-ui/src/timeline/read_receipts.rs b/crates/matrix-sdk-ui/src/timeline/read_receipts.rs index c7e889dee..c1759fce6 100644 --- a/crates/matrix-sdk-ui/src/timeline/read_receipts.rs +++ b/crates/matrix-sdk-ui/src/timeline/read_receipts.rs @@ -16,7 +16,7 @@ use std::{collections::HashMap, sync::Arc}; use eyeball_im::ObservableVector; use indexmap::IndexMap; -use matrix_sdk::room; +use matrix_sdk::Room; use ruma::{ events::receipt::{Receipt, ReceiptEventContent, ReceiptThread, ReceiptType}, EventId, OwnedEventId, OwnedUserId, UserId, @@ -129,7 +129,7 @@ impl TimelineInnerState { &self, user_id: &UserId, receipt_type: ReceiptType, - room: &room::Common, + room: &Room, ) -> Option<(OwnedEventId, Receipt)> { if let Some(receipt) = self .users_read_receipts @@ -154,7 +154,7 @@ impl TimelineInnerState { pub(super) async fn latest_user_read_receipt( &self, user_id: &UserId, - room: &room::Common, + room: &Room, ) -> Option<(OwnedEventId, Receipt)> { let public_read_receipt = self.user_receipt(user_id, ReceiptType::Read, room).await; let private_read_receipt = self.user_receipt(user_id, ReceiptType::ReadPrivate, room).await; diff --git a/crates/matrix-sdk-ui/src/timeline/traits.rs b/crates/matrix-sdk-ui/src/timeline/traits.rs index 4d6b808be..a966fcc9f 100644 --- a/crates/matrix-sdk-ui/src/timeline/traits.rs +++ b/crates/matrix-sdk-ui/src/timeline/traits.rs @@ -14,7 +14,7 @@ use async_trait::async_trait; use indexmap::IndexMap; -use matrix_sdk::room; +use matrix_sdk::Room; #[cfg(feature = "e2e-encryption")] use matrix_sdk::{deserialized_responses::TimelineEvent, Result}; use ruma::{ @@ -52,7 +52,7 @@ pub trait RoomExt { } #[async_trait] -impl RoomExt for room::Common { +impl RoomExt for Room { async fn timeline(&self) -> Timeline { self.timeline_builder().build().await } @@ -71,7 +71,7 @@ pub(super) trait RoomDataProvider: Clone + Send + Sync + 'static { } #[async_trait] -impl RoomDataProvider for room::Common { +impl RoomDataProvider for Room { fn own_user_id(&self) -> &UserId { (**self).own_user_id() } @@ -137,7 +137,7 @@ pub(super) trait Decryptor: Clone + Send + Sync + 'static { #[cfg(feature = "e2e-encryption")] #[async_trait] -impl Decryptor for room::Common { +impl Decryptor for Room { async fn decrypt_event_impl(&self, raw: &Raw) -> Result { self.decrypt_event(raw.cast_ref()).await } diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 26189f7db..eeb528162 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -84,9 +84,9 @@ use crate::{ http_client::HttpClient, matrix_auth::MatrixAuth, notification_settings::NotificationSettings, - room, sync::{RoomUpdate, SyncResponse}, - Account, AuthApi, AuthSession, Error, Media, RefreshTokenError, Result, TransmissionProgress, + Account, AuthApi, AuthSession, Error, Media, RefreshTokenError, Result, Room, + TransmissionProgress, }; mod builder; @@ -104,10 +104,9 @@ type NotificationHandlerFut = Pin>>; #[cfg(not(target_arch = "wasm32"))] type NotificationHandlerFn = - Box NotificationHandlerFut + Send + Sync>; + Box NotificationHandlerFut + Send + Sync>; #[cfg(target_arch = "wasm32")] -type NotificationHandlerFn = - Box NotificationHandlerFut>; +type NotificationHandlerFn = Box NotificationHandlerFut>; /// Enum controlling if a loop running callbacks should continue or abort. /// @@ -477,8 +476,8 @@ impl Client { /// the event handler being skipped and an error being logged. The following /// context argument types are only available for a subset of event types: /// - /// * [`room::Common`] is only available for room-specific events, i.e. not - /// for events like global account data events or presence events. + /// * [`Room`] is only available for room-specific events, i.e. not for + /// events like global account data events or presence events. /// /// You can provide custom context via /// [`add_event_handler_context`](Client::add_event_handler_context) and @@ -495,7 +494,6 @@ impl Client { /// use matrix_sdk::{ /// deserialized_responses::EncryptionInfo, /// event_handler::Ctx, - /// room::Common, /// ruma::{ /// events::{ /// macros::EventContent, @@ -505,7 +503,7 @@ impl Client { /// push::Action, /// Int, MilliSecondsSinceUnixEpoch, /// }, - /// Client, + /// Client, Room, /// }; /// use serde::{Deserialize, Serialize}; /// @@ -518,12 +516,12 @@ impl Client { /// # .unwrap(); /// # /// client.add_event_handler( - /// |ev: SyncRoomMessageEvent, room: Common, client: Client| async move { + /// |ev: SyncRoomMessageEvent, room: Room, client: Client| async move { /// // Common usage: Room event plus room and client. /// }, /// ); /// client.add_event_handler( - /// |ev: SyncRoomMessageEvent, room: Common, encryption_info: Option| { + /// |ev: SyncRoomMessageEvent, room: Room, encryption_info: Option| { /// async move { /// // An `Option` parameter lets you distinguish between /// // unencrypted events and events that were decrypted by the SDK. @@ -531,7 +529,7 @@ impl Client { /// }, /// ); /// client.add_event_handler( - /// |ev: SyncRoomMessageEvent, room: Common, push_actions: Vec| { + /// |ev: SyncRoomMessageEvent, room: Room, push_actions: Vec| { /// async move { /// // A `Vec` parameter allows you to know which push actions /// // are applicable for an event. For example, an event with @@ -570,7 +568,7 @@ impl Client { /// expires_at: MilliSecondsSinceUnixEpoch, /// } /// - /// client.add_event_handler(|ev: SyncTokenEvent, room: Common| async move { + /// client.add_event_handler(|ev: SyncTokenEvent, room: Room| async move { /// todo!("Display the token"); /// }); /// @@ -699,8 +697,8 @@ impl Client { /// /// ``` /// use matrix_sdk::{ - /// event_handler::Ctx, room::Common, - /// ruma::events::room::message::SyncRoomMessageEvent, + /// event_handler::Ctx, ruma::events::room::message::SyncRoomMessageEvent, + /// Room, /// }; /// # #[derive(Clone)] /// # struct SomeType; @@ -719,7 +717,7 @@ impl Client { /// /// client.add_event_handler_context(my_gui_handle.clone()); /// client.add_event_handler( - /// |ev: SyncRoomMessageEvent, room: Common, gui_handle: Ctx| { + /// |ev: SyncRoomMessageEvent, room: Room, gui_handle: Ctx| { /// async move { /// // gui_handle.send(DisplayMessage { message: ev }); /// } @@ -737,14 +735,11 @@ impl Client { /// Register a handler for a notification. /// /// Similar to [`Client::add_event_handler`], but only allows functions - /// or closures with exactly the three arguments [`Notification`], - /// [`room::Common`], [`Client`] for now. + /// or closures with exactly the three arguments [`Notification`], [`Room`], + /// [`Client`] for now. pub async fn register_notification_handler(&self, handler: H) -> &Self where - H: Fn(Notification, room::Common, Client) -> Fut - + SendOutsideWasm - + SyncOutsideWasm - + 'static, + H: Fn(Notification, Room, Client) -> Fut + SendOutsideWasm + SyncOutsideWasm + 'static, Fut: Future + SendOutsideWasm + 'static, { self.inner.notification_handlers.write().await.push(Box::new( @@ -778,47 +773,47 @@ impl Client { /// Get all the rooms the client knows about. /// /// This will return the list of joined, invited, and left rooms. - pub fn rooms(&self) -> Vec { + pub fn rooms(&self) -> Vec { self.base_client() .get_rooms() .into_iter() - .map(|room| room::Common::new(self.clone(), room)) + .map(|room| Room::new(self.clone(), room)) .collect() } /// Get all the rooms the client knows about, filtered by room state. - pub fn rooms_filtered(&self, filter: RoomStateFilter) -> Vec { + pub fn rooms_filtered(&self, filter: RoomStateFilter) -> Vec { self.base_client() .get_rooms_filtered(filter) .into_iter() - .map(|room| room::Common::new(self.clone(), room)) + .map(|room| Room::new(self.clone(), room)) .collect() } /// Returns the joined rooms this client knows about. - pub fn joined_rooms(&self) -> Vec { + pub fn joined_rooms(&self) -> Vec { self.base_client() .get_rooms_filtered(RoomStateFilter::JOINED) .into_iter() - .map(|room| room::Common::new(self.clone(), room)) + .map(|room| Room::new(self.clone(), room)) .collect() } /// Returns the invited rooms this client knows about. - pub fn invited_rooms(&self) -> Vec { + pub fn invited_rooms(&self) -> Vec { self.base_client() .get_rooms_filtered(RoomStateFilter::INVITED) .into_iter() - .map(|room| room::Common::new(self.clone(), room)) + .map(|room| Room::new(self.clone(), room)) .collect() } /// Returns the left rooms this client knows about. - pub fn left_rooms(&self) -> Vec { + pub fn left_rooms(&self) -> Vec { self.base_client() .get_rooms_filtered(RoomStateFilter::LEFT) .into_iter() - .map(|room| room::Common::new(self.clone(), room)) + .map(|room| Room::new(self.clone(), room)) .collect() } @@ -827,8 +822,8 @@ impl Client { /// # Arguments /// /// `room_id` - The unique id of the room that should be fetched. - pub fn get_room(&self, room_id: &RoomId) -> Option { - self.base_client().get_room(room_id).map(|room| room::Common::new(self.clone(), room)) + pub fn get_room(&self, room_id: &RoomId) -> Option { + self.base_client().get_room(room_id).map(|room| Room::new(self.clone(), room)) } /// Resolve a room alias to a room id and a list of servers which know @@ -974,11 +969,11 @@ impl Client { /// # Arguments /// /// * `room_id` - The `RoomId` of the room to be joined. - pub async fn join_room_by_id(&self, room_id: &RoomId) -> Result { + pub async fn join_room_by_id(&self, room_id: &RoomId) -> Result { let request = join_room_by_id::v3::Request::new(room_id.to_owned()); let response = self.send(request, None).await?; let base_room = self.base_client().room_joined(&response.room_id).await?; - Ok(room::Common::new(self.clone(), base_room)) + Ok(Room::new(self.clone(), base_room)) } /// Join a room by `RoomId`. @@ -994,13 +989,13 @@ impl Client { &self, alias: &RoomOrAliasId, server_names: &[OwnedServerName], - ) -> Result { + ) -> Result { let request = assign!(join_room_by_id_or_alias::v3::Request::new(alias.to_owned()), { server_name: server_names.to_owned(), }); let response = self.send(request, None).await?; let base_room = self.base_client().room_joined(&response.room_id).await?; - Ok(room::Common::new(self.clone(), base_room)) + Ok(Room::new(self.clone(), base_room)) } /// Search the homeserver's directory of public rooms. @@ -1079,14 +1074,14 @@ impl Client { /// assert!(client.create_room(request).await.is_ok()); /// # }; /// ``` - pub async fn create_room(&self, request: create_room::v3::Request) -> Result { + pub async fn create_room(&self, request: create_room::v3::Request) -> Result { let invite = request.invite.clone(); let is_direct_room = request.is_direct; let response = self.send(request, None).await?; let base_room = self.base_client().get_or_create_room(&response.room_id, RoomState::Joined); - let joined_room = room::Common::new(self.clone(), base_room); + let joined_room = Room::new(self.clone(), base_room); if is_direct_room && !invite.is_empty() { if let Err(error) = @@ -1105,7 +1100,7 @@ impl Client { /// Convenience shorthand for [`create_room`][Self::create_room] with the /// given user being invited, the room marked `is_direct` and both the /// creator and invitee getting the default maximum power level. - pub async fn create_dm(&self, user_id: &UserId) -> Result { + pub async fn create_dm(&self, user_id: &UserId) -> Result { self.create_room(assign!(create_room::v3::Request::new(), { invite: vec![user_id.to_owned()], is_direct: true, diff --git a/crates/matrix-sdk/src/docs/encryption.md b/crates/matrix-sdk/src/docs/encryption.md index e50f36a37..79145768d 100644 --- a/crates/matrix-sdk/src/docs/encryption.md +++ b/crates/matrix-sdk/src/docs/encryption.md @@ -224,7 +224,7 @@ is **not** supported using the default store. [Megolm]: https://gitlab.matrix.org/matrix-org/olm/blob/master/docs/megolm.md [`UserIdentity`]: #struct.verification.UserIdentity [filtered]: crate::config::SyncSettings::filter -[enabled]: crate::room::Common::enable_encryption +[enabled]: crate::Room::enable_encryption [Restoring a Client]: #restoring-a-client [spec]: https://spec.matrix.org/unstable/client-server-api/#relationship-between-access-tokens-and-devices [device keys]: https://spec.matrix.org/unstable/client-server-api/#device-keys diff --git a/crates/matrix-sdk/src/encryption/identities/users.rs b/crates/matrix-sdk/src/encryption/identities/users.rs index 19a1dba32..18c58593f 100644 --- a/crates/matrix-sdk/src/encryption/identities/users.rs +++ b/crates/matrix-sdk/src/encryption/identities/users.rs @@ -31,7 +31,7 @@ use ruma::{ use tokio::sync::RwLock; use super::{ManualVerifyError, RequestVerificationError}; -use crate::{encryption::verification::VerificationRequest, room::Common, Client}; +use crate::{encryption::verification::VerificationRequest, Client, Room}; /// A struct representing a E2EE capable identity of a user. /// @@ -78,7 +78,7 @@ impl UserIdentity { Self { inner: identity.into() } } - pub(crate) fn new(client: Client, identity: InnerUserIdentity, room: Option) -> Self { + pub(crate) fn new(client: Client, identity: InnerUserIdentity, room: Option) -> Self { let identity = OtherUserIdentity { inner: identity, client, @@ -425,7 +425,7 @@ struct OwnUserIdentity { struct OtherUserIdentity { pub(crate) inner: InnerUserIdentity, pub(crate) client: Client, - pub(crate) direct_message_room: Arc>>, + pub(crate) direct_message_room: Arc>>, } impl OwnUserIdentity { diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 430681411..b3bc0e520 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -64,7 +64,7 @@ use crate::{ verification::{SasVerification, Verification, VerificationRequest}, }, error::HttpResult, - room, Client, Error, Result, TransmissionProgress, + Client, Error, Result, Room, TransmissionProgress, }; mod futures; @@ -358,7 +358,7 @@ impl Client { } /// Get the existing DM room with the given user, if any. - pub fn get_dm_room(&self, user_id: &UserId) -> Option { + pub fn get_dm_room(&self, user_id: &UserId) -> Option { let rooms = self.joined_rooms(); // Find the room we share with the `user_id` and only with `user_id` diff --git a/crates/matrix-sdk/src/event_handler/context.rs b/crates/matrix-sdk/src/event_handler/context.rs index 20b80671b..3760b51d7 100644 --- a/crates/matrix-sdk/src/event_handler/context.rs +++ b/crates/matrix-sdk/src/event_handler/context.rs @@ -20,7 +20,7 @@ use ruma::push::Action; use serde_json::value::RawValue as RawJsonValue; use super::{EventHandlerData, EventHandlerHandle}; -use crate::{room, Client}; +use crate::{Client, Room}; /// Context for an event handler. /// @@ -49,7 +49,7 @@ impl EventHandlerContext for EventHandlerHandle { /// Trying to use it in the event handler for another event, for example a /// global account data or presence event, will result in the event handler /// being skipped and an error getting logged. -impl EventHandlerContext for room::Common { +impl EventHandlerContext for Room { fn from_data(data: &EventHandlerData<'_>) -> Option { data.room.clone() } diff --git a/crates/matrix-sdk/src/event_handler/mod.rs b/crates/matrix-sdk/src/event_handler/mod.rs index 7613920b1..11a436bba 100644 --- a/crates/matrix-sdk/src/event_handler/mod.rs +++ b/crates/matrix-sdk/src/event_handler/mod.rs @@ -56,7 +56,7 @@ use serde_json::value::RawValue as RawJsonValue; use tracing::{debug, error, field::debug, instrument, warn}; use self::maps::EventHandlerMaps; -use crate::{room, Client}; +use crate::{Client, Room}; mod context; mod maps; @@ -231,7 +231,7 @@ where #[derive(Debug)] pub struct EventHandlerData<'a> { client: Client, - room: Option, + room: Option, raw: &'a RawJsonValue, encryption_info: Option<&'a EncryptionInfo>, push_actions: &'a [Action], @@ -328,7 +328,7 @@ impl Client { pub(crate) async fn handle_sync_events( &self, kind: HandlerKind, - room: Option<&room::Common>, + room: Option<&Room>, events: &[Raw], ) -> serde_json::Result<()> { #[derive(Deserialize)] @@ -347,7 +347,7 @@ impl Client { pub(crate) async fn handle_sync_state_events( &self, - room: Option<&room::Common>, + room: Option<&Room>, state_events: &[Raw], ) -> serde_json::Result<()> { #[derive(Deserialize)] @@ -375,7 +375,7 @@ impl Client { pub(crate) async fn handle_sync_timeline_events( &self, - room: Option<&room::Common>, + room: Option<&Room>, timeline_events: &[SyncTimelineEvent], ) -> serde_json::Result<()> { #[derive(Deserialize)] @@ -441,7 +441,7 @@ impl Client { #[instrument(skip_all, fields(?event_kind, ?event_type, room_id))] async fn call_event_handlers( &self, - room: Option<&room::Common>, + room: Option<&Room>, raw: &RawJsonValue, event_kind: HandlerKind, event_type: &str, @@ -571,9 +571,8 @@ mod tests { use crate::{ event_handler::Ctx, - room, test_utils::{logged_in_client, no_retry_test_client}, - Client, + Client, Room, }; #[async_test] @@ -587,7 +586,7 @@ mod tests { client.add_event_handler({ let member_count = member_count.clone(); - move |_ev: OriginalSyncRoomMemberEvent, _room: room::Common| { + move |_ev: OriginalSyncRoomMemberEvent, _room: Room| { member_count.fetch_add(1, SeqCst); future::ready(()) } @@ -601,7 +600,7 @@ mod tests { }); client.add_event_handler({ let power_levels_count = power_levels_count.clone(); - move |_ev: OriginalSyncRoomPowerLevelsEvent, _client: Client, _room: room::Common| { + move |_ev: OriginalSyncRoomPowerLevelsEvent, _client: Client, _room: Room| { power_levels_count.fetch_add(1, SeqCst); future::ready(()) } @@ -683,14 +682,14 @@ mod tests { // Room event handlers for member events in both rooms client.add_room_event_handler(room_id_a, { let member_count = member_count.clone(); - move |_ev: OriginalSyncRoomMemberEvent, _room: room::Common| { + move |_ev: OriginalSyncRoomMemberEvent, _room: Room| { member_count.fetch_add(1, SeqCst); future::ready(()) } }); client.add_room_event_handler(room_id_b, { let member_count = member_count.clone(); - move |_ev: OriginalSyncRoomMemberEvent, _room: room::Common| { + move |_ev: OriginalSyncRoomMemberEvent, _room: Room| { member_count.fetch_add(1, SeqCst); future::ready(()) } @@ -699,7 +698,7 @@ mod tests { // Power levels event handlers for member events in room A client.add_room_event_handler(room_id_a, { let power_levels_count = power_levels_count.clone(); - move |_ev: OriginalSyncRoomPowerLevelsEvent, _client: Client, _room: room::Common| { + move |_ev: OriginalSyncRoomPowerLevelsEvent, _client: Client, _room: Room| { power_levels_count.fetch_add(1, SeqCst); future::ready(()) } diff --git a/crates/matrix-sdk/src/lib.rs b/crates/matrix-sdk/src/lib.rs index a9a4d380f..84879a226 100644 --- a/crates/matrix-sdk/src/lib.rs +++ b/crates/matrix-sdk/src/lib.rs @@ -61,6 +61,7 @@ pub use http_client::TransmissionProgress; #[cfg(all(feature = "e2e-encryption", feature = "sqlite"))] pub use matrix_sdk_sqlite::SqliteCryptoStore; pub use media::Media; +pub use room::Room; pub use ruma::{IdParseError, OwnedServerName, ServerName}; #[cfg(feature = "experimental-sliding-sync")] pub use sliding_sync::{ diff --git a/crates/matrix-sdk/src/room/futures.rs b/crates/matrix-sdk/src/room/futures.rs index bb6507668..affc1d8cc 100644 --- a/crates/matrix-sdk/src/room/futures.rs +++ b/crates/matrix-sdk/src/room/futures.rs @@ -10,7 +10,7 @@ use mime::Mime; use ruma::api::client::message::send_message_event; use tracing::{Instrument, Span}; -use super::Common; +use super::Room; use crate::{attachment::AttachmentConfig, Result, TransmissionProgress}; #[cfg(feature = "image-proc")] use crate::{ @@ -18,10 +18,10 @@ use crate::{ error::ImageError, }; -/// Future returned by [`Common::send_attachment`]. +/// Future returned by [`Room::send_attachment`]. #[allow(missing_debug_implementations)] pub struct SendAttachment<'a> { - room: &'a Common, + room: &'a Room, body: &'a str, content_type: &'a Mime, data: Vec, @@ -32,7 +32,7 @@ pub struct SendAttachment<'a> { impl<'a> SendAttachment<'a> { pub(crate) fn new( - room: &'a Common, + room: &'a Room, body: &'a str, content_type: &'a Mime, data: Vec, diff --git a/crates/matrix-sdk/src/room/messages.rs b/crates/matrix-sdk/src/room/messages.rs index a2ac8c542..180fcefff 100644 --- a/crates/matrix-sdk/src/room/messages.rs +++ b/crates/matrix-sdk/src/room/messages.rs @@ -26,7 +26,7 @@ use ruma::{ uint, RoomId, UInt, }; -/// Options for [`messages`][super::Common::messages]. +/// Options for [`messages`][super::Room::messages]. /// /// See that method and /// diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index 69e109668..9aba88ad1 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -88,12 +88,12 @@ pub use self::{ /// A struct containing methods that are common for Joined, Invited and Left /// Rooms #[derive(Debug, Clone)] -pub struct Common { +pub struct Room { inner: BaseRoom, pub(crate) client: Client, } -impl Deref for Common { +impl Deref for Room { type Target = BaseRoom; fn deref(&self) -> &Self::Target { @@ -104,8 +104,8 @@ impl Deref for Common { const TYPING_NOTICE_TIMEOUT: Duration = Duration::from_secs(4); const TYPING_NOTICE_RESEND_TIMEOUT: Duration = Duration::from_secs(3); -impl Common { - /// Create a new `room::Common` +impl Room { + /// Create a new `Room` /// /// # Arguments /// * `client` - The client used to make requests. @@ -590,7 +590,7 @@ impl Common { /// /// ```no_run /// # async { - /// # let room: matrix_sdk::room::Common = todo!(); + /// # let room: matrix_sdk::Room = todo!(); /// use matrix_sdk::ruma::{ /// events::room::member::RoomMemberEventContent, serde::Raw, /// }; @@ -629,7 +629,7 @@ impl Common { /// /// ```no_run /// # async { - /// # let room: matrix_sdk::room::Common = todo!(); + /// # let room: matrix_sdk::Room = todo!(); /// # let user_ids: &[matrix_sdk::ruma::OwnedUserId] = &[]; /// use matrix_sdk::ruma::events::room::member::RoomMemberEventContent; /// @@ -676,7 +676,7 @@ impl Common { /// /// ```no_run /// # async { - /// # let room: matrix_sdk::room::Common = todo!(); + /// # let room: matrix_sdk::Room = todo!(); /// use matrix_sdk::ruma::events::room::power_levels::RoomPowerLevelsEventContent; /// /// let power_levels = room @@ -701,7 +701,7 @@ impl Common { /// /// ```no_run /// # async { - /// # let room: matrix_sdk::room::Common = todo!(); + /// # let room: matrix_sdk::Room = todo!(); /// use matrix_sdk::ruma::{ /// events::room::member::RoomMemberEventContent, serde::Raw, user_id, /// }; @@ -745,7 +745,7 @@ impl Common { /// /// ```no_run /// # async { - /// # let room: matrix_sdk::room::Common = todo!(); + /// # let room: matrix_sdk::Room = todo!(); /// use matrix_sdk::ruma::events::fully_read::FullyReadEventContent; /// /// match room.account_data_static::().await? { @@ -1721,7 +1721,7 @@ impl Common { /// ```no_run /// # use serde::{Deserialize, Serialize}; /// # async { - /// # let joined_room: matrix_sdk::room::Common = todo!(); + /// # let joined_room: matrix_sdk::Room = todo!(); /// use matrix_sdk::ruma::{ /// events::{ /// macros::EventContent, room::encryption::RoomEncryptionEventContent, @@ -1772,7 +1772,7 @@ impl Common { /// ```no_run /// # use serde::{Deserialize, Serialize}; /// # async { - /// # let joined_room: matrix_sdk::room::Common = todo!(); + /// # let joined_room: matrix_sdk::Room = todo!(); /// use matrix_sdk::ruma::{ /// events::{ /// macros::EventContent, diff --git a/crates/matrix-sdk/src/sliding_sync/room.rs b/crates/matrix-sdk/src/sliding_sync/room.rs index a9642642d..c411727f2 100644 --- a/crates/matrix-sdk/src/sliding_sync/room.rs +++ b/crates/matrix-sdk/src/sliding_sync/room.rs @@ -240,7 +240,7 @@ impl SlidingSyncRoom { #[derive(Debug)] struct SlidingSyncRoomInner { - /// The client, used to fetch [`room::Common`][crate::room::Common]. + /// The client, used to fetch [`Room`][crate::Room]. client: Client, /// The room ID. diff --git a/crates/matrix-sdk/src/sync.rs b/crates/matrix-sdk/src/sync.rs index 3d0ddb6e5..964b183e8 100644 --- a/crates/matrix-sdk/src/sync.rs +++ b/crates/matrix-sdk/src/sync.rs @@ -39,7 +39,7 @@ use ruma::{ }; use tracing::{debug, error, warn}; -use crate::{event_handler::HandlerKind, room, Client, Result}; +use crate::{event_handler::HandlerKind, Client, Result, Room}; /// The processed response of a `/sync` request. #[derive(Clone, Default)] @@ -116,21 +116,21 @@ pub enum RoomUpdate { /// Updates to a room the user is no longer in. Left { /// Room object with general information on the room. - room: room::Common, + room: Room, /// Updates to the room. updates: LeftRoom, }, /// Updates to a room the user is currently in. Joined { /// Room object with general information on the room. - room: room::Common, + room: Room, /// Updates to the room. updates: JoinedRoom, }, /// Updates to a room the user is invited to. Invited { /// Room object with general information on the room. - room: room::Common, + room: Room, /// Updates to the room. updates: InvitedRoom, }, diff --git a/examples/appservice_autojoin/src/main.rs b/examples/appservice_autojoin/src/main.rs index 702f605d1..f5c18ec49 100644 --- a/examples/appservice_autojoin/src/main.rs +++ b/examples/appservice_autojoin/src/main.rs @@ -3,11 +3,11 @@ use std::env; use matrix_sdk_appservice::{ matrix_sdk::{ event_handler::Ctx, - room, ruma::{ events::room::member::{MembershipState, OriginalSyncRoomMemberEvent}, UserId, }, + Room, }, ruma::api::client::error::ErrorKind, AppService, AppServiceBuilder, AppServiceRegistration, Result, @@ -16,7 +16,7 @@ use tracing::trace; pub async fn handle_room_member( appservice: AppService, - room: room::Common, + room: Room, event: OriginalSyncRoomMemberEvent, ) -> Result<()> { if !appservice.user_id_is_in_namespace(&event.state_key) { @@ -68,9 +68,7 @@ pub async fn main() -> anyhow::Result<()> { user.add_event_handler_context(appservice.clone()); user.add_event_handler( - move |event: OriginalSyncRoomMemberEvent, - room: room::Common, - Ctx(appservice): Ctx| { + move |event: OriginalSyncRoomMemberEvent, room: Room, Ctx(appservice): Ctx| { handle_room_member(appservice, room, event) }, ); diff --git a/examples/autojoin/src/main.rs b/examples/autojoin/src/main.rs index 5689d2239..1aa0242a4 100644 --- a/examples/autojoin/src/main.rs +++ b/examples/autojoin/src/main.rs @@ -1,7 +1,7 @@ use std::{env, process::exit}; use matrix_sdk::{ - config::SyncSettings, room, ruma::events::room::member::StrippedRoomMemberEvent, Client, + config::SyncSettings, ruma::events::room::member::StrippedRoomMemberEvent, Client, Room, RoomState, }; use tokio::time::{sleep, Duration}; @@ -9,7 +9,7 @@ use tokio::time::{sleep, Duration}; async fn on_stripped_state_member( room_member: StrippedRoomMemberEvent, client: Client, - room: room::Common, + room: Room, ) { if room_member.state_key != client.user_id().unwrap() { return; diff --git a/examples/command_bot/src/main.rs b/examples/command_bot/src/main.rs index 6f9220dbb..b15dd3915 100644 --- a/examples/command_bot/src/main.rs +++ b/examples/command_bot/src/main.rs @@ -2,14 +2,13 @@ use std::{env, process::exit}; use matrix_sdk::{ config::SyncSettings, - room, ruma::events::room::message::{ MessageType, OriginalSyncRoomMessageEvent, RoomMessageEventContent, }, - Client, RoomState, + Client, Room, RoomState, }; -async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: room::Common) { +async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) { if room.state() != RoomState::Joined { return; } diff --git a/examples/custom_events/src/main.rs b/examples/custom_events/src/main.rs index 6001a5246..38b578b59 100644 --- a/examples/custom_events/src/main.rs +++ b/examples/custom_events/src/main.rs @@ -13,7 +13,6 @@ use std::{env, process::exit}; use matrix_sdk::{ config::SyncSettings, - room, ruma::{ events::{ macros::EventContent, @@ -24,7 +23,7 @@ use matrix_sdk::{ }, OwnedEventId, }, - Client, RoomState, + Client, Room, RoomState, }; use serde::{Deserialize, Serialize}; use tokio::time::{sleep, Duration}; @@ -50,7 +49,7 @@ pub struct AckEventContent { // use that for `on_ping_event`. // we want to start the ping-ack-flow on "!ping" messages. -async fn on_regular_room_message(event: OriginalSyncRoomMessageEvent, room: room::Common) { +async fn on_regular_room_message(event: OriginalSyncRoomMessageEvent, room: Room) { if room.state() != RoomState::Joined { return; } @@ -66,7 +65,7 @@ async fn on_regular_room_message(event: OriginalSyncRoomMessageEvent, room: room } // call this on any PingEvent we receive -async fn on_ping_event(event: SyncPingEvent, room: room::Common) { +async fn on_ping_event(event: SyncPingEvent, room: Room) { if room.state() != RoomState::Joined { return; } @@ -124,7 +123,7 @@ async fn login_and_sync( async fn on_stripped_state_member( room_member: StrippedRoomMemberEvent, client: Client, - room: room::Common, + room: Room, ) { if room_member.state_key != client.user_id().unwrap() { // the invite we've seen isn't for us, but for someone else. ignore diff --git a/examples/getting_started/src/main.rs b/examples/getting_started/src/main.rs index 001961135..abacb8b90 100644 --- a/examples/getting_started/src/main.rs +++ b/examples/getting_started/src/main.rs @@ -14,12 +14,11 @@ use std::{env, process::exit}; use matrix_sdk::{ config::SyncSettings, - room, ruma::events::room::{ member::StrippedRoomMemberEvent, message::{MessageType, OriginalSyncRoomMessageEvent, RoomMessageEventContent}, }, - Client, RoomState, + Client, Room, RoomState, }; use tokio::time::{sleep, Duration}; @@ -108,7 +107,7 @@ async fn login_and_sync( async fn on_stripped_state_member( room_member: StrippedRoomMemberEvent, client: Client, - room: room::Common, + room: Room, ) { if room_member.state_key != client.user_id().unwrap() { // the invite we've seen isn't for us, but for someone else. ignore @@ -146,7 +145,7 @@ async fn on_stripped_state_member( // handler lies only in their input parameters. However, that is enough for the // rust-sdk to figure out which one to call one and only do so, when // the parameters are available. -async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: room::Common) { +async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) { // First, we need to unpack the message: We only want messages from rooms we are // still in and that are regular text messages - ignoring everything else. if room.state() != RoomState::Joined { diff --git a/examples/image_bot/src/main.rs b/examples/image_bot/src/main.rs index 930cfda7e..49660db48 100644 --- a/examples/image_bot/src/main.rs +++ b/examples/image_bot/src/main.rs @@ -4,13 +4,12 @@ use matrix_sdk::{ self, attachment::AttachmentConfig, config::SyncSettings, - room, ruma::events::room::message::{MessageType, OriginalSyncRoomMessageEvent}, - Client, RoomState, + Client, Room, RoomState, }; use url::Url; -async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: room::Common, image: Vec) { +async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room, image: Vec) { if room.state() != RoomState::Joined { return; } diff --git a/examples/login/src/main.rs b/examples/login/src/main.rs index 95471f8e6..6912e48e6 100644 --- a/examples/login/src/main.rs +++ b/examples/login/src/main.rs @@ -8,12 +8,11 @@ use anyhow::anyhow; use matrix_sdk::{ self, config::SyncSettings, - room, ruma::{ api::client::session::get_login_types::v3::{IdentityProvider, LoginType}, events::room::message::{MessageType, OriginalSyncRoomMessageEvent}, }, - Client, RoomState, + Client, Room, RoomState, }; use url::Url; @@ -208,7 +207,7 @@ async fn login_with_sso(client: &Client, idp: Option<&IdentityProvider>) -> anyh } /// Handle room messages by logging them. -async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: room::Common) { +async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) { // We only want to listen to joined rooms. if room.state() != RoomState::Joined { return; diff --git a/examples/persist_session/src/main.rs b/examples/persist_session/src/main.rs index 32ff50ca8..4cb5d07b1 100644 --- a/examples/persist_session/src/main.rs +++ b/examples/persist_session/src/main.rs @@ -5,12 +5,11 @@ use std::{ use matrix_sdk::{ config::SyncSettings, - room, ruma::{ api::client::filter::FilterDefinition, events::room::message::{MessageType, OriginalSyncRoomMessageEvent}, }, - AuthSession, Client, Error, LoopCtrl, RoomState, + AuthSession, Client, Error, LoopCtrl, Room, RoomState, }; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use serde::{Deserialize, Serialize}; @@ -290,7 +289,7 @@ async fn persist_sync_token(session_file: &Path, sync_token: String) -> anyhow:: } /// Handle room messages. -async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: room::Common) { +async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) { // We only want to log text messages in joined rooms. if room.state() != RoomState::Joined { return; diff --git a/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs b/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs index a77bd55f7..01d84eb39 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/repeated_join.rs @@ -4,12 +4,11 @@ use anyhow::Result; use assign::assign; use matrix_sdk::{ event_handler::Ctx, - room, ruma::{ api::client::room::create_room::v3::Request as CreateRoomRequest, events::room::member::{MembershipState, StrippedRoomMemberEvent}, }, - Client, RoomMemberships, RoomState, StateStoreExt, + Client, Room, RoomMemberships, RoomState, StateStoreExt, }; use tokio::sync::Notify; @@ -120,7 +119,7 @@ async fn test_repeated_join_leave() -> Result<()> { async fn signal_on_invite( event: StrippedRoomMemberEvent, - room: room::Common, + room: Room, client: Client, sender: Ctx>, ) {