From 429fe7b2151069825e11d095006af52a398531da Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 6 Jun 2024 18:13:21 +0200 Subject: [PATCH] sdk: finish renaming "sending queue" to "send queue" --- bindings/matrix-sdk-ffi/src/client.rs | 10 ++-- crates/matrix-sdk-ui/src/timeline/builder.rs | 2 +- crates/matrix-sdk-ui/src/timeline/mod.rs | 2 +- .../tests/integration/timeline/echo.rs | 6 +-- .../tests/integration/timeline/queue.rs | 2 +- crates/matrix-sdk/src/client/builder.rs | 4 +- crates/matrix-sdk/src/client/mod.rs | 8 ++-- crates/matrix-sdk/src/send_queue.rs | 24 +++++----- .../tests/integration/send_queue.rs | 48 +++++++++---------- labs/multiverse/src/main.rs | 2 +- 10 files changed, 53 insertions(+), 55 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 93b76638e14..f5f845d2755 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -321,11 +321,11 @@ impl Client { /// event with it failed (e.g., sending an event via the high-level Timeline /// object), so it's required to manually re-enable it as soon as /// connectivity is back on the device. - pub fn enable_sending_queue(&self, enable: bool) { + pub fn enable_send_queue(&self, enable: bool) { if enable { - self.inner.sending_queue().enable(); + self.inner.send_queue().enable(); } else { - self.inner.sending_queue().disable(); + self.inner.send_queue().disable(); } } @@ -334,11 +334,11 @@ impl Client { /// /// The given listener will be immediately called with the initial value of /// the enablement status. - pub fn subscribe_to_sending_queue_status( + pub fn subscribe_to_send_queue_status( &self, listener: Box, ) -> Arc { - let mut subscriber = self.inner.sending_queue().subscribe_status(); + let mut subscriber = self.inner.send_queue().subscribe_status(); Arc::new(TaskHandle::new(RUNTIME.spawn(async move { // Call with the initial value. diff --git a/crates/matrix-sdk-ui/src/timeline/builder.rs b/crates/matrix-sdk-ui/src/timeline/builder.rs index e206b3e2dde..a8dc3d7b850 100644 --- a/crates/matrix-sdk-ui/src/timeline/builder.rs +++ b/crates/matrix-sdk-ui/src/timeline/builder.rs @@ -269,7 +269,7 @@ impl TimelineBuilder { let local_echo_listener_handle = if is_live { Some(spawn({ let timeline = inner.clone(); - let (local_echoes, mut listener) = room.sending_queue().subscribe().await; + let (local_echoes, mut listener) = room.send_queue().subscribe().await; // Handles existing local echoes first. for echo in local_echoes { diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index d10ee267a56..3f30474f772 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -301,7 +301,7 @@ impl Timeline { &self, content: AnyMessageLikeEventContent, ) -> Result { - self.room().sending_queue().send(content).await + self.room().send_queue().send(content).await } /// Send a reply to the given event. diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs b/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs index e52b6a4991b..5bd47e8b88e 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/echo.rs @@ -142,7 +142,7 @@ async fn test_retry_failed() { mock_encryption_state(&server, false).await; - client.sending_queue().enable(); + client.send_queue().enable(); let room = client.get_room(room_id).unwrap(); let timeline = Arc::new(room.timeline().await.unwrap()); @@ -173,9 +173,9 @@ async fn test_retry_failed() { .mount(&server) .await; - assert!(!client.sending_queue().is_enabled()); + assert!(!client.send_queue().is_enabled()); - client.sending_queue().enable(); + client.send_queue().enable(); // Let the send queue handle the event. tokio::time::sleep(Duration::from_millis(300)).await; diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs b/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs index 6f4c36b5111..42c3efcc032 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs @@ -182,7 +182,7 @@ async fn test_retry_order() { .await; // Retry the second message first - client.sending_queue().enable(); + client.send_queue().enable(); // Wait 200ms for the first msg, 100ms for the second, 300ms for overhead sleep(Duration::from_millis(600)).await; diff --git a/crates/matrix-sdk/src/client/builder.rs b/crates/matrix-sdk/src/client/builder.rs index 2505ae74ce2..5e64971db5e 100644 --- a/crates/matrix-sdk/src/client/builder.rs +++ b/crates/matrix-sdk/src/client/builder.rs @@ -453,7 +453,7 @@ impl ClientBuilder { }); let event_cache = OnceCell::new(); - let sending_queue = Arc::new(SendQueueData::new(true)); + let send_queue = Arc::new(SendQueueData::new(true)); let inner = ClientInner::new( auth_ctx, homeserver, @@ -465,7 +465,7 @@ impl ClientBuilder { None, self.respect_login_well_known, event_cache, - sending_queue, + send_queue, #[cfg(feature = "e2e-encryption")] self.encryption_settings, ) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 904edba31eb..af3c6e37ec9 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -287,7 +287,7 @@ pub(crate) struct ClientInner { /// Data related to the [`SendQueue`]. /// /// [`SendQueue`]: crate::send_queue::SendQueue - pub(crate) sending_queue_data: Arc, + pub(crate) send_queue_data: Arc, } impl ClientInner { @@ -307,7 +307,7 @@ impl ClientInner { unstable_features: Option>, respect_login_well_known: bool, event_cache: OnceCell, - sending_queue: Arc, + send_queue: Arc, #[cfg(feature = "e2e-encryption")] encryption_settings: EncryptionSettings, ) -> Arc { let client = Self { @@ -330,7 +330,7 @@ impl ClientInner { respect_login_well_known, sync_beat: event_listener::Event::new(), event_cache, - sending_queue_data: sending_queue, + send_queue_data: send_queue, #[cfg(feature = "e2e-encryption")] e2ee: EncryptionData::new(encryption_settings), #[cfg(feature = "e2e-encryption")] @@ -2110,7 +2110,7 @@ impl Client { self.inner.unstable_features.get().cloned(), self.inner.respect_login_well_known, self.inner.event_cache.clone(), - self.inner.sending_queue_data.clone(), + self.inner.send_queue_data.clone(), #[cfg(feature = "e2e-encryption")] self.inner.e2ee.encryption_settings, ) diff --git a/crates/matrix-sdk/src/send_queue.rs b/crates/matrix-sdk/src/send_queue.rs index 22e41e9b1a1..8fddb7498c8 100644 --- a/crates/matrix-sdk/src/send_queue.rs +++ b/crates/matrix-sdk/src/send_queue.rs @@ -52,7 +52,7 @@ impl SendQueue { } fn for_room(&self, room: Room) -> RoomSendQueue { - let data = &self.client.inner.sending_queue_data; + let data = &self.client.inner.send_queue_data; let mut map = data.rooms.write().unwrap(); @@ -77,9 +77,9 @@ impl SendQueue { /// This may wake up background tasks and resume sending of events in the /// background. pub fn enable(&self) { - if self.client.inner.sending_queue_data.globally_enabled.set_if_not_eq(true).is_some() { + if self.client.inner.send_queue_data.globally_enabled.set_if_not_eq(true).is_some() { debug!("globally enabling send queue"); - let rooms = self.client.inner.sending_queue_data.rooms.read().unwrap(); + let rooms = self.client.inner.send_queue_data.rooms.read().unwrap(); // Wake up the rooms, in case events have been queued in the meanwhile. for room in rooms.values() { room.inner.notifier.notify_one(); @@ -101,26 +101,26 @@ impl SendQueue { // - or they were not, and it's not worth it waking them to let them they're // disabled, which causes them to go to sleep again. debug!("globally disabling send queue"); - self.client.inner.sending_queue_data.globally_enabled.set(false); + self.client.inner.send_queue_data.globally_enabled.set(false); } /// Returns whether the send queue is enabled, at a client-wide /// granularity. pub fn is_enabled(&self) -> bool { - self.client.inner.sending_queue_data.globally_enabled.get() + self.client.inner.send_queue_data.globally_enabled.get() } /// A subscriber to the enablement status (enabled or disabled) of the /// send queue. pub fn subscribe_status(&self) -> Subscriber { - self.client.inner.sending_queue_data.globally_enabled.subscribe() + self.client.inner.send_queue_data.globally_enabled.subscribe() } } impl Client { /// Returns a [`SendQueue`] that handles sending, retrying and not /// forgetting about messages that are to be sent. - pub fn sending_queue(&self) -> SendQueue { + pub fn send_queue(&self) -> SendQueue { SendQueue::new(self.clone()) } } @@ -163,8 +163,8 @@ impl Drop for SendQueueData { impl Room { /// Returns the [`RoomSendQueue`] for this specific room. - pub fn sending_queue(&self) -> RoomSendQueue { - self.client.sending_queue().for_room(self.clone()) + pub fn send_queue(&self) -> RoomSendQueue { + self.client.send_queue().for_room(self.clone()) } } @@ -620,14 +620,14 @@ mod tests { .unwrap(); let room = client.get_room(room_id).unwrap(); - let q = room.sending_queue(); + let q = room.send_queue(); let _watcher = q.subscribe().await; if enabled { - client.sending_queue().enable(); + client.send_queue().enable(); } else { - client.sending_queue().disable(); + client.send_queue().disable(); } } diff --git a/crates/matrix-sdk/tests/integration/send_queue.rs b/crates/matrix-sdk/tests/integration/send_queue.rs index e9e974d85ab..342ef57d239 100644 --- a/crates/matrix-sdk/tests/integration/send_queue.rs +++ b/crates/matrix-sdk/tests/integration/send_queue.rs @@ -49,9 +49,7 @@ async fn test_cant_send_invited_room() { // I can't send message to it with the send queue. assert_matches!( - room.sending_queue() - .send(RoomMessageEventContent::text_plain("Hello, World!").into()) - .await, + room.send_queue().send(RoomMessageEventContent::text_plain("Hello, World!").into()).await, Err(RoomSendQueueError::RoomNotJoined) ); } @@ -75,7 +73,7 @@ async fn test_cant_send_left_room() { // I can't send message to it with the send queue. assert_matches!( - room.sending_queue() + room.send_queue() .send(RoomMessageEventContent::text_plain("Farewell, World!").into()) .await, Err(RoomSendQueueError::RoomNotJoined) @@ -103,10 +101,10 @@ async fn test_nothing_sent_when_disabled() { let event_id = event_id!("$1"); mock_send_event(event_id).expect(0).mount(&server).await; - client.sending_queue().disable(); + client.send_queue().disable(); // A message is queued, but never sent. - room.sending_queue() + room.send_queue() .send(RoomMessageEventContent::text_plain("Hello, World!").into()) .await .unwrap(); @@ -139,7 +137,7 @@ async fn test_smoke() { ) .await; - let q = room.sending_queue(); + let q = room.send_queue(); let (local_echoes, mut watch) = q.subscribe().await; assert!(local_echoes.is_empty()); @@ -177,7 +175,7 @@ async fn test_smoke() { .mount(&server) .await; - room.sending_queue().send(RoomMessageEventContent::text_plain("1").into()).await.unwrap(); + room.send_queue().send(RoomMessageEventContent::text_plain("1").into()).await.unwrap(); assert_let!( Ok(Ok(RoomSendQueueUpdate::NewLocalEvent(LocalEcho { @@ -216,9 +214,9 @@ async fn test_smoke() { async fn test_error() { let (client, server) = logged_in_client_with_server().await; - let mut global_status = client.sending_queue().subscribe_status(); + let mut global_status = client.send_queue().subscribe_status(); - assert!(client.sending_queue().is_enabled()); + assert!(client.send_queue().is_enabled()); assert!(global_status.next_now()); // Mark the room as joined. @@ -234,7 +232,7 @@ async fn test_error() { ) .await; - let q = room.sending_queue(); + let q = room.send_queue(); let (local_echoes, mut watch) = q.subscribe().await; assert!(local_echoes.is_empty()); @@ -311,7 +309,7 @@ async fn test_error() { assert!(watch.is_empty()); assert!(!global_status.next().await.unwrap(), "the queue should be disabled next"); - assert!(!client.sending_queue().is_enabled()); + assert!(!client.send_queue().is_enabled()); server.reset().await; Mock::given(method("PUT")) @@ -325,13 +323,13 @@ async fn test_error() { .await; // Re-enabling the queue will re-send the same message in that room. - client.sending_queue().enable(); + client.send_queue().enable(); assert!( global_status.next().await.unwrap(), "the queue should be re-enabled after the user action" ); - assert!(client.sending_queue().is_enabled()); + assert!(client.send_queue().is_enabled()); assert_let!( Ok(Ok(RoomSendQueueUpdate::SentEvent { event_id, transaction_id: txn3 })) = @@ -361,17 +359,17 @@ async fn test_reenabling_queue() { ) .await; - let mut global_status = client.sending_queue().subscribe_status(); + let mut global_status = client.send_queue().subscribe_status(); assert!(global_status.next_now()); // When I start with a disabled send queue, - client.sending_queue().disable(); + client.send_queue().disable(); - assert!(!client.sending_queue().is_enabled()); + assert!(!client.send_queue().is_enabled()); assert!(!global_status.next().await.unwrap()); - let q = room.sending_queue(); + let q = room.send_queue(); let (local_echoes, mut watch) = q.subscribe().await; @@ -426,9 +424,9 @@ async fn test_reenabling_queue() { .await; // But when reenabling the queue, - client.sending_queue().enable(); + client.send_queue().enable(); - assert!(client.sending_queue().is_enabled()); + assert!(client.send_queue().is_enabled()); assert!(global_status.next().await.unwrap()); // They're sent, in the same ordering. @@ -460,7 +458,7 @@ async fn test_cancellation() { ) .await; - let q = room.sending_queue(); + let q = room.send_queue(); let (local_echoes, mut watch) = q.subscribe().await; @@ -651,16 +649,16 @@ async fn test_abort_reenable() { ) .await; - let mut global_status = client.sending_queue().subscribe_status(); + let mut global_status = client.send_queue().subscribe_status(); assert!(global_status.next_now()); // When I start with an enabled sending queue, - client.sending_queue().enable(); + client.send_queue().enable(); - assert!(client.sending_queue().is_enabled()); + assert!(client.send_queue().is_enabled()); - let q = room.sending_queue(); + let q = room.send_queue(); let (local_echoes, mut watch) = q.subscribe().await; diff --git a/labs/multiverse/src/main.rs b/labs/multiverse/src/main.rs index cf74274fdb5..d2a260a792a 100644 --- a/labs/multiverse/src/main.rs +++ b/labs/multiverse/src/main.rs @@ -436,7 +436,7 @@ impl App { Char('S') => self.sync_service.stop().await?, Char('Q') => { - let q = self.client.sending_queue(); + let q = self.client.send_queue(); let enabled = q.is_enabled(); if enabled { q.disable();