@@ -101,10 +101,14 @@ impl Timeline {
101
101
async fn send_attachment (
102
102
& self ,
103
103
filename : String ,
104
- mime_type : Mime ,
104
+ mime_type : Option < String > ,
105
105
attachment_config : AttachmentConfig ,
106
106
progress_watcher : Option < Box < dyn ProgressWatcher > > ,
107
107
) -> 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
+
108
112
let request = self . inner . send_attachment ( filename, mime_type, attachment_config) ;
109
113
if let Some ( progress_watcher) = progress_watcher {
110
114
let mut subscriber = request. subscribe_to_send_progress ( ) ;
@@ -120,11 +124,6 @@ impl Timeline {
120
124
}
121
125
}
122
126
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
-
128
127
fn build_thumbnail_info (
129
128
thumbnail_url : Option < String > ,
130
129
thumbnail_info : Option < ThumbnailInfo > ,
@@ -290,13 +289,8 @@ impl Timeline {
290
289
. caption ( caption)
291
290
. formatted_caption ( formatted_caption. map ( Into :: into) ) ;
292
291
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
300
294
} ) )
301
295
}
302
296
@@ -319,13 +313,8 @@ impl Timeline {
319
313
. caption ( caption)
320
314
. formatted_caption ( formatted_caption. map ( Into :: into) ) ;
321
315
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
329
318
} ) )
330
319
}
331
320
@@ -347,13 +336,8 @@ impl Timeline {
347
336
. caption ( caption)
348
337
. formatted_caption ( formatted_caption. map ( Into :: into) ) ;
349
338
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
357
341
} ) )
358
342
}
359
343
@@ -377,13 +361,8 @@ impl Timeline {
377
361
. caption ( caption)
378
362
. formatted_caption ( formatted_caption. map ( Into :: into) ) ;
379
363
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
387
366
} ) )
388
367
}
389
368
@@ -400,13 +379,7 @@ impl Timeline {
400
379
401
380
let attachment_config = AttachmentConfig :: new ( ) . info ( attachment_info) ;
402
381
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
410
383
} ) )
411
384
}
412
385
0 commit comments