Skip to content

Commit efa4539

Browse files
authored
refactor(client): have upload_encrypted_file own the Client instance (#5470)
Signed-off-by: multi [email protected]
1 parent 42d2b93 commit efa4539

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

crates/matrix-sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ All notable changes to this project will be documented in this file.
3838

3939
### Refactor
4040

41+
- [**breaking**] Change the upload_encrypted_file and make it clone the client instead of owning it. The lifetime of the `UploadEncryptedFile` request returned by `Client::upload_encrypted_file()` only depends on the request lifetime now.
4142
- [**breaking**] Add an `IsPrefix = False` bound to the `account_data()` and
4243
`fetch_account_data_static()` methods of `Account`. These methods only worked
4344
for events where the full event type is statically-known, and this is now

crates/matrix-sdk/src/encryption/futures.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ use crate::{config::RequestConfig, Client, Media, Result, TransmissionProgress};
2828
/// Future returned by [`Client::upload_encrypted_file`].
2929
#[allow(missing_debug_implementations)]
3030
pub struct UploadEncryptedFile<'a, R: ?Sized> {
31-
client: &'a Client,
31+
client: Client,
3232
reader: &'a mut R,
3333
send_progress: SharedObservable<TransmissionProgress>,
3434
request_config: Option<RequestConfig>,
3535
}
3636

3737
impl<'a, R: ?Sized> UploadEncryptedFile<'a, R> {
38-
pub(crate) fn new(client: &'a Client, reader: &'a mut R) -> Self {
39-
Self { client, reader, send_progress: Default::default(), request_config: None }
38+
pub(crate) fn new(client: &Client, reader: &'a mut R) -> Self {
39+
Self {
40+
client: client.clone(),
41+
reader,
42+
send_progress: Default::default(),
43+
request_config: None,
44+
}
4045
}
4146

4247
/// Replace the default `SharedObservable` used for tracking upload

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,12 +861,9 @@ impl RoomSendQueue {
861861
let media_source = if room.latest_encryption_state().await?.is_encrypted() {
862862
trace!("upload will be encrypted (encrypted room)");
863863

864-
// TODO: clone the Client when creating `UploadEncryptedFile` to avoid the
865-
// borrow and the local variable here. See also issue 5465.
866-
let client = room.client();
867-
868864
let mut cursor = std::io::Cursor::new(data);
869-
let mut req = client
865+
let mut req = room
866+
.client
870867
.upload_encrypted_file(&mut cursor)
871868
.with_request_config(RequestConfig::short_retry());
872869
if let Some(progress) = progress {

0 commit comments

Comments
 (0)