Skip to content

Commit

Permalink
fix: Emit MsgsNoticed on receipt of an IMAP-seen message
Browse files Browse the repository at this point in the history
`imap::Session::sync_seen_flags()` emits `MsgsNoticed` for existing messages seen on other devices,
so `receive_imf` should do the same when it receives a seen message. Otherwise a multi-device user
may see a new message notification on device A, just swipe it, then see another new message
notification and mark it as read, and when their device B goes online, it will show a notification
for the first message, and it won't be removed because `MsgsNoticed` isn't emitted. I have checked
this with my DC Android and Desktop. With this fix the notification should be removed at least.
  • Loading branch information
iequidoo committed Dec 20, 2024
1 parent 3af4ea1 commit e8d5e50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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 received_msg.state == MessageState::InSeen {
context.emit_event(EventType::MsgsNoticed(chat_id));
}
context.new_msgs_notify.notify_one();

mime_parser
Expand Down
25 changes: 25 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

0 comments on commit e8d5e50

Please sign in to comment.