@@ -2075,13 +2075,7 @@ async fn test_chat_get_color_encrypted() -> Result<()> {
20752075 Ok ( ( ) )
20762076}
20772077
2078- async fn test_sticker (
2079- filename : & str ,
2080- bytes : & [ u8 ] ,
2081- res_viewtype : Viewtype ,
2082- w : i32 ,
2083- h : i32 ,
2084- ) -> Result < ( ) > {
2078+ async fn test_sticker ( filename : & str , bytes : & [ u8 ] , w : i32 , h : i32 ) -> Result < ( ) > {
20852079 let alice = TestContext :: new_alice ( ) . await ;
20862080 let bob = TestContext :: new_bob ( ) . await ;
20872081 let alice_chat = alice. create_chat ( & bob) . await ;
@@ -2097,7 +2091,7 @@ async fn test_sticker(
20972091
20982092 let msg = bob. recv_msg ( & sent_msg) . await ;
20992093 assert_eq ! ( msg. chat_id, bob_chat. id) ;
2100- assert_eq ! ( msg. get_viewtype( ) , res_viewtype ) ;
2094+ assert_eq ! ( msg. get_viewtype( ) , Viewtype :: Sticker ) ;
21012095 assert_eq ! ( msg. get_filename( ) . unwrap( ) , filename) ;
21022096 assert_eq ! ( msg. get_width( ) , w) ;
21032097 assert_eq ! ( msg. get_height( ) , h) ;
@@ -2111,7 +2105,6 @@ async fn test_sticker_png() -> Result<()> {
21112105 test_sticker (
21122106 "sticker.png" ,
21132107 include_bytes ! ( "../../test-data/image/logo.png" ) ,
2114- Viewtype :: Sticker ,
21152108 135 ,
21162109 135 ,
21172110 )
@@ -2123,18 +2116,40 @@ async fn test_sticker_jpeg() -> Result<()> {
21232116 test_sticker (
21242117 "sticker.jpg" ,
21252118 include_bytes ! ( "../../test-data/image/avatar1000x1000.jpg" ) ,
2126- Viewtype :: Image ,
21272119 1000 ,
21282120 1000 ,
21292121 )
21302122 . await
21312123}
21322124
21332125#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2134- async fn test_sticker_jpeg_force ( ) {
2135- let alice = TestContext :: new_alice ( ) . await ;
2136- let bob = TestContext :: new_bob ( ) . await ;
2137- let alice_chat = alice. create_chat ( & bob) . await ;
2126+ async fn test_sticker_gif ( ) -> Result < ( ) > {
2127+ test_sticker (
2128+ "sticker.gif" ,
2129+ include_bytes ! ( "../../test-data/image/logo.gif" ) ,
2130+ 135 ,
2131+ 135 ,
2132+ )
2133+ . await
2134+ }
2135+
2136+ /// Tests that stickers are sent as stickers.
2137+ ///
2138+ /// Previously there was heuristic that stickers
2139+ /// were sometimes turned into non-stickers,
2140+ /// e.g. when it looked like UI sent
2141+ /// a screenshot dragged from the gallery into chat
2142+ /// as a sticker.
2143+ ///
2144+ /// We have no such heuristic anymore,
2145+ /// if such heuristic is needed on some platform,
2146+ /// UI code should implement it.
2147+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2148+ async fn test_sticker_no_heuristics ( ) {
2149+ let mut tcm = TestContextManager :: new ( ) ;
2150+ let alice = & tcm. alice ( ) . await ;
2151+ let bob = & tcm. bob ( ) . await ;
2152+ let alice_chat = alice. create_chat ( bob) . await ;
21382153
21392154 let file = alice. get_blobdir ( ) . join ( "sticker.jpg" ) ;
21402155 tokio:: fs:: write (
@@ -2144,53 +2159,38 @@ async fn test_sticker_jpeg_force() {
21442159 . await
21452160 . unwrap ( ) ;
21462161
2147- // Images without force_sticker should be turned into [Viewtype::Image]
2162+ // Send a sticker.
21482163 let mut msg = Message :: new ( Viewtype :: Sticker ) ;
2149- msg. set_file_and_deduplicate ( & alice, & file, Some ( "sticker.jpg" ) , None )
2164+ msg. set_file_and_deduplicate ( alice, & file, Some ( "sticker.jpg" ) , None )
21502165 . unwrap ( ) ;
2151- let file = msg. get_file ( & alice) . unwrap ( ) ;
2166+ let file = msg. get_file ( alice) . unwrap ( ) ;
21522167 let sent_msg = alice. send_msg ( alice_chat. id , & mut msg) . await ;
21532168 let msg = bob. recv_msg ( & sent_msg) . await ;
2154- assert_eq ! ( msg. get_viewtype( ) , Viewtype :: Image ) ;
2169+ assert_eq ! ( msg. get_viewtype( ) , Viewtype :: Sticker ) ;
21552170
2156- // Images with `force_sticker = true` should keep [Viewtype::Sticker]
2171+ // Send a sticker reusing the file.
21572172 let mut msg = Message :: new ( Viewtype :: Sticker ) ;
2158- msg. set_file_and_deduplicate ( & alice, & file, Some ( "sticker.jpg" ) , None )
2173+ msg. set_file_and_deduplicate ( alice, & file, Some ( "sticker.jpg" ) , None )
21592174 . unwrap ( ) ;
2160- msg. force_sticker ( ) ;
21612175 let sent_msg = alice. send_msg ( alice_chat. id , & mut msg) . await ;
21622176 let msg = bob. recv_msg ( & sent_msg) . await ;
21632177 assert_eq ! ( msg. get_viewtype( ) , Viewtype :: Sticker ) ;
21642178
2165- // Images with `force_sticker = true` should keep [Viewtype::Sticker]
2166- // even on drafted messages
2179+ // Set sticker as a draft, then send it.
21672180 let mut msg = Message :: new ( Viewtype :: Sticker ) ;
2168- msg. set_file_and_deduplicate ( & alice, & file, Some ( "sticker.jpg" ) , None )
2181+ msg. set_file_and_deduplicate ( alice, & file, Some ( "sticker.jpg" ) , None )
21692182 . unwrap ( ) ;
2170- msg. force_sticker ( ) ;
21712183 alice_chat
21722184 . id
2173- . set_draft ( & alice, Some ( & mut msg) )
2185+ . set_draft ( alice, Some ( & mut msg) )
21742186 . await
21752187 . unwrap ( ) ;
2176- let mut msg = alice_chat. id . get_draft ( & alice) . await . unwrap ( ) . unwrap ( ) ;
2188+ let mut msg = alice_chat. id . get_draft ( alice) . await . unwrap ( ) . unwrap ( ) ;
21772189 let sent_msg = alice. send_msg ( alice_chat. id , & mut msg) . await ;
21782190 let msg = bob. recv_msg ( & sent_msg) . await ;
21792191 assert_eq ! ( msg. get_viewtype( ) , Viewtype :: Sticker ) ;
21802192}
21812193
2182- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
2183- async fn test_sticker_gif ( ) -> Result < ( ) > {
2184- test_sticker (
2185- "sticker.gif" ,
2186- include_bytes ! ( "../../test-data/image/logo.gif" ) ,
2187- Viewtype :: Sticker ,
2188- 135 ,
2189- 135 ,
2190- )
2191- . await
2192- }
2193-
21942194#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
21952195async fn test_sticker_forward ( ) -> Result < ( ) > {
21962196 // create chats
0 commit comments