Skip to content

Commit

Permalink
fix: Don't recode images in Viewtype::File messages (#5617)
Browse files Browse the repository at this point in the history
  • Loading branch information
iequidoo committed May 22, 2024
1 parent 907d3ef commit 25b4993
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,21 @@ mod tests {
.await
.unwrap();

send_image_check_mediaquality(
Viewtype::File,
Some("1"),
bytes,
"png",
false, // no Exif
1920,
1080,
0,
1920,
1080,
)
.await
.unwrap();

// This will be sent as Image, see [`BlobObject::maybe_sticker`] for explanation.
send_image_check_mediaquality(
Viewtype::Sticker,
Expand Down
6 changes: 4 additions & 2 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,7 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
.get_blob(Param::File, context, !msg.is_increation())
.await?
.with_context(|| format!("attachment missing for message of type #{}", msg.viewtype))?;
let send_as_is = msg.viewtype == Viewtype::File;

if msg.viewtype == Viewtype::File || msg.viewtype == Viewtype::Image {
// Correct the type, take care not to correct already very special
Expand All @@ -2645,8 +2646,9 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> {
}

let mut maybe_sticker = msg.viewtype == Viewtype::Sticker;
if msg.viewtype == Viewtype::Image
|| maybe_sticker && !msg.param.exists(Param::ForceSticker)
if !send_as_is
&& (msg.viewtype == Viewtype::Image
|| maybe_sticker && !msg.param.exists(Param::ForceSticker))
{
blob.recode_to_image_size(context, &mut maybe_sticker)
.await?;
Expand Down

0 comments on commit 25b4993

Please sign in to comment.