Skip to content

Commit c34ccaf

Browse files
committed
fix: Make reaction message hidden only if there are no other parts
RFC 9078 "Reaction: ..." doesn't forbid messages with reactions to have other parts, so be prepared for this.
1 parent 6837874 commit c34ccaf

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

src/reaction.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ mod tests {
404404
use crate::config::Config;
405405
use crate::contact::{Contact, Origin};
406406
use crate::download::DownloadState;
407-
use crate::message::{MessageState, delete_msgs};
407+
use crate::message::{MessageState, Viewtype, delete_msgs};
408408
use crate::receive_imf::{receive_imf, receive_imf_from_inbox};
409409
use crate::sql::housekeeping;
410410
use crate::test_utils::E2EE_INFO_MSGS;
@@ -550,6 +550,46 @@ Here's my footer -- [email protected]"
550550
let reactions = get_msg_reactions(&alice, msg.id).await?;
551551
assert_eq!(reactions.to_string(), "😀1");
552552

553+
// Alice receives a message with reaction to her message from Bob.
554+
let msg_bob = receive_imf(
555+
&alice,
556+
557+
558+
Date: Today, 29 February 2021 00:00:10 -800\n\
559+
Message-ID: [email protected]\n\
560+
In-Reply-To: [email protected]\n\
561+
Mime-Version: 1.0\n\
562+
Content-Type: multipart/mixed; boundary=\"YiEDa0DAkWCtVeE4\"\n\
563+
Content-Disposition: inline\n\
564+
\n\
565+
--YiEDa0DAkWCtVeE4\n\
566+
Content-Type: text/plain; charset=utf-8\n\
567+
Content-Disposition: inline\n\
568+
\n\
569+
Reply + reaction\n\
570+
\n\
571+
--YiEDa0DAkWCtVeE4\n\
572+
Content-Type: text/plain; charset=utf-8\n\
573+
Content-Disposition: reaction\n\
574+
\n\
575+
\u{1F44D}\n\
576+
\n\
577+
--YiEDa0DAkWCtVeE4--"
578+
.as_bytes(),
579+
false,
580+
)
581+
.await?
582+
.unwrap();
583+
let msg_bob = Message::load_from_db(&alice, msg_bob.msg_ids[0]).await?;
584+
assert_eq!(msg_bob.from_id, bob_id);
585+
assert_eq!(msg_bob.chat_id, msg.chat_id);
586+
assert_eq!(msg_bob.viewtype, Viewtype::Text);
587+
assert_eq!(msg_bob.state, MessageState::InFresh);
588+
assert_eq!(msg_bob.hidden, false);
589+
assert_eq!(msg_bob.text, "Reply + reaction");
590+
let reactions = get_msg_reactions(&alice, msg.id).await?;
591+
assert_eq!(reactions.to_string(), "👍1");
592+
553593
Ok(())
554594
}
555595

src/receive_imf.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ pub(crate) async fn receive_imf_inner(
763763
let show_emails = ShowEmails::from_i32(context.get_config_int(Config::ShowEmails).await?)
764764
.unwrap_or_default();
765765

766-
let is_reaction = mime_parser.parts.iter().any(|part| part.is_reaction);
767766
let allow_creation = if mime_parser.decrypting_failed {
768767
false
769768
} else if mime_parser.is_system_message != SystemMessage::AutocryptSetupMessage
@@ -777,7 +776,7 @@ pub(crate) async fn receive_imf_inner(
777776
ShowEmails::All => true,
778777
}
779778
} else {
780-
!is_reaction
779+
!mime_parser.parts.iter().all(|part| part.is_reaction)
781780
};
782781

783782
let to_id = if mime_parser.incoming {
@@ -1995,10 +1994,10 @@ async fn add_parts(
19951994

19961995
handle_edit_delete(context, mime_parser, from_id).await?;
19971996

1998-
let is_reaction = mime_parser.parts.iter().any(|part| part.is_reaction);
1999-
let hidden = is_reaction;
1997+
let hidden = mime_parser.parts.iter().all(|part| part.is_reaction);
20001998
let mut parts = mime_parser.parts.iter().peekable();
20011999
while let Some(part) = parts.next() {
2000+
let hidden = part.is_reaction;
20022001
if part.is_reaction {
20032002
let reaction_str = simplify::remove_footers(part.msg.as_str());
20042003
let is_incoming_fresh = mime_parser.incoming && !seen;

0 commit comments

Comments
 (0)