diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 685aea56c72..1b36a6a99ed 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -889,11 +889,11 @@ impl Room { /// The current requests to join the room will be emitted immediately /// when subscribing, along with a [`TaskHandle`] to cancel the /// subscription. - pub async fn subscribe_to_requests_to_join( + pub async fn subscribe_to_join_requests( self: Arc, listener: Box, ) -> Result, ClientError> { - let stream = self.inner.subscribe_to_requests_to_join().await?; + let stream = self.inner.subscribe_to_join_requests().await?; let handle = Arc::new(TaskHandle::new(RUNTIME.spawn(async move { pin_mut!(stream); @@ -906,8 +906,8 @@ impl Room { } } -impl From for RequestToJoin { - fn from(request: matrix_sdk::room::request_to_join::RequestToJoinRoom) -> Self { +impl From for JoinRequest { + fn from(request: matrix_sdk::room::request_to_join::JoinRequest) -> Self { Self { event_id: request.event_id.to_string(), user_id: request.member_info.user_id.to_string(), @@ -917,7 +917,7 @@ impl From for RequestToJoi reason: request.member_info.reason.clone(), timestamp: request.timestamp.map(|ts| ts.into()), is_seen: request.is_seen, - actions: Arc::new(RequestToJoinActions { inner: request }), + actions: Arc::new(JoinRequestActions { inner: request }), } } } @@ -925,12 +925,12 @@ impl From for RequestToJoi /// A listener for receiving new requests to a join a room. #[matrix_sdk_ffi_macros::export(callback_interface)] pub trait RequestsToJoinListener: Send + Sync { - fn call(&self, requests_to_join: Vec); + fn call(&self, join_requests: Vec); } /// An FFI representation of a request to join a room. #[derive(Debug, Clone, uniffi::Record)] -pub struct RequestToJoin { +pub struct JoinRequest { /// The event id of the event that contains the `knock` membership change. pub event_id: String, /// The user id of the user who's requesting to join the room. @@ -949,17 +949,17 @@ pub struct RequestToJoin { /// filtered by the client. pub is_seen: bool, /// A set of actions to perform for this request to join. - pub actions: Arc, + pub actions: Arc, } /// A set of actions to perform for a request to join. #[derive(Debug, Clone, uniffi::Object)] -pub struct RequestToJoinActions { - inner: matrix_sdk::room::request_to_join::RequestToJoinRoom, +pub struct JoinRequestActions { + inner: matrix_sdk::room::request_to_join::JoinRequest, } #[matrix_sdk_ffi_macros::export] -impl RequestToJoinActions { +impl JoinRequestActions { /// Accepts the request to join by inviting the user to the room. pub async fn accept(&self) -> Result<(), ClientError> { self.inner.accept().await.map_err(Into::into) diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index 92d7d3dae31..ed61badf8d8 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -152,7 +152,7 @@ pub struct Room { pub latest_encrypted_events: Arc>>>, /// The event ids for seen request to join room events. - pub seen_requests_to_join_ids: SharedObservable>>, + pub seen_join_request_ids: SharedObservable>>, } /// The room summary containing member counts and members that should be used to @@ -275,7 +275,7 @@ impl Room { Self::MAX_ENCRYPTED_EVENTS, ))), room_info_notable_update_sender, - seen_requests_to_join_ids: SharedObservable::new(None), + seen_join_request_ids: SharedObservable::new(None), } } diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index fafb1afa307..a262fe694a5 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -187,13 +187,13 @@ impl StateStore for MemoryStore { .get(room_id) .cloned() .map(StateStoreDataValue::ComposerDraft), - StateStoreDataKey::SeenRequestsToJoin(room_id) => self + StateStoreDataKey::SeenJoinRequests(room_id) => self .seen_requests_to_join .read() .unwrap() .get(room_id) .cloned() - .map(StateStoreDataValue::SeenRequestsToJoin), + .map(StateStoreDataValue::SeenJoinRequests), }) } @@ -247,7 +247,7 @@ impl StateStore for MemoryStore { .expect("Session data not containing server capabilities"), ); } - StateStoreDataKey::SeenRequestsToJoin(room_id) => { + StateStoreDataKey::SeenJoinRequests(room_id) => { self.seen_requests_to_join.write().unwrap().insert( room_id.to_owned(), value @@ -281,7 +281,7 @@ impl StateStore for MemoryStore { StateStoreDataKey::ComposerDraft(room_id) => { self.composer_drafts.write().unwrap().remove(room_id); } - StateStoreDataKey::SeenRequestsToJoin(room_id) => { + StateStoreDataKey::SeenJoinRequests(room_id) => { self.seen_requests_to_join.write().unwrap().remove(room_id); } } diff --git a/crates/matrix-sdk-base/src/store/traits.rs b/crates/matrix-sdk-base/src/store/traits.rs index 8653eb969f1..8c004637924 100644 --- a/crates/matrix-sdk-base/src/store/traits.rs +++ b/crates/matrix-sdk-base/src/store/traits.rs @@ -1024,7 +1024,7 @@ pub enum StateStoreDataValue { ComposerDraft(ComposerDraft), /// A list of requests to join marked as seen in a room. - SeenRequestsToJoin(HashSet), + SeenJoinRequests(HashSet), } /// Current draft of the composer for the room. @@ -1094,7 +1094,7 @@ impl StateStoreDataValue { /// Get this value if it is the data for the ignored join requests. pub fn into_seen_join_requests(self) -> Option> { - as_variant!(self, Self::SeenRequestsToJoin) + as_variant!(self, Self::SeenJoinRequests) } } @@ -1127,7 +1127,7 @@ pub enum StateStoreDataKey<'a> { ComposerDraft(&'a RoomId), /// A list of requests to join in a room marked as seen. - SeenRequestsToJoin(&'a RoomId), + SeenJoinRequests(&'a RoomId), } impl StateStoreDataKey<'_> { @@ -1155,7 +1155,7 @@ impl StateStoreDataKey<'_> { pub const COMPOSER_DRAFT: &'static str = "composer_draft"; /// Key prefix to use for the - /// [`SeenRequestsToJoin`][Self::SeenRequestsToJoin] variant. + /// [`SeenJoinRequests`][Self::SeenJoinRequests] variant. pub const SEEN_REQUESTS_TO_JOIN: &'static str = "seen_requests_to_join"; } diff --git a/crates/matrix-sdk-indexeddb/src/state_store/mod.rs b/crates/matrix-sdk-indexeddb/src/state_store/mod.rs index ed1d06aeba5..f15434de5c4 100644 --- a/crates/matrix-sdk-indexeddb/src/state_store/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/state_store/mod.rs @@ -419,7 +419,7 @@ impl IndexeddbStateStore { StateStoreDataKey::ComposerDraft(room_id) => { self.encode_key(keys::KV, (StateStoreDataKey::COMPOSER_DRAFT, room_id)) } - StateStoreDataKey::SeenRequestsToJoin(room_id) => { + StateStoreDataKey::SeenJoinRequests(room_id) => { self.encode_key(keys::KV, (StateStoreDataKey::SEEN_REQUESTS_TO_JOIN, room_id)) } } @@ -540,10 +540,10 @@ impl_state_store!({ .map(|f| self.deserialize_value::(&f)) .transpose()? .map(StateStoreDataValue::ComposerDraft), - StateStoreDataKey::SeenRequestsToJoin(_) => value + StateStoreDataKey::SeenJoinRequests(_) => value .map(|f| self.deserialize_value::>(&f)) .transpose()? - .map(StateStoreDataValue::SeenRequestsToJoin), + .map(StateStoreDataValue::SeenJoinRequests), }; Ok(value) @@ -581,7 +581,7 @@ impl_state_store!({ StateStoreDataKey::ComposerDraft(_) => self.serialize_value( &value.into_composer_draft().expect("Session data not a composer draft"), ), - StateStoreDataKey::SeenRequestsToJoin(_) => self.serialize_value( + StateStoreDataKey::SeenJoinRequests(_) => self.serialize_value( &value .into_seen_join_requests() .expect("Session data not a set of ignored requests to join"), diff --git a/crates/matrix-sdk-sqlite/src/state_store.rs b/crates/matrix-sdk-sqlite/src/state_store.rs index 618fa9201c5..df864ea45f7 100644 --- a/crates/matrix-sdk-sqlite/src/state_store.rs +++ b/crates/matrix-sdk-sqlite/src/state_store.rs @@ -390,7 +390,7 @@ impl SqliteStateStore { StateStoreDataKey::ComposerDraft(room_id) => { Cow::Owned(format!("{}:{room_id}", StateStoreDataKey::COMPOSER_DRAFT)) } - StateStoreDataKey::SeenRequestsToJoin(room_id) => { + StateStoreDataKey::SeenJoinRequests(room_id) => { Cow::Owned(format!("{}:{room_id}", StateStoreDataKey::SEEN_REQUESTS_TO_JOIN)) } }; @@ -998,8 +998,8 @@ impl StateStore for SqliteStateStore { StateStoreDataKey::ComposerDraft(_) => { StateStoreDataValue::ComposerDraft(self.deserialize_value(&data)?) } - StateStoreDataKey::SeenRequestsToJoin(_) => { - StateStoreDataValue::SeenRequestsToJoin(self.deserialize_value(&data)?) + StateStoreDataKey::SeenJoinRequests(_) => { + StateStoreDataValue::SeenJoinRequests(self.deserialize_value(&data)?) } }) }) @@ -1035,7 +1035,7 @@ impl StateStore for SqliteStateStore { StateStoreDataKey::ComposerDraft(_) => self.serialize_value( &value.into_composer_draft().expect("Session data not a composer draft"), )?, - StateStoreDataKey::SeenRequestsToJoin(_) => self.serialize_value( + StateStoreDataKey::SeenJoinRequests(_) => self.serialize_value( &value .into_seen_join_requests() .expect("Session data not a set of ignored requests to join"), diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index d045531d2f3..d8be71a1d87 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -143,7 +143,7 @@ use crate::{ notification_settings::{IsEncrypted, IsOneToOne, RoomNotificationMode}, room::{ power_levels::{RoomPowerLevelChanges, RoomPowerLevelsExt}, - request_to_join::RequestToJoinRoom, + request_to_join::JoinRequest, }, sync::RoomUpdate, utils::{IntoRawMessageLikeEventContent, IntoRawStateEventContent}, @@ -3210,20 +3210,18 @@ impl Room { /// Helper to requests to join this `Room`. It returns both a list with the /// initial items and any new request to join received. - pub async fn subscribe_to_requests_to_join( - &self, - ) -> Result>> { + pub async fn subscribe_to_join_requests(&self) -> Result>> { let this = Arc::new(self.clone()); let requests_observable = this.client.observe_room_events::(this.room_id()); let (current_seen_ids, mut seen_request_ids_stream) = - this.subscribe_to_seen_requests_to_join_ids().await?; + this.subscribe_to_seen_join_request_ids().await?; let combined_stream = stream! { // Emit current requests to join - match this.clone().get_current_requests_to_join(¤t_seen_ids).await { + match this.clone().get_current_join_requests(¤t_seen_ids).await { Ok(initial_requests) => yield initial_requests, Err(e) => warn!("Failed to get initial requests to join: {e:?}") } @@ -3260,7 +3258,7 @@ impl Room { MembershipChange::KnockAccepted | MembershipChange::KnockDenied | MembershipChange::KnockRetracted => { - match this.clone().get_current_requests_to_join(&seen_ids).await { + match this.clone().get_current_join_requests(&seen_ids).await { Ok(requests) => yield requests, Err(e) => { warn!("Failed to get updated requests to join on membership change: {e:?}") @@ -3272,7 +3270,7 @@ impl Room { } else { // If we can't calculate the membership change, assume we need to // emit updated values - match this.clone().get_current_requests_to_join(&seen_ids).await { + match this.clone().get_current_join_requests(&seen_ids).await { Ok(requests) => yield requests, Err(e) => { warn!("Failed to get updated requests to join on new member event: {e:?}") @@ -3282,7 +3280,7 @@ impl Room { } else if has_new_seen_ids { // If seen requests have changed, we need to recalculate all the // requests to join - match this.clone().get_current_requests_to_join(&seen_ids).await { + match this.clone().get_current_join_requests(&seen_ids).await { Ok(requests) => yield requests, Err(e) => { warn!("Failed to get updated requests to join on seen ids changed: {e:?}") @@ -3295,10 +3293,10 @@ impl Room { Ok(combined_stream) } - async fn get_current_requests_to_join( + async fn get_current_join_requests( self: Arc, seen_request_ids: &HashSet, - ) -> Result> { + ) -> Result> { Ok(self .members(RoomMemberships::KNOCK) .await? @@ -3306,7 +3304,7 @@ impl Room { .filter_map(|member| { if let Some(event_id) = member.event().event_id() { let event_id = event_id.to_owned(); - Some(RequestToJoinRoom::new( + Some(JoinRequest::new( self.clone(), &event_id, member.event().timestamp(), @@ -3322,54 +3320,54 @@ impl Room { /// Mark a list of requests to join the room as seen, given their state /// event ids. - pub async fn mark_requests_to_join_as_seen(&self, event_ids: &[OwnedEventId]) -> Result<()> { - let mut current_seen_events = self.get_seen_requests_to_join_ids().await?; + pub async fn mark_join_requests_as_seen(&self, event_ids: &[OwnedEventId]) -> Result<()> { + let mut current_seen_events = self.get_seen_join_requests().await?; for event_id in event_ids { current_seen_events.insert(event_id.to_owned()); } - self.seen_requests_to_join_ids.set(Some(current_seen_events.clone())); + self.seen_join_request_ids.set(Some(current_seen_events.clone())); self.client .store() .set_kv_data( - StateStoreDataKey::SeenRequestsToJoin(self.room_id()), - StateStoreDataValue::SeenRequestsToJoin(current_seen_events), + StateStoreDataKey::SeenJoinRequests(self.room_id()), + StateStoreDataValue::SeenJoinRequests(current_seen_events), ) .await .map_err(Into::into) } /// Get the list of seen requests to join event ids in this room. - pub async fn get_seen_requests_to_join_ids(&self) -> Result> { - let current_requests_to_join_ids = self.seen_requests_to_join_ids.get(); - let current_requests_to_join_ids: HashSet = - if let Some(requests) = current_requests_to_join_ids.as_ref() { + pub async fn get_seen_join_requests(&self) -> Result> { + let current_join_request_ids = self.seen_join_request_ids.get(); + let current_join_request_ids: HashSet = + if let Some(requests) = current_join_request_ids.as_ref() { requests.clone() } else { let requests = self .client .store() - .get_kv_data(StateStoreDataKey::SeenRequestsToJoin(self.room_id())) + .get_kv_data(StateStoreDataKey::SeenJoinRequests(self.room_id())) .await? .and_then(|v| v.into_seen_join_requests()) .unwrap_or_default(); - self.seen_requests_to_join_ids.set(Some(requests.clone())); + self.seen_join_request_ids.set(Some(requests.clone())); requests }; - Ok(current_requests_to_join_ids) + Ok(current_join_request_ids) } /// Subscribes to the set of requests to join that have been marked as /// 'seen'. - pub async fn subscribe_to_seen_requests_to_join_ids( + pub async fn subscribe_to_seen_join_request_ids( &self, ) -> Result<(HashSet, impl Stream>)> { - let current = self.get_seen_requests_to_join_ids().await?; + let current = self.get_seen_join_requests().await?; let subscriber = - self.seen_requests_to_join_ids.subscribe().map(|values| values.unwrap_or_default()); + self.seen_join_request_ids.subscribe().map(|values| values.unwrap_or_default()); Ok((current, subscriber)) } } diff --git a/crates/matrix-sdk/src/room/request_to_join.rs b/crates/matrix-sdk/src/room/request_to_join.rs index 8ad054418b7..2b1f5975937 100644 --- a/crates/matrix-sdk/src/room/request_to_join.rs +++ b/crates/matrix-sdk/src/room/request_to_join.rs @@ -7,7 +7,7 @@ use crate::{room::RoomMember, Error, Room}; /// A request to join a room with `knock` join rule. #[derive(Debug, Clone)] -pub struct RequestToJoinRoom { +pub struct JoinRequest { room: Arc, /// The event id of the event containing knock membership change. pub event_id: OwnedEventId, @@ -19,7 +19,7 @@ pub struct RequestToJoinRoom { pub is_seen: bool, } -impl RequestToJoinRoom { +impl JoinRequest { pub(crate) fn new( room: Arc, event_id: &EventId, @@ -38,7 +38,7 @@ impl RequestToJoinRoom { /// Marks the request to join as 'seen' so the client can ignore it in the /// future. pub async fn mark_as_seen(&mut self) -> Result<(), Error> { - self.room.mark_requests_to_join_as_seen(&[self.event_id.to_owned()]).await?; + self.room.mark_join_requests_as_seen(&[self.event_id.to_owned()]).await?; Ok(()) } diff --git a/crates/matrix-sdk/tests/integration/room/joined.rs b/crates/matrix-sdk/tests/integration/room/joined.rs index 6671af609ea..2652f5bcde5 100644 --- a/crates/matrix-sdk/tests/integration/room/joined.rs +++ b/crates/matrix-sdk/tests/integration/room/joined.rs @@ -861,7 +861,7 @@ async fn test_subscribe_to_requests_to_join() { server.mock_get_members().ok(vec![alice_knock_event]).mock_once().mount().await; let room = server.sync_joined_room(&client, room_id).await; - let stream = room.subscribe_to_requests_to_join().await.unwrap(); + let stream = room.subscribe_to_join_requests().await.unwrap(); pin_mut!(stream); @@ -874,7 +874,7 @@ async fn test_subscribe_to_requests_to_join() { assert!(!alices_request_to_join.is_seen); // We then mark the request to join as seen - room.mark_requests_to_join_as_seen(&[alice_knock_event_id.to_owned()]).await.unwrap(); + room.mark_join_requests_as_seen(&[alice_knock_event_id.to_owned()]).await.unwrap(); // Now it's received again as seen let seen = assert_next_with_timeout!(stream, 100);