Skip to content

Commit 5068a0e

Browse files
committed
refactor(room): rename RequestToJoin and related code to JoinRequest
1 parent 848142a commit 5068a0e

File tree

9 files changed

+59
-61
lines changed

9 files changed

+59
-61
lines changed

bindings/matrix-sdk-ffi/src/room.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -889,11 +889,11 @@ impl Room {
889889
/// The current requests to join the room will be emitted immediately
890890
/// when subscribing, along with a [`TaskHandle`] to cancel the
891891
/// subscription.
892-
pub async fn subscribe_to_requests_to_join(
892+
pub async fn subscribe_to_join_requests(
893893
self: Arc<Self>,
894894
listener: Box<dyn RequestsToJoinListener>,
895895
) -> Result<Arc<TaskHandle>, ClientError> {
896-
let stream = self.inner.subscribe_to_requests_to_join().await?;
896+
let stream = self.inner.subscribe_to_join_requests().await?;
897897

898898
let handle = Arc::new(TaskHandle::new(RUNTIME.spawn(async move {
899899
pin_mut!(stream);
@@ -906,8 +906,8 @@ impl Room {
906906
}
907907
}
908908

909-
impl From<matrix_sdk::room::request_to_join::RequestToJoinRoom> for RequestToJoin {
910-
fn from(request: matrix_sdk::room::request_to_join::RequestToJoinRoom) -> Self {
909+
impl From<matrix_sdk::room::request_to_join::JoinRequest> for JoinRequest {
910+
fn from(request: matrix_sdk::room::request_to_join::JoinRequest) -> Self {
911911
Self {
912912
event_id: request.event_id.to_string(),
913913
user_id: request.member_info.user_id.to_string(),
@@ -917,20 +917,20 @@ impl From<matrix_sdk::room::request_to_join::RequestToJoinRoom> for RequestToJoi
917917
reason: request.member_info.reason.clone(),
918918
timestamp: request.timestamp.map(|ts| ts.into()),
919919
is_seen: request.is_seen,
920-
actions: Arc::new(RequestToJoinActions { inner: request }),
920+
actions: Arc::new(JoinRequestActions { inner: request }),
921921
}
922922
}
923923
}
924924

925925
/// A listener for receiving new requests to a join a room.
926926
#[matrix_sdk_ffi_macros::export(callback_interface)]
927927
pub trait RequestsToJoinListener: Send + Sync {
928-
fn call(&self, requests_to_join: Vec<RequestToJoin>);
928+
fn call(&self, join_requests: Vec<JoinRequest>);
929929
}
930930

931931
/// An FFI representation of a request to join a room.
932932
#[derive(Debug, Clone, uniffi::Record)]
933-
pub struct RequestToJoin {
933+
pub struct JoinRequest {
934934
/// The event id of the event that contains the `knock` membership change.
935935
pub event_id: String,
936936
/// The user id of the user who's requesting to join the room.
@@ -949,17 +949,17 @@ pub struct RequestToJoin {
949949
/// filtered by the client.
950950
pub is_seen: bool,
951951
/// A set of actions to perform for this request to join.
952-
pub actions: Arc<RequestToJoinActions>,
952+
pub actions: Arc<JoinRequestActions>,
953953
}
954954

955955
/// A set of actions to perform for a request to join.
956956
#[derive(Debug, Clone, uniffi::Object)]
957-
pub struct RequestToJoinActions {
958-
inner: matrix_sdk::room::request_to_join::RequestToJoinRoom,
957+
pub struct JoinRequestActions {
958+
inner: matrix_sdk::room::request_to_join::JoinRequest,
959959
}
960960

961961
#[matrix_sdk_ffi_macros::export]
962-
impl RequestToJoinActions {
962+
impl JoinRequestActions {
963963
/// Accepts the request to join by inviting the user to the room.
964964
pub async fn accept(&self) -> Result<(), ClientError> {
965965
self.inner.accept().await.map_err(Into::into)

crates/matrix-sdk-base/src/rooms/normal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub struct Room {
152152
pub latest_encrypted_events: Arc<SyncRwLock<RingBuffer<Raw<AnySyncTimelineEvent>>>>,
153153

154154
/// The event ids for seen request to join room events.
155-
pub seen_requests_to_join_ids: SharedObservable<Option<HashSet<OwnedEventId>>>,
155+
pub seen_join_request_ids: SharedObservable<Option<HashSet<OwnedEventId>>>,
156156
}
157157

158158
/// The room summary containing member counts and members that should be used to
@@ -275,7 +275,7 @@ impl Room {
275275
Self::MAX_ENCRYPTED_EVENTS,
276276
))),
277277
room_info_notable_update_sender,
278-
seen_requests_to_join_ids: SharedObservable::new(None),
278+
seen_join_request_ids: SharedObservable::new(None),
279279
}
280280
}
281281

crates/matrix-sdk-base/src/store/memory_store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ impl StateStore for MemoryStore {
187187
.get(room_id)
188188
.cloned()
189189
.map(StateStoreDataValue::ComposerDraft),
190-
StateStoreDataKey::SeenRequestsToJoin(room_id) => self
190+
StateStoreDataKey::SeenJoinRequests(room_id) => self
191191
.seen_requests_to_join
192192
.read()
193193
.unwrap()
194194
.get(room_id)
195195
.cloned()
196-
.map(StateStoreDataValue::SeenRequestsToJoin),
196+
.map(StateStoreDataValue::SeenJoinRequests),
197197
})
198198
}
199199

@@ -247,7 +247,7 @@ impl StateStore for MemoryStore {
247247
.expect("Session data not containing server capabilities"),
248248
);
249249
}
250-
StateStoreDataKey::SeenRequestsToJoin(room_id) => {
250+
StateStoreDataKey::SeenJoinRequests(room_id) => {
251251
self.seen_requests_to_join.write().unwrap().insert(
252252
room_id.to_owned(),
253253
value
@@ -281,7 +281,7 @@ impl StateStore for MemoryStore {
281281
StateStoreDataKey::ComposerDraft(room_id) => {
282282
self.composer_drafts.write().unwrap().remove(room_id);
283283
}
284-
StateStoreDataKey::SeenRequestsToJoin(room_id) => {
284+
StateStoreDataKey::SeenJoinRequests(room_id) => {
285285
self.seen_requests_to_join.write().unwrap().remove(room_id);
286286
}
287287
}

crates/matrix-sdk-base/src/store/traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ pub enum StateStoreDataValue {
10241024
ComposerDraft(ComposerDraft),
10251025

10261026
/// A list of requests to join marked as seen in a room.
1027-
SeenRequestsToJoin(HashSet<OwnedEventId>),
1027+
SeenJoinRequests(HashSet<OwnedEventId>),
10281028
}
10291029

10301030
/// Current draft of the composer for the room.
@@ -1094,7 +1094,7 @@ impl StateStoreDataValue {
10941094

10951095
/// Get this value if it is the data for the ignored join requests.
10961096
pub fn into_seen_join_requests(self) -> Option<HashSet<OwnedEventId>> {
1097-
as_variant!(self, Self::SeenRequestsToJoin)
1097+
as_variant!(self, Self::SeenJoinRequests)
10981098
}
10991099
}
11001100

@@ -1127,7 +1127,7 @@ pub enum StateStoreDataKey<'a> {
11271127
ComposerDraft(&'a RoomId),
11281128

11291129
/// A list of requests to join in a room marked as seen.
1130-
SeenRequestsToJoin(&'a RoomId),
1130+
SeenJoinRequests(&'a RoomId),
11311131
}
11321132

11331133
impl StateStoreDataKey<'_> {
@@ -1155,7 +1155,7 @@ impl StateStoreDataKey<'_> {
11551155
pub const COMPOSER_DRAFT: &'static str = "composer_draft";
11561156

11571157
/// Key prefix to use for the
1158-
/// [`SeenRequestsToJoin`][Self::SeenRequestsToJoin] variant.
1158+
/// [`SeenJoinRequests`][Self::SeenJoinRequests] variant.
11591159
pub const SEEN_REQUESTS_TO_JOIN: &'static str = "seen_requests_to_join";
11601160
}
11611161

crates/matrix-sdk-indexeddb/src/state_store/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl IndexeddbStateStore {
419419
StateStoreDataKey::ComposerDraft(room_id) => {
420420
self.encode_key(keys::KV, (StateStoreDataKey::COMPOSER_DRAFT, room_id))
421421
}
422-
StateStoreDataKey::SeenRequestsToJoin(room_id) => {
422+
StateStoreDataKey::SeenJoinRequests(room_id) => {
423423
self.encode_key(keys::KV, (StateStoreDataKey::SEEN_REQUESTS_TO_JOIN, room_id))
424424
}
425425
}
@@ -540,10 +540,10 @@ impl_state_store!({
540540
.map(|f| self.deserialize_value::<ComposerDraft>(&f))
541541
.transpose()?
542542
.map(StateStoreDataValue::ComposerDraft),
543-
StateStoreDataKey::SeenRequestsToJoin(_) => value
543+
StateStoreDataKey::SeenJoinRequests(_) => value
544544
.map(|f| self.deserialize_value::<HashSet<OwnedEventId>>(&f))
545545
.transpose()?
546-
.map(StateStoreDataValue::SeenRequestsToJoin),
546+
.map(StateStoreDataValue::SeenJoinRequests),
547547
};
548548

549549
Ok(value)
@@ -581,7 +581,7 @@ impl_state_store!({
581581
StateStoreDataKey::ComposerDraft(_) => self.serialize_value(
582582
&value.into_composer_draft().expect("Session data not a composer draft"),
583583
),
584-
StateStoreDataKey::SeenRequestsToJoin(_) => self.serialize_value(
584+
StateStoreDataKey::SeenJoinRequests(_) => self.serialize_value(
585585
&value
586586
.into_seen_join_requests()
587587
.expect("Session data not a set of ignored requests to join"),

crates/matrix-sdk-sqlite/src/state_store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl SqliteStateStore {
390390
StateStoreDataKey::ComposerDraft(room_id) => {
391391
Cow::Owned(format!("{}:{room_id}", StateStoreDataKey::COMPOSER_DRAFT))
392392
}
393-
StateStoreDataKey::SeenRequestsToJoin(room_id) => {
393+
StateStoreDataKey::SeenJoinRequests(room_id) => {
394394
Cow::Owned(format!("{}:{room_id}", StateStoreDataKey::SEEN_REQUESTS_TO_JOIN))
395395
}
396396
};
@@ -998,8 +998,8 @@ impl StateStore for SqliteStateStore {
998998
StateStoreDataKey::ComposerDraft(_) => {
999999
StateStoreDataValue::ComposerDraft(self.deserialize_value(&data)?)
10001000
}
1001-
StateStoreDataKey::SeenRequestsToJoin(_) => {
1002-
StateStoreDataValue::SeenRequestsToJoin(self.deserialize_value(&data)?)
1001+
StateStoreDataKey::SeenJoinRequests(_) => {
1002+
StateStoreDataValue::SeenJoinRequests(self.deserialize_value(&data)?)
10031003
}
10041004
})
10051005
})
@@ -1035,7 +1035,7 @@ impl StateStore for SqliteStateStore {
10351035
StateStoreDataKey::ComposerDraft(_) => self.serialize_value(
10361036
&value.into_composer_draft().expect("Session data not a composer draft"),
10371037
)?,
1038-
StateStoreDataKey::SeenRequestsToJoin(_) => self.serialize_value(
1038+
StateStoreDataKey::SeenJoinRequests(_) => self.serialize_value(
10391039
&value
10401040
.into_seen_join_requests()
10411041
.expect("Session data not a set of ignored requests to join"),

crates/matrix-sdk/src/room/mod.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ use crate::{
143143
notification_settings::{IsEncrypted, IsOneToOne, RoomNotificationMode},
144144
room::{
145145
power_levels::{RoomPowerLevelChanges, RoomPowerLevelsExt},
146-
request_to_join::RequestToJoinRoom,
146+
request_to_join::JoinRequest,
147147
},
148148
sync::RoomUpdate,
149149
utils::{IntoRawMessageLikeEventContent, IntoRawStateEventContent},
@@ -3210,20 +3210,18 @@ impl Room {
32103210

32113211
/// Helper to requests to join this `Room`. It returns both a list with the
32123212
/// initial items and any new request to join received.
3213-
pub async fn subscribe_to_requests_to_join(
3214-
&self,
3215-
) -> Result<impl Stream<Item = Vec<RequestToJoinRoom>>> {
3213+
pub async fn subscribe_to_join_requests(&self) -> Result<impl Stream<Item = Vec<JoinRequest>>> {
32163214
let this = Arc::new(self.clone());
32173215

32183216
let requests_observable =
32193217
this.client.observe_room_events::<SyncRoomMemberEvent, (Client, Room)>(this.room_id());
32203218

32213219
let (current_seen_ids, mut seen_request_ids_stream) =
3222-
this.subscribe_to_seen_requests_to_join_ids().await?;
3220+
this.subscribe_to_seen_join_request_ids().await?;
32233221

32243222
let combined_stream = stream! {
32253223
// Emit current requests to join
3226-
match this.clone().get_current_requests_to_join(&current_seen_ids).await {
3224+
match this.clone().get_current_join_requests(&current_seen_ids).await {
32273225
Ok(initial_requests) => yield initial_requests,
32283226
Err(e) => warn!("Failed to get initial requests to join: {e:?}")
32293227
}
@@ -3260,7 +3258,7 @@ impl Room {
32603258
MembershipChange::KnockAccepted |
32613259
MembershipChange::KnockDenied |
32623260
MembershipChange::KnockRetracted => {
3263-
match this.clone().get_current_requests_to_join(&seen_ids).await {
3261+
match this.clone().get_current_join_requests(&seen_ids).await {
32643262
Ok(requests) => yield requests,
32653263
Err(e) => {
32663264
warn!("Failed to get updated requests to join on membership change: {e:?}")
@@ -3272,7 +3270,7 @@ impl Room {
32723270
} else {
32733271
// If we can't calculate the membership change, assume we need to
32743272
// emit updated values
3275-
match this.clone().get_current_requests_to_join(&seen_ids).await {
3273+
match this.clone().get_current_join_requests(&seen_ids).await {
32763274
Ok(requests) => yield requests,
32773275
Err(e) => {
32783276
warn!("Failed to get updated requests to join on new member event: {e:?}")
@@ -3282,7 +3280,7 @@ impl Room {
32823280
} else if has_new_seen_ids {
32833281
// If seen requests have changed, we need to recalculate all the
32843282
// requests to join
3285-
match this.clone().get_current_requests_to_join(&seen_ids).await {
3283+
match this.clone().get_current_join_requests(&seen_ids).await {
32863284
Ok(requests) => yield requests,
32873285
Err(e) => {
32883286
warn!("Failed to get updated requests to join on seen ids changed: {e:?}")
@@ -3295,18 +3293,18 @@ impl Room {
32953293
Ok(combined_stream)
32963294
}
32973295

3298-
async fn get_current_requests_to_join(
3296+
async fn get_current_join_requests(
32993297
self: Arc<Self>,
33003298
seen_request_ids: &HashSet<OwnedEventId>,
3301-
) -> Result<Vec<RequestToJoinRoom>> {
3299+
) -> Result<Vec<JoinRequest>> {
33023300
Ok(self
33033301
.members(RoomMemberships::KNOCK)
33043302
.await?
33053303
.into_iter()
33063304
.filter_map(|member| {
33073305
if let Some(event_id) = member.event().event_id() {
33083306
let event_id = event_id.to_owned();
3309-
Some(RequestToJoinRoom::new(
3307+
Some(JoinRequest::new(
33103308
self.clone(),
33113309
&event_id,
33123310
member.event().timestamp(),
@@ -3322,54 +3320,54 @@ impl Room {
33223320

33233321
/// Mark a list of requests to join the room as seen, given their state
33243322
/// event ids.
3325-
pub async fn mark_requests_to_join_as_seen(&self, event_ids: &[OwnedEventId]) -> Result<()> {
3326-
let mut current_seen_events = self.get_seen_requests_to_join_ids().await?;
3323+
pub async fn mark_join_requests_as_seen(&self, event_ids: &[OwnedEventId]) -> Result<()> {
3324+
let mut current_seen_events = self.get_seen_join_requests().await?;
33273325

33283326
for event_id in event_ids {
33293327
current_seen_events.insert(event_id.to_owned());
33303328
}
33313329

3332-
self.seen_requests_to_join_ids.set(Some(current_seen_events.clone()));
3330+
self.seen_join_request_ids.set(Some(current_seen_events.clone()));
33333331

33343332
self.client
33353333
.store()
33363334
.set_kv_data(
3337-
StateStoreDataKey::SeenRequestsToJoin(self.room_id()),
3338-
StateStoreDataValue::SeenRequestsToJoin(current_seen_events),
3335+
StateStoreDataKey::SeenJoinRequests(self.room_id()),
3336+
StateStoreDataValue::SeenJoinRequests(current_seen_events),
33393337
)
33403338
.await
33413339
.map_err(Into::into)
33423340
}
33433341

33443342
/// Get the list of seen requests to join event ids in this room.
3345-
pub async fn get_seen_requests_to_join_ids(&self) -> Result<HashSet<OwnedEventId>> {
3346-
let current_requests_to_join_ids = self.seen_requests_to_join_ids.get();
3347-
let current_requests_to_join_ids: HashSet<OwnedEventId> =
3348-
if let Some(requests) = current_requests_to_join_ids.as_ref() {
3343+
pub async fn get_seen_join_requests(&self) -> Result<HashSet<OwnedEventId>> {
3344+
let current_join_request_ids = self.seen_join_request_ids.get();
3345+
let current_join_request_ids: HashSet<OwnedEventId> =
3346+
if let Some(requests) = current_join_request_ids.as_ref() {
33493347
requests.clone()
33503348
} else {
33513349
let requests = self
33523350
.client
33533351
.store()
3354-
.get_kv_data(StateStoreDataKey::SeenRequestsToJoin(self.room_id()))
3352+
.get_kv_data(StateStoreDataKey::SeenJoinRequests(self.room_id()))
33553353
.await?
33563354
.and_then(|v| v.into_seen_join_requests())
33573355
.unwrap_or_default();
33583356

3359-
self.seen_requests_to_join_ids.set(Some(requests.clone()));
3357+
self.seen_join_request_ids.set(Some(requests.clone()));
33603358
requests
33613359
};
3362-
Ok(current_requests_to_join_ids)
3360+
Ok(current_join_request_ids)
33633361
}
33643362

33653363
/// Subscribes to the set of requests to join that have been marked as
33663364
/// 'seen'.
3367-
pub async fn subscribe_to_seen_requests_to_join_ids(
3365+
pub async fn subscribe_to_seen_join_request_ids(
33683366
&self,
33693367
) -> Result<(HashSet<OwnedEventId>, impl Stream<Item = HashSet<OwnedEventId>>)> {
3370-
let current = self.get_seen_requests_to_join_ids().await?;
3368+
let current = self.get_seen_join_requests().await?;
33713369
let subscriber =
3372-
self.seen_requests_to_join_ids.subscribe().map(|values| values.unwrap_or_default());
3370+
self.seen_join_request_ids.subscribe().map(|values| values.unwrap_or_default());
33733371
Ok((current, subscriber))
33743372
}
33753373
}

crates/matrix-sdk/src/room/request_to_join.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{room::RoomMember, Error, Room};
77

88
/// A request to join a room with `knock` join rule.
99
#[derive(Debug, Clone)]
10-
pub struct RequestToJoinRoom {
10+
pub struct JoinRequest {
1111
room: Arc<Room>,
1212
/// The event id of the event containing knock membership change.
1313
pub event_id: OwnedEventId,
@@ -19,7 +19,7 @@ pub struct RequestToJoinRoom {
1919
pub is_seen: bool,
2020
}
2121

22-
impl RequestToJoinRoom {
22+
impl JoinRequest {
2323
pub(crate) fn new(
2424
room: Arc<Room>,
2525
event_id: &EventId,
@@ -38,7 +38,7 @@ impl RequestToJoinRoom {
3838
/// Marks the request to join as 'seen' so the client can ignore it in the
3939
/// future.
4040
pub async fn mark_as_seen(&mut self) -> Result<(), Error> {
41-
self.room.mark_requests_to_join_as_seen(&[self.event_id.to_owned()]).await?;
41+
self.room.mark_join_requests_as_seen(&[self.event_id.to_owned()]).await?;
4242
Ok(())
4343
}
4444

0 commit comments

Comments
 (0)