Skip to content

Commit b609637

Browse files
committed
feat(send_queue): add global setting for sending media progress updates
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
1 parent ec112ca commit b609637

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub struct ClientBuilder {
129129
decryption_settings: DecryptionSettings,
130130
enable_share_history_on_invite: bool,
131131
request_config: Option<RequestConfig>,
132+
enable_send_queue_media_upload_progress_reporting: bool,
132133

133134
#[cfg(not(target_family = "wasm"))]
134135
user_agent: Option<String>,
@@ -180,6 +181,7 @@ impl ClientBuilder {
180181
enable_share_history_on_invite: false,
181182
request_config: Default::default(),
182183
threads_enabled: false,
184+
enable_send_queue_media_upload_progress_reporting: false,
183185
})
184186
}
185187

@@ -386,6 +388,18 @@ impl ClientBuilder {
386388
Arc::new(builder)
387389
}
388390

391+
/// Set whether to enable progress reporting for media uploads in the send
392+
/// queue.
393+
pub fn enable_send_queue_media_upload_progress_reporting(
394+
self: Arc<Self>,
395+
enable_send_queue_media_upload_progress_reporting: bool,
396+
) -> Arc<Self> {
397+
let mut builder = unwrap_or_clone_arc(self);
398+
builder.enable_send_queue_media_upload_progress_reporting =
399+
enable_send_queue_media_upload_progress_reporting;
400+
Arc::new(builder)
401+
}
402+
389403
/// Add a default request config to this client.
390404
pub fn request_config(self: Arc<Self>, config: RequestConfig) -> Arc<Self> {
391405
let mut builder = unwrap_or_clone_arc(self);
@@ -524,7 +538,10 @@ impl ClientBuilder {
524538
.with_encryption_settings(builder.encryption_settings)
525539
.with_room_key_recipient_strategy(builder.room_key_recipient_strategy)
526540
.with_decryption_settings(builder.decryption_settings)
527-
.with_enable_share_history_on_invite(builder.enable_share_history_on_invite);
541+
.with_enable_share_history_on_invite(builder.enable_share_history_on_invite)
542+
.with_enable_send_queue_media_upload_progress_reporting(
543+
builder.enable_send_queue_media_upload_progress_reporting,
544+
);
528545

529546
match builder.sliding_sync_version_builder {
530547
SlidingSyncVersionBuilder::None => {

crates/matrix-sdk/src/client/builder/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub struct ClientBuilder {
114114
enable_share_history_on_invite: bool,
115115
cross_process_store_locks_holder_name: String,
116116
threading_support: ThreadingSupport,
117+
enable_send_queue_media_upload_progress_reporting: bool,
117118
}
118119

119120
impl ClientBuilder {
@@ -145,6 +146,7 @@ impl ClientBuilder {
145146
cross_process_store_locks_holder_name:
146147
Self::DEFAULT_CROSS_PROCESS_STORE_LOCKS_HOLDER_NAME.to_owned(),
147148
threading_support: ThreadingSupport::Disabled,
149+
enable_send_queue_media_upload_progress_reporting: false,
148150
}
149151
}
150152

@@ -489,6 +491,16 @@ impl ClientBuilder {
489491
self
490492
}
491493

494+
/// Set whether to report media upload progress via the send queue.
495+
pub fn with_enable_send_queue_media_upload_progress_reporting(
496+
mut self,
497+
enable_send_queue_media_upload_progress_reporting: bool,
498+
) -> Self {
499+
self.enable_send_queue_media_upload_progress_reporting =
500+
enable_send_queue_media_upload_progress_reporting;
501+
self
502+
}
503+
492504
/// Create a [`Client`] with the options set on this builder.
493505
///
494506
/// # Errors
@@ -573,7 +585,10 @@ impl ClientBuilder {
573585
});
574586

575587
// Enable the send queue by default.
576-
let send_queue = Arc::new(SendQueueData::new(true));
588+
let send_queue = Arc::new(SendQueueData::new(
589+
true,
590+
self.enable_send_queue_media_upload_progress_reporting,
591+
));
577592

578593
let server_info = ClientServerInfo {
579594
server_versions: match self.server_versions {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl SendQueue {
246246
data.is_dropping.clone(),
247247
&self.client,
248248
owned_room_id.clone(),
249+
data.report_media_upload_progress.clone(),
249250
);
250251

251252
map.insert(owned_room_id, room_q.clone());
@@ -330,18 +331,22 @@ pub(super) struct SendQueueData {
330331

331332
/// Are we currently dropping the Client?
332333
is_dropping: Arc<AtomicBool>,
334+
335+
/// Will media upload progress be reported via send queue updates?
336+
report_media_upload_progress: Arc<AtomicBool>,
333337
}
334338

335339
impl SendQueueData {
336340
/// Create the data for a send queue, in the given enabled state.
337-
pub fn new(globally_enabled: bool) -> Self {
341+
pub fn new(globally_enabled: bool, report_media_upload_progress: bool) -> Self {
338342
let (sender, _) = broadcast::channel(32);
339343

340344
Self {
341345
rooms: Default::default(),
342346
globally_enabled: AtomicBool::new(globally_enabled),
343347
error_reporter: sender,
344348
is_dropping: Arc::new(false.into()),
349+
report_media_upload_progress: Arc::new(AtomicBool::new(report_media_upload_progress)),
345350
}
346351
}
347352
}
@@ -389,6 +394,7 @@ impl RoomSendQueue {
389394
is_dropping: Arc<AtomicBool>,
390395
client: &Client,
391396
room_id: OwnedRoomId,
397+
report_media_upload_progress: Arc<AtomicBool>,
392398
) -> Self {
393399
let (updates_sender, _) = broadcast::channel(32);
394400

@@ -406,6 +412,7 @@ impl RoomSendQueue {
406412
locally_enabled.clone(),
407413
global_error_reporter,
408414
is_dropping,
415+
report_media_upload_progress,
409416
));
410417

411418
Self {
@@ -514,6 +521,7 @@ impl RoomSendQueue {
514521
///
515522
/// It only progresses forward: nothing can be cancelled at any point, which
516523
/// makes the implementation not overly complicated to follow.
524+
#[allow(clippy::too_many_arguments)]
517525
#[instrument(skip_all, fields(room_id = %room.room_id()))]
518526
async fn sending_task(
519527
room: WeakRoom,
@@ -523,6 +531,7 @@ impl RoomSendQueue {
523531
locally_enabled: Arc<AtomicBool>,
524532
global_error_reporter: broadcast::Sender<SendQueueRoomError>,
525533
is_dropping: Arc<AtomicBool>,
534+
_report_media_upload_progress: Arc<AtomicBool>,
526535
) {
527536
trace!("spawned the sending task");
528537

0 commit comments

Comments
 (0)