diff --git a/native/mtproto-rs/src/client/media_download.rs b/native/mtproto-rs/src/client/media_download.rs index e2c49135..d377469b 100644 --- a/native/mtproto-rs/src/client/media_download.rs +++ b/native/mtproto-rs/src/client/media_download.rs @@ -241,6 +241,11 @@ pub fn peek_message_inline_thumb(handle: u64, chat_id: i64, message_id: i32) -> media::inline_thumb_jpeg(indexed) } +/// Shared-index read of an inline stripped/cached avatar JPEG for a peer (user or chat). +pub fn peek_peer_inline_thumb(handle: u64, peer_id: i64) -> Option> { + peek_message_inline_thumb(handle, peer_id, 0) +} + pub(crate) fn indexed_media_for_download( data: &ClientData, chat_id: i64, diff --git a/native/mtproto-rs/src/dialogs/get_dialogs.rs b/native/mtproto-rs/src/dialogs/get_dialogs.rs index ecc1e1a7..9fbfdd6c 100644 --- a/native/mtproto-rs/src/dialogs/get_dialogs.rs +++ b/native/mtproto-rs/src/dialogs/get_dialogs.rs @@ -184,6 +184,7 @@ pub(crate) fn map_peer_dialogs( p.photo_id, p.dc_id, p.has_video.is_some(), + p.stripped_thumb.as_deref(), )) }); let (peer_status, peer_status_at) = @@ -215,6 +216,7 @@ pub(crate) fn map_peer_dialogs( p.photo_id, p.dc_id, p.has_video.is_some(), + p.stripped_thumb.as_deref(), )), _ => None, }; @@ -236,6 +238,7 @@ pub(crate) fn map_peer_dialogs( p.photo_id, p.dc_id, p.has_video.is_some(), + p.stripped_thumb.as_deref(), ) }), _ => None, diff --git a/native/mtproto-rs/src/dialogs/peers.rs b/native/mtproto-rs/src/dialogs/peers.rs index 21789710..ef283c75 100644 --- a/native/mtproto-rs/src/dialogs/peers.rs +++ b/native/mtproto-rs/src/dialogs/peers.rs @@ -62,6 +62,7 @@ pub(crate) fn cache_from_users_chats( p.photo_id, p.dc_id, p.has_video.is_some(), + p.stripped_thumb.as_deref(), ); } } @@ -84,6 +85,7 @@ pub(crate) fn cache_from_users_chats( p.photo_id, p.dc_id, p.has_video.is_some(), + p.stripped_thumb.as_deref(), ); } } @@ -109,6 +111,7 @@ pub(crate) fn cache_from_users_chats( p.photo_id, p.dc_id, p.has_video.is_some(), + p.stripped_thumb.as_deref(), ); } } @@ -129,6 +132,7 @@ pub(crate) fn index_dialog_avatar( photo_id: i64, dc_id: i32, has_video: bool, + stripped_thumb: Option<&[u8]>, ) -> String { let cache_key = media::avatar_cache_key(chat_id, has_video); let media = media::media_ref_peer_photo( @@ -139,6 +143,7 @@ pub(crate) fn index_dialog_avatar( dc_id, cache_key, has_video, + stripped_thumb, ); media::index_avatar(media_index, chat_id, media) } diff --git a/native/mtproto-rs/src/ffi.rs b/native/mtproto-rs/src/ffi.rs index 1450d0f6..58ce4156 100644 --- a/native/mtproto-rs/src/ffi.rs +++ b/native/mtproto-rs/src/ffi.rs @@ -908,6 +908,11 @@ pub fn peek_message_inline_thumb(handle: u64, chat_id: i64, message_id: i32) -> client::peek_message_inline_thumb(handle, chat_id, message_id) } +#[uniffi::export] +pub fn peek_peer_inline_thumb(handle: u64, peer_id: i64) -> Option> { + client::peek_peer_inline_thumb(handle, peer_id) +} + #[uniffi::export] pub fn download_message_display( handle: u64, diff --git a/native/mtproto-rs/src/media/index.rs b/native/mtproto-rs/src/media/index.rs index 2582e4fe..6ba32463 100644 --- a/native/mtproto-rs/src/media/index.rs +++ b/native/mtproto-rs/src/media/index.rs @@ -328,7 +328,15 @@ pub fn media_ref_peer_photo( dc_id: i32, cache_key: String, has_video: bool, + stripped_thumb: Option<&[u8]>, ) -> MediaRef { + let (thumb_cache_key, thumb_location) = match stripped_thumb.and_then(crate::stripped_jpeg::expand_stripped_jpeg) { + Some(bytes) => ( + Some(format!("{}:thumb", cache_key)), + Some(MediaLocation::Inline { bytes, extension: "jpg".into() }), + ), + None => (None, None), + }; MediaRef { file_size: None, kind: if has_video { @@ -337,8 +345,8 @@ pub fn media_ref_peer_photo( "photo".into() }, cache_key, - thumb_cache_key: None, - thumb_location: None, + thumb_cache_key, + thumb_location, display_cache_key: None, display_location: None, sticker_set_id: None, diff --git a/native/mtproto-rs/src/profile/full.rs b/native/mtproto-rs/src/profile/full.rs index abb2c42f..bf0d6d61 100644 --- a/native/mtproto-rs/src/profile/full.rs +++ b/native/mtproto-rs/src/profile/full.rs @@ -103,6 +103,7 @@ pub(crate) fn index_user_avatar( p.dc_id, media::avatar_cache_key(peer_chat_id, has_video), has_video, + p.stripped_thumb.as_deref(), ); return Some(media::index_avatar(media_index, peer_chat_id, media)); } @@ -131,6 +132,7 @@ pub(crate) fn index_chat_photo( p.dc_id, media::avatar_cache_key(peer_chat_id, has_video), has_video, + p.stripped_thumb.as_deref(), ); Some(media::index_avatar(media_index, peer_chat_id, media)) } diff --git a/native/mtproto-rs/tests/unit/media_location_tests.rs b/native/mtproto-rs/tests/unit/media_location_tests.rs index 1f0fbe1b..2ce70663 100644 --- a/native/mtproto-rs/tests/unit/media_location_tests.rs +++ b/native/mtproto-rs/tests/unit/media_location_tests.rs @@ -57,6 +57,7 @@ fn fill_zero_peer_photo_hashes_from_full_peer() { 2, "avatar:-1000000000042".into(), false, + None, ), ); let mut peers = HashMap::new(); diff --git a/native/mtproto-rs/tests/unit/media_thumbs_tests.rs b/native/mtproto-rs/tests/unit/media_thumbs_tests.rs index f857e776..1766dc52 100644 --- a/native/mtproto-rs/tests/unit/media_thumbs_tests.rs +++ b/native/mtproto-rs/tests/unit/media_thumbs_tests.rs @@ -440,6 +440,7 @@ fn resolved_video_avatar_survives_still_peer_photo() { 2, "avatar:7".into(), false, + None, ); assert_eq!(index_avatar(&mut media, 7, still), "avatar:7:video"); assert!(is_resolved_video_avatar(media.get(&(7, 0)).unwrap())); @@ -451,8 +452,26 @@ fn resolved_video_avatar_survives_still_peer_photo() { 2, "avatar:7:video".into(), true, + None, ); assert!(needs_video_avatar_upgrade(&placeholder)); assert_eq!(index_avatar(&mut media, 7, placeholder), "avatar:7:video"); assert!(is_resolved_video_avatar(media.get(&(7, 0)).unwrap())); } + +#[test] +fn peer_photo_with_stripped_thumb() { + let raw_stripped = [0x01, 0x08, 0x08, 0x28, 0x00]; + let photo = media_ref_peer_photo( + crate::peers::PeerKind::User, + 7, + 1, + 99, + 2, + "avatar:7".into(), + false, + Some(&raw_stripped), + ); + assert_eq!(photo.thumb_cache_key, Some("avatar:7:thumb".into())); + assert!(matches!(photo.thumb_location, Some(MediaLocation::Inline { extension, .. }) if extension == "jpg")); +} diff --git a/vendor/telers-mtproto-impl b/vendor/telers-mtproto-impl index b31ca081..a2702214 160000 --- a/vendor/telers-mtproto-impl +++ b/vendor/telers-mtproto-impl @@ -1 +1 @@ -Subproject commit b31ca081ce94713c338853f5f05827c7a649c7a1 +Subproject commit a270221474d05db8febc9eb6f290138d136501fc