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