Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions native/mtproto-rs/src/client/media_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>> {
peek_message_inline_thumb(handle, peer_id, 0)
}

pub(crate) fn indexed_media_for_download(
data: &ClientData,
chat_id: i64,
Expand Down
3 changes: 3 additions & 0 deletions native/mtproto-rs/src/dialogs/get_dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions native/mtproto-rs/src/dialogs/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
}
Expand All @@ -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(),
);
}
}
Expand All @@ -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(),
);
}
}
Expand All @@ -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(
Expand All @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions native/mtproto-rs/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>> {
client::peek_peer_inline_thumb(handle, peer_id)
}

#[uniffi::export]
pub fn download_message_display(
handle: u64,
Expand Down
12 changes: 10 additions & 2 deletions native/mtproto-rs/src/media/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions native/mtproto-rs/src/profile/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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))
}
Expand Down
1 change: 1 addition & 0 deletions native/mtproto-rs/tests/unit/media_location_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fn fill_zero_peer_photo_hashes_from_full_peer() {
2,
"avatar:-1000000000042".into(),
false,
None,
),
);
let mut peers = HashMap::new();
Expand Down
19 changes: 19 additions & 0 deletions native/mtproto-rs/tests/unit/media_thumbs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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"));
}
2 changes: 1 addition & 1 deletion vendor/telers-mtproto-impl
Submodule telers-mtproto-impl updated 30 files
+1 −1 Cargo.toml
+26 −0 crates/tellers-mtproto/Cargo.toml
+373 −0 crates/tellers-mtproto/LICENSE
+169 −0 crates/tellers-mtproto/src/codec/decoder.rs
+87 −0 crates/tellers-mtproto/src/codec/encoder.rs
+143 −0 crates/tellers-mtproto/src/codec/error.rs
+26 −0 crates/tellers-mtproto/src/codec/mod.rs
+135 −0 crates/tellers-mtproto/src/codec/tests.rs
+79 −0 crates/tellers-mtproto/src/codec/traits.rs
+219 −0 crates/tellers-mtproto/src/codec/value.rs
+237,708 −0 crates/tellers-mtproto/src/layer_223/api.rs
+234,645 −0 crates/tellers-mtproto/src/layer_229/api.rs
+52 −0 crates/tellers-mtproto/src/lib.rs
+5,508 −0 crates/tellers-mtproto/src/secret_chat/layer_101.rs
+5,508 −0 crates/tellers-mtproto/src/secret_chat/layer_143.rs
+5,662 −0 crates/tellers-mtproto/src/secret_chat/layer_144.rs
+2,303 −0 crates/tellers-mtproto/src/secret_chat/layer_17.rs
+2,654 −0 crates/tellers-mtproto/src/secret_chat/layer_20.rs
+6,442 −0 crates/tellers-mtproto/src/secret_chat/layer_216.rs
+3,747 −0 crates/tellers-mtproto/src/secret_chat/layer_23.rs
+5,019 −0 crates/tellers-mtproto/src/secret_chat/layer_45.rs
+5,095 −0 crates/tellers-mtproto/src/secret_chat/layer_46.rs
+5,239 −0 crates/tellers-mtproto/src/secret_chat/layer_66.rs
+5,293 −0 crates/tellers-mtproto/src/secret_chat/layer_73.rs
+1,308 −0 crates/tellers-mtproto/src/secret_chat/layer_8.rs
+88 −0 crates/tellers-mtproto/src/secret_chat/mod.rs
+4,850 −0 crates/tellers-mtproto/src/transport.rs
+26 −0 crates/tellers-mtproto/tests/secret_chat.rs
+111 −0 crates/tellers-mtproto/tests/tracing_capture.rs
+10 −0 crates/tellers-mtproto/tests/version.rs
Loading