Skip to content
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

fix: Emit MsgsNoticed on receipt of an IMAP-seen message #6415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions src/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,9 @@ impl Session {
context.on_archived_chats_maybe_noticed();
}
for updated_chat_id in updated_chat_ids {
// NB: There are no other events that remove notifications at least for messages seen on
// other devices, so while we may also remove useful notifications for newer messages,
// we have no other choice.
context.emit_event(EventType::MsgsNoticed(updated_chat_id));
chatlist_events::emit_chatlist_item_changed(context, updated_chat_id);
}
Expand Down
26 changes: 26 additions & 0 deletions src/reaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,32 @@ Here's my footer -- [email protected]"
let reactions = get_msg_reactions(&alice, msg.id).await?;
assert_eq!(reactions.to_string(), "😀1");

// Alice receives a seen reaction to her message from Bob. Reactions are assigned to the
// trash chat and shouldn't cause emitting `MsgsNoticed`.
alice.evtracker.clear_events();
let seen = true;
receive_imf(
&alice,
"To: [email protected]\n\
From: [email protected]\n\
Date: Today, 29 February 2021 00:00:10 -800\n\
Message-ID: [email protected]\n\
In-Reply-To: [email protected]\n\
Subject: Meeting\n\
Mime-Version: 1.0 (1.0)\n\
Content-Type: text/plain; charset=utf-8\n\
Content-Disposition: reaction\n\
\n\
\u{1F44D}"
.as_bytes(),
seen,
)
.await?;
let ev = alice
.evtracker
.get_matching_opt(&alice, |e| matches!(e, EventType::MsgsNoticed { .. }))
.await;
assert!(ev.is_none());
Ok(())
}

Expand Down
3 changes: 3 additions & 0 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ pub(crate) async fn receive_imf_inner(
chat_id.emit_msg_event(context, *msg_id, mime_parser.incoming && fresh);
}
}
if !chat_id.is_trash() && received_msg.state == MessageState::InSeen {
context.emit_event(EventType::MsgsNoticed(chat_id));
}
context.new_msgs_notify.notify_one();

mime_parser
Expand Down
54 changes: 54 additions & 0 deletions src/receive_imf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ async fn test_adhoc_groups_merge() -> Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_msgs_noticed_on_seen_msg() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let seen = true;
let rcvd_msg = receive_imf(
alice,
b"From: [email protected]\n\
To: [email protected]\n\
Message-ID: <[email protected]>\n\
Date: Sun, 22 Mar 2020 22:37:57 +0000\n\
\n\
This is a seen message.\n",
seen,
)
.await?
.unwrap();
let ev = alice
.evtracker
.get_matching(|e| matches!(e, EventType::MsgsNoticed { .. }))
.await;
assert_eq!(ev, EventType::MsgsNoticed(rcvd_msg.chat_id));
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_read_receipt_and_unarchive() -> Result<()> {
// create alice's account
Expand Down Expand Up @@ -3009,6 +3034,35 @@ async fn test_read_receipts_dont_unmark_bots() -> Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_no_msgs_noticed_on_seen_mdn() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;

let received_msg = tcm.send_recv_accept(alice, bob, "hi").await;

let mdn_mimefactory = crate::mimefactory::MimeFactory::from_mdn(
bob,
received_msg.from_id,
received_msg.rfc724_mid,
vec![],
)
.await?;
let rendered_mdn = mdn_mimefactory.render(bob).await?;
let mdn_body = rendered_mdn.message;

let seen = true;
alice.evtracker.clear_events();
receive_imf(alice, mdn_body.as_bytes(), seen).await?;
let ev = alice
.evtracker
.get_matching_opt(alice, |e| matches!(e, EventType::MsgsNoticed { .. }))
.await;
assert!(ev.is_none());
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_gmx_forwarded_msg() -> Result<()> {
let t = TestContext::new_alice().await;
Expand Down
Loading