chatmail / chatmail/core

Self-MDN handling in `receive_imf_inner()` may mark as noticed messages which haven't been actually noticed on other devices

Open
#8,363 0 comments 0 reactions 1 assignee Claimed by @iequidoo View on GitHub
bug
Dominant language
Rust
Stars
929
Forks
143
Avg merge
1d 20h
Merged PRs (30d)
53

Description

Creating an issue because there's already #8263 apparently fixing this in most cases, but maybe we want to fix it in a better way.

Since ef265689dd713327edab6489d773899135046ebc messages in a chat are sorted basically by Date, so delayed messages may be inserted in the middle of the chat, but this is fine because they are `InFresh` and UIs should scroll to the first fresh message when the chat opens. However, there's a logic in `receive_imf_inner()` marking all preceding chat messages as noticed when a self-MDN is received: https://github.com/chatmail/core/blob/8b80ac146fbaf5bfe6b6393fc9edf41ae219a766/src/receive_imf.rs#L980-L995
Some of such messages may be delayed and might not be actually noticed on the device which issued the MDN. This may lead to notifications wrongly removed. A possible scenario:
- The user reads a chat on device A in offline mode, self-MDNs for the read messages are pending for being sent.
- A delayed message arrives and gets inserted above already existing messages on device B.
- Device A goes online and sends the self-MDNs.
- All notifications are removed from device B. Also if the user opens the chat, it's not scrolled to the delayed message.

A partial solution implemented in #8263 is to not mark messages added to the db later as noticed, i.e. change the condition `(timestamp,id)<(?,?)` (which actually reflects message sorting) to a stricter `timestamp<=? AND id

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.