Skip to content

Commit 65ed4f3

Browse files
committed
refactor(ffi): push further and inline parse_mime into the same caller
1 parent 41d392f commit 65ed4f3

File tree

1 file changed

+14
-41
lines changed
  • bindings/matrix-sdk-ffi/src/timeline

1 file changed

+14
-41
lines changed

bindings/matrix-sdk-ffi/src/timeline/mod.rs

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ impl Timeline {
101101
async fn send_attachment(
102102
&self,
103103
filename: String,
104-
mime_type: Mime,
104+
mime_type: Option<String>,
105105
attachment_config: AttachmentConfig,
106106
progress_watcher: Option<Box<dyn ProgressWatcher>>,
107107
) -> Result<(), RoomError> {
108+
let mime_str = mime_type.as_ref().ok_or(RoomError::InvalidAttachmentMimeType)?;
109+
let mime_type =
110+
mime_str.parse::<Mime>().map_err(|_| RoomError::InvalidAttachmentMimeType)?;
111+
108112
let request = self.inner.send_attachment(filename, mime_type, attachment_config);
109113
if let Some(progress_watcher) = progress_watcher {
110114
let mut subscriber = request.subscribe_to_send_progress();
@@ -120,11 +124,6 @@ impl Timeline {
120124
}
121125
}
122126

123-
fn parse_mime(mimetype: Option<String>) -> Result<Mime, RoomError> {
124-
let mime_str = mimetype.as_ref().ok_or(RoomError::InvalidAttachmentMimeType)?;
125-
mime_str.parse::<Mime>().map_err(|_| RoomError::InvalidAttachmentMimeType)
126-
}
127-
128127
fn build_thumbnail_info(
129128
thumbnail_url: Option<String>,
130129
thumbnail_info: Option<ThumbnailInfo>,
@@ -290,13 +289,8 @@ impl Timeline {
290289
.caption(caption)
291290
.formatted_caption(formatted_caption.map(Into::into));
292291

293-
self.send_attachment(
294-
url,
295-
parse_mime(image_info.mimetype)?,
296-
attachment_config,
297-
progress_watcher,
298-
)
299-
.await
292+
self.send_attachment(url, image_info.mimetype, attachment_config, progress_watcher)
293+
.await
300294
}))
301295
}
302296

@@ -319,13 +313,8 @@ impl Timeline {
319313
.caption(caption)
320314
.formatted_caption(formatted_caption.map(Into::into));
321315

322-
self.send_attachment(
323-
url,
324-
parse_mime(video_info.mimetype)?,
325-
attachment_config,
326-
progress_watcher,
327-
)
328-
.await
316+
self.send_attachment(url, video_info.mimetype, attachment_config, progress_watcher)
317+
.await
329318
}))
330319
}
331320

@@ -347,13 +336,8 @@ impl Timeline {
347336
.caption(caption)
348337
.formatted_caption(formatted_caption.map(Into::into));
349338

350-
self.send_attachment(
351-
url,
352-
parse_mime(audio_info.mimetype)?,
353-
attachment_config,
354-
progress_watcher,
355-
)
356-
.await
339+
self.send_attachment(url, audio_info.mimetype, attachment_config, progress_watcher)
340+
.await
357341
}))
358342
}
359343

@@ -377,13 +361,8 @@ impl Timeline {
377361
.caption(caption)
378362
.formatted_caption(formatted_caption.map(Into::into));
379363

380-
self.send_attachment(
381-
url,
382-
parse_mime(audio_info.mimetype)?,
383-
attachment_config,
384-
progress_watcher,
385-
)
386-
.await
364+
self.send_attachment(url, audio_info.mimetype, attachment_config, progress_watcher)
365+
.await
387366
}))
388367
}
389368

@@ -400,13 +379,7 @@ impl Timeline {
400379

401380
let attachment_config = AttachmentConfig::new().info(attachment_info);
402381

403-
self.send_attachment(
404-
url,
405-
parse_mime(file_info.mimetype)?,
406-
attachment_config,
407-
progress_watcher,
408-
)
409-
.await
382+
self.send_attachment(url, file_info.mimetype, attachment_config, progress_watcher).await
410383
}))
411384
}
412385

0 commit comments

Comments
 (0)