Skip to content

Commit

Permalink
move optional parameters to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
surakin committed Mar 17, 2024
1 parent e165e1c commit 74ca821
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 94 deletions.
40 changes: 20 additions & 20 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ impl Timeline {

async fn send_attachment(
&self,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
mime_type: Mime,
attachment_config: AttachmentConfig,
caption: Option<String>,
formatted: Option<FormattedBody>,
progress_watcher: Option<Box<dyn ProgressWatcher>>,
) -> Result<(), RoomError> {
let formatted: Option<RumaFormattedBody> = match formatted {
Some(p) => Some(RumaFormattedBody::from(p)),
None => None,
};
let request =
self.inner.send_attachment(caption, formatted, url, mime_type, attachment_config);
self.inner.send_attachment(url, mime_type, attachment_config, caption, formatted);
if let Some(progress_watcher) = progress_watcher {
let mut subscriber = request.subscribe_to_send_progress();
RUNTIME.spawn(async move {
Expand Down Expand Up @@ -224,11 +224,11 @@ impl Timeline {

pub fn send_image(
self: Arc<Self>,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
thumbnail_url: Option<String>,
image_info: ImageInfo,
caption: Option<String>,
formatted: Option<FormattedBody>,
progress_watcher: Option<Box<dyn ProgressWatcher>>,
) -> Arc<SendAttachmentJoinHandle> {
SendAttachmentJoinHandle::new(RUNTIME.spawn(async move {
Expand All @@ -252,23 +252,23 @@ impl Timeline {
};

self.send_attachment(
caption,
formatted,
url,
mime_type,
attachment_config,
caption,
formatted,
progress_watcher
).await
}))
}

pub fn send_video(
self: Arc<Self>,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
thumbnail_url: Option<String>,
video_info: VideoInfo,
caption: Option<String>,
formatted: Option<FormattedBody>,
progress_watcher: Option<Box<dyn ProgressWatcher>>,
) -> Arc<SendAttachmentJoinHandle> {
SendAttachmentJoinHandle::new(RUNTIME.spawn(async move {
Expand All @@ -292,22 +292,22 @@ impl Timeline {
};

self.send_attachment(
caption,
formatted,
url,
mime_type,
attachment_config,
caption,
formatted,
progress_watcher
).await
}))
}

pub fn send_audio(
self: Arc<Self>,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
audio_info: AudioInfo,
caption: Option<String>,
formatted: Option<FormattedBody>,
progress_watcher: Option<Box<dyn ProgressWatcher>>,
) -> Arc<SendAttachmentJoinHandle> {
SendAttachmentJoinHandle::new(RUNTIME.spawn(async move {
Expand All @@ -323,23 +323,23 @@ impl Timeline {
let attachment_config = AttachmentConfig::new().info(attachment_info);

self.send_attachment(
caption,
formatted,
url,
mime_type,
attachment_config,
caption,
formatted,
progress_watcher
).await
}))
}

pub fn send_voice_message(
self: Arc<Self>,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
audio_info: AudioInfo,
waveform: Vec<u16>,
caption: Option<String>,
formatted: Option<FormattedBody>,
progress_watcher: Option<Box<dyn ProgressWatcher>>,
) -> Arc<SendAttachmentJoinHandle> {
SendAttachmentJoinHandle::new(RUNTIME.spawn(async move {
Expand All @@ -356,11 +356,11 @@ impl Timeline {
let attachment_config = AttachmentConfig::new().info(attachment_info);

self.send_attachment(
caption,
formatted,
url,
mime_type,
attachment_config,
caption,
formatted,
progress_watcher
).await
}))
Expand All @@ -384,7 +384,7 @@ impl Timeline {
let attachment_info = AttachmentInfo::File(base_file_info);
let attachment_config = AttachmentConfig::new().info(attachment_info);

self.send_attachment(None, None, url, mime_type, attachment_config, progress_watcher)
self.send_attachment(url, mime_type, attachment_config, None, None, progress_watcher)
.await
}))
}
Expand Down
18 changes: 9 additions & 9 deletions crates/matrix-sdk-ui/src/timeline/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ use super::{Error, Timeline};

pub struct SendAttachment<'a> {
timeline: &'a Timeline,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
mime_type: Mime,
config: AttachmentConfig,
caption: Option<String>,
formatted: Option<FormattedBody>,
tracing_span: Span,
pub(crate) send_progress: SharedObservable<TransmissionProgress>,
}

impl<'a> SendAttachment<'a> {
pub(crate) fn new(
timeline: &'a Timeline,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
mime_type: Mime,
config: AttachmentConfig,
caption: Option<String>,
formatted: Option<FormattedBody>,
) -> Self {
Self {
timeline,
caption,
formatted,
url,
mime_type,
config,
caption,
formatted,
tracing_span: Span::current(),
send_progress: Default::default(),
}
Expand All @@ -56,11 +56,11 @@ impl<'a> IntoFuture for SendAttachment<'a> {
fn into_future(self) -> Self::IntoFuture {
let Self {
timeline,
caption,
formatted,
url,
mime_type,
config,
caption,
formatted,
tracing_span,
send_progress
} = self;
Expand All @@ -74,7 +74,7 @@ impl<'a> IntoFuture for SendAttachment<'a> {

timeline
.room()
.send_attachment(caption, formatted, urlbody, &mime_type, data, config)
.send_attachment(urlbody, &mime_type, data, config, caption, formatted)
.with_send_progress_observable(send_progress)
.await
.map_err(|_| Error::FailedSendingAttachment)?;
Expand Down
15 changes: 8 additions & 7 deletions crates/matrix-sdk-ui/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,27 +514,28 @@ impl Timeline {
///
/// # Arguments
///
/// * `caption` - The url for the file to be sent
///
/// * `formatted` - The url for the file to be sent
///
/// * `url` - The url for the file to be sent
///
/// * `mime_type` - The attachment's mime type
///
/// * `config` - An attachment configuration object containing details about
/// the attachment
///
/// * `caption` - An optional caption of this attachment
///
/// * `formatted` - An optional formatted caption of this attachment
///
/// like a thumbnail, its size, duration etc.
#[instrument(skip_all)]
pub fn send_attachment(
&self,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: String,
mime_type: Mime,
config: AttachmentConfig,
caption: Option<String>,
formatted: Option<FormattedBody>,
) -> SendAttachment<'_> {
SendAttachment::new(self, caption, formatted, url, mime_type, config)
SendAttachment::new(self, url, mime_type, config, caption, formatted)
}

/// Retry sending a message that previously failed to send.
Expand Down
15 changes: 6 additions & 9 deletions crates/matrix-sdk/src/encryption/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ impl Client {
/// optionanly with `formatted` and `filename`.
pub(crate) async fn prepare_encrypted_attachment_message(
&self,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: &str,
content_type: &mime::Mime,
data: Vec<u8>,
info: Option<AttachmentInfo>,
thumbnail: Option<Thumbnail>,
caption: Option<String>,
formatted: Option<FormattedBody>,
send_progress: SharedObservable<TransmissionProgress>,
) -> Result<MessageType> {
let upload_thumbnail =
Expand All @@ -324,13 +324,10 @@ impl Client {
let ((thumbnail_source, thumbnail_info), file) =
try_join(upload_thumbnail, upload_attachment).await?;

let body: &str = match &caption {
Some(p) => p,
None => url,
};
let filename = match &caption {
Some(p) => Some(String::from(p)),
None => None,
let url = url.to_owned();
let (body, filename) = match caption {
Some(caption) => (caption, Some(url)),
None => (url, None),
};

Ok(match content_type.type_() {
Expand Down
16 changes: 7 additions & 9 deletions crates/matrix-sdk/src/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ impl Media {
/// optionally with `formatted` and `filename`.
pub(crate) async fn prepare_attachment_message(
&self,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: &str,
content_type: &Mime,
data: Vec<u8>,
info: Option<AttachmentInfo>,
thumbnail: Option<Thumbnail>,
caption: Option<String>,
formatted: Option<FormattedBody>,
send_progress: SharedObservable<TransmissionProgress>,
) -> Result<MessageType> {
let upload_thumbnail = self.upload_thumbnail(thumbnail, send_progress.clone());
Expand All @@ -462,14 +462,12 @@ impl Media {
let ((thumbnail_source, thumbnail_info), response) =
try_join(upload_thumbnail, upload_attachment).await?;

let body: &str = match &caption {
Some(p) => p,
None => url,
};
let filename = match &caption {
Some(_) => Some(String::from(url)),
None => None,
let url = url.to_owned();
let (body, filename)= match caption {
Some(caption) => (caption, Some(url)),
None => (url, None),
};

let url = response.content_uri;

Ok(match content_type.type_() {
Expand Down
24 changes: 12 additions & 12 deletions crates/matrix-sdk/src/room/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,34 +216,34 @@ impl<'a> IntoFuture for SendRawMessageLikeEvent<'a> {
#[allow(missing_debug_implementations)]
pub struct SendAttachment<'a> {
room: &'a Room,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: &'a str,
content_type: &'a Mime,
data: Vec<u8>,
config: AttachmentConfig,
caption: Option<String>,
formatted: Option<FormattedBody>,
tracing_span: Span,
send_progress: SharedObservable<TransmissionProgress>,
}

impl<'a> SendAttachment<'a> {
pub(crate) fn new(
room: &'a Room,
caption: Option<String>,
formatted: Option<FormattedBody>,
url: &'a str,
content_type: &'a Mime,
data: Vec<u8>,
config: AttachmentConfig,
caption: Option<String>,
formatted: Option<FormattedBody>,
) -> Self {
Self {
room,
caption,
formatted,
url,
content_type,
data,
config,
caption,
formatted,
tracing_span: Span::current(),
send_progress: Default::default(),
}
Expand All @@ -268,24 +268,24 @@ impl<'a> IntoFuture for SendAttachment<'a> {
fn into_future(self) -> Self::IntoFuture {
let Self {
room,
caption,
formatted,
url,
content_type,
data,
config,
caption,
formatted,
tracing_span,
send_progress
} = self;
let fut = async move {
if config.thumbnail.is_some() {
room.prepare_and_send_attachment(
caption,
formatted,
url,
content_type,
data,
config,
caption,
formatted,
send_progress
).await
} else {
Expand Down Expand Up @@ -346,12 +346,12 @@ impl<'a> IntoFuture for SendAttachment<'a> {
};

room.prepare_and_send_attachment(
caption,
formatted,
url,
content_type,
data,
config,
caption,
formatted,
send_progress
).await
}
Expand Down
Loading

0 comments on commit 74ca821

Please sign in to comment.