File tree 2 files changed +29
-2
lines changed
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -1455,4 +1455,23 @@ mod tests {
1455
1455
check_image_size ( file_saved, width, height) ;
1456
1456
Ok ( ( ) )
1457
1457
}
1458
+
1459
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
1460
+ async fn test_send_gif_as_sticker ( ) -> Result < ( ) > {
1461
+ let bytes = include_bytes ! ( "../test-data/image/image100x50.gif" ) ;
1462
+ let alice = & TestContext :: new_alice ( ) . await ;
1463
+ let file = alice. get_blobdir ( ) . join ( "file" ) . with_extension ( "gif" ) ;
1464
+ fs:: write ( & file, & bytes)
1465
+ . await
1466
+ . context ( "failed to write file" ) ?;
1467
+ let mut msg = Message :: new ( Viewtype :: Sticker ) ;
1468
+ msg. set_file ( file. to_str ( ) . unwrap ( ) , None ) ;
1469
+ let chat = alice. get_self_chat ( ) . await ;
1470
+ let sent = alice. send_msg ( chat. id , & mut msg) . await ;
1471
+ let msg = Message :: load_from_db ( alice, sent. sender_msg_id ) . await ?;
1472
+ // Message::force_sticker() wasn't used, still Viewtype::Sticker is preserved because of the
1473
+ // extension.
1474
+ assert_eq ! ( msg. get_viewtype( ) , Viewtype :: Sticker ) ;
1475
+ Ok ( ( ) )
1476
+ }
1458
1477
}
Original file line number Diff line number Diff line change @@ -2688,7 +2688,10 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
2688
2688
. with_context ( || format ! ( "attachment missing for message of type #{}" , msg. viewtype) ) ?;
2689
2689
let send_as_is = msg. viewtype == Viewtype :: File ;
2690
2690
2691
- if msg. viewtype == Viewtype :: File || msg. viewtype == Viewtype :: Image {
2691
+ if msg. viewtype == Viewtype :: File
2692
+ || msg. viewtype == Viewtype :: Image
2693
+ || msg. viewtype == Viewtype :: Sticker && !msg. param . exists ( Param :: ForceSticker )
2694
+ {
2692
2695
// Correct the type, take care not to correct already very special
2693
2696
// formats as GIF or VOICE.
2694
2697
//
@@ -2697,7 +2700,12 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
2697
2700
// - from FILE/IMAGE to GIF */
2698
2701
if let Some ( ( better_type, _) ) = message:: guess_msgtype_from_suffix ( & blob. to_abs_path ( ) )
2699
2702
{
2700
- if better_type != Viewtype :: Webxdc
2703
+ if msg. viewtype == Viewtype :: Sticker {
2704
+ if better_type != Viewtype :: Image {
2705
+ // UIs don't want conversions of `Sticker` to anything other than `Image`.
2706
+ msg. param . set_int ( Param :: ForceSticker , 1 ) ;
2707
+ }
2708
+ } else if better_type != Viewtype :: Webxdc
2701
2709
|| context
2702
2710
. ensure_sendable_webxdc_file ( & blob. to_abs_path ( ) )
2703
2711
. await
You can’t perform that action at this time.
0 commit comments