-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: forceSticker viewtype #4814
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2207,11 +2207,12 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<()> { | |
.await? | ||
.with_context(|| format!("attachment missing for message of type #{}", msg.viewtype))?; | ||
|
||
let mut maybe_sticker = msg.viewtype == Viewtype::Sticker; | ||
let mut maybe_sticker = | ||
msg.viewtype == Viewtype::Sticker || msg.viewtype == Viewtype::ForceSticker; | ||
if msg.viewtype == Viewtype::Image || maybe_sticker { | ||
blob.recode_to_image_size(context, &mut maybe_sticker) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd better pass viewtype here then. Otherwise it can be processed/recoded as an image while being a sticker There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this function be called at all for stickers that cannot be images? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think yes, it removes Exif from all files also |
||
.await?; | ||
if !maybe_sticker { | ||
if !maybe_sticker && msg.viewtype != Viewtype::ForceSticker { | ||
msg.viewtype = Viewtype::Image; | ||
} | ||
} | ||
|
@@ -3573,7 +3574,7 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId) | |
// by not marking own forwarded messages as such, | ||
// however, this turned out to be to confusing and unclear. | ||
|
||
if msg.get_viewtype() != Viewtype::Sticker { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, why do we have this logic for stickers? |
||
if msg.get_viewtype() != Viewtype::Sticker && msg.get_viewtype() != Viewtype::ForceSticker { | ||
msg.param | ||
.set_int(Param::Forwarded, src_msg_id.to_u32() as i32); | ||
} | ||
|
@@ -5618,6 +5619,7 @@ mod tests { | |
async fn test_sticker( | ||
filename: &str, | ||
bytes: &[u8], | ||
viewtype: Viewtype, | ||
res_viewtype: Viewtype, | ||
w: i32, | ||
h: i32, | ||
|
@@ -5630,12 +5632,12 @@ mod tests { | |
let file = alice.get_blobdir().join(filename); | ||
tokio::fs::write(&file, bytes).await?; | ||
|
||
let mut msg = Message::new(Viewtype::Sticker); | ||
let mut msg = Message::new(viewtype); | ||
msg.set_file(file.to_str().unwrap(), None); | ||
|
||
let sent_msg = alice.send_msg(alice_chat.id, &mut msg).await; | ||
let mime = sent_msg.payload(); | ||
if res_viewtype == Viewtype::Sticker { | ||
if res_viewtype == Viewtype::Sticker || res_viewtype == Viewtype::ForceSticker { | ||
assert_eq!(mime.match_indices("Chat-Content: sticker").count(), 1); | ||
} | ||
|
||
|
@@ -5644,7 +5646,7 @@ mod tests { | |
assert_eq!(msg.get_viewtype(), res_viewtype); | ||
let msg_filename = msg.get_filename().unwrap(); | ||
match res_viewtype { | ||
Viewtype::Sticker => assert_eq!(msg_filename, filename), | ||
Viewtype::Sticker | Viewtype::ForceSticker => assert_eq!(msg_filename, filename), | ||
Viewtype::Image => assert!(msg_filename.starts_with("image_")), | ||
_ => panic!("Not implemented"), | ||
} | ||
|
@@ -5661,6 +5663,7 @@ mod tests { | |
"sticker.png", | ||
include_bytes!("../test-data/image/logo.png"), | ||
Viewtype::Sticker, | ||
Viewtype::Sticker, | ||
135, | ||
135, | ||
) | ||
|
@@ -5672,19 +5675,34 @@ mod tests { | |
test_sticker( | ||
"sticker.jpg", | ||
include_bytes!("../test-data/image/avatar1000x1000.jpg"), | ||
Viewtype::Sticker, | ||
Viewtype::Image, | ||
1000, | ||
1000, | ||
) | ||
.await | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_sticker_jpeg_force() -> Result<()> { | ||
test_sticker( | ||
"sticker.jpg", | ||
include_bytes!("../test-data/image/avatar1000x1000.jpg"), | ||
Viewtype::ForceSticker, | ||
Viewtype::Sticker, | ||
1000, | ||
1000, | ||
) | ||
.await | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_sticker_gif() -> Result<()> { | ||
test_sticker( | ||
"sticker.gif", | ||
include_bytes!("../test-data/image/logo.gif"), | ||
Viewtype::Sticker, | ||
Viewtype::Sticker, | ||
135, | ||
135, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1858,6 +1858,12 @@ pub enum Viewtype { | |
/// A click on a sticker will offer to install the sticker set in some future. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather add a comment here that it can be converted to Image using some heuristics |
||
Sticker = 23, | ||
|
||
/// Message containing a sticker, similar to image. | ||
/// If possible, the ui should display the image without borders in a transparent way. | ||
/// A click on a sticker will offer to install the sticker set in some future. | ||
/// This stick is guaranteed to be displayed as a stick in the ui. | ||
ForceSticker = 24, | ||
|
||
/// Message containing an Audio file. | ||
/// File and duration are set via dc_msg_set_file(), dc_msg_set_duration() | ||
/// and retrieved via dc_msg_get_file(), dc_msg_get_duration(). | ||
|
@@ -1898,6 +1904,7 @@ impl Viewtype { | |
Viewtype::Image => true, | ||
Viewtype::Gif => true, | ||
Viewtype::Sticker => true, | ||
Viewtype::ForceSticker => true, | ||
Viewtype::Audio => true, | ||
Viewtype::Voice => true, | ||
Viewtype::Video => true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be a new function to not break desktop, but I think this adjustment is fine @Simon-Laux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah as long as it is mentioned as breaking api change in the changelog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to always force viewtype in JSON-RPC as we do not need heuristics on desktop currently.