Skip to content

Commit 8da1fae

Browse files
committed
fix: markseen_msgs: Limit not yet downloaded messages state to InNoticed (#2970)
This fixes sending MDNs for big messages when they are downloaded and really seen. Otherwise MDNs are not sent for big encrypted messages because they "don't want MDN" until downloaded.
1 parent eabf1d1 commit 8da1fae

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

src/message.rs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
16931693
m.id AS id,
16941694
m.chat_id AS chat_id,
16951695
m.state AS state,
1696+
m.download_state as download_state,
16961697
m.ephemeral_timer AS ephemeral_timer,
16971698
m.param AS param,
16981699
m.from_id AS from_id,
@@ -1708,6 +1709,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
17081709
let id: MsgId = row.get("id")?;
17091710
let chat_id: ChatId = row.get("chat_id")?;
17101711
let state: MessageState = row.get("state")?;
1712+
let download_state: DownloadState = row.get("download_state")?;
17111713
let param: Params = row.get::<_, String>("param")?.parse().unwrap_or_default();
17121714
let from_id: ContactId = row.get("from_id")?;
17131715
let rfc724_mid: String = row.get("rfc724_mid")?;
@@ -1719,6 +1721,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
17191721
id,
17201722
chat_id,
17211723
state,
1724+
download_state,
17221725
param,
17231726
from_id,
17241727
rfc724_mid,
@@ -1748,6 +1751,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
17481751
id,
17491752
curr_chat_id,
17501753
curr_state,
1754+
curr_download_state,
17511755
curr_param,
17521756
curr_from_id,
17531757
curr_rfc724_mid,
@@ -1757,7 +1761,14 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
17571761
_curr_ephemeral_timer,
17581762
) in msgs
17591763
{
1760-
if curr_state == MessageState::InFresh || curr_state == MessageState::InNoticed {
1764+
if curr_download_state != DownloadState::Done {
1765+
if curr_state == MessageState::InFresh {
1766+
// Don't mark partially downloaded messages as seen or send a read receipt since
1767+
// they are not really seen by the user.
1768+
update_msg_state(context, id, MessageState::InNoticed).await?;
1769+
updated_chat_ids.insert(curr_chat_id);
1770+
}
1771+
} else if curr_state == MessageState::InFresh || curr_state == MessageState::InNoticed {
17611772
update_msg_state(context, id, MessageState::InSeen).await?;
17621773
info!(context, "Seen message {}.", id);
17631774

@@ -2601,8 +2612,28 @@ mod tests {
26012612
assert!(!msg.param.get_bool(Param::WantsMdn).unwrap_or_default());
26022613
assert_eq!(msg.state, MessageState::InFresh);
26032614
markseen_msgs(alice, vec![msg.id]).await?;
2604-
let msg = Message::load_from_db(alice, msg.id).await?;
2605-
assert_eq!(msg.state, MessageState::InSeen);
2615+
// A not downloaded message can be seen only if it's seen on another device.
2616+
assert_eq!(msg.id.get_state(alice).await?, MessageState::InNoticed);
2617+
// Marking the message as seen again is a no op.
2618+
markseen_msgs(alice, vec![msg.id]).await?;
2619+
assert_eq!(msg.id.get_state(alice).await?, MessageState::InNoticed);
2620+
2621+
msg.id
2622+
.update_download_state(alice, DownloadState::InProgress)
2623+
.await?;
2624+
markseen_msgs(alice, vec![msg.id]).await?;
2625+
assert_eq!(msg.id.get_state(alice).await?, MessageState::InNoticed);
2626+
msg.id
2627+
.update_download_state(alice, DownloadState::Failure)
2628+
.await?;
2629+
markseen_msgs(alice, vec![msg.id]).await?;
2630+
assert_eq!(msg.id.get_state(alice).await?, MessageState::InNoticed);
2631+
msg.id
2632+
.update_download_state(alice, DownloadState::Undecipherable)
2633+
.await?;
2634+
markseen_msgs(alice, vec![msg.id]).await?;
2635+
assert_eq!(msg.id.get_state(alice).await?, MessageState::InNoticed);
2636+
26062637
assert!(
26072638
!alice
26082639
.sql
@@ -2611,12 +2642,25 @@ mod tests {
26112642
);
26122643

26132644
alice.set_config(Config::DownloadLimit, None).await?;
2645+
// Let's assume that Alice and Bob resolved the problem with encryption.
2646+
let old_msg = msg;
26142647
let msg = alice.recv_msg(&sent_msg).await;
2648+
assert_eq!(msg.chat_id, old_msg.chat_id);
26152649
assert_eq!(msg.download_state, DownloadState::Done);
26162650
assert!(msg.param.get_bool(Param::WantsMdn).unwrap_or_default());
26172651
assert!(msg.get_showpadlock());
2652+
// The message state mustn't be downgraded to `InFresh`.
2653+
assert_eq!(msg.state, MessageState::InNoticed);
2654+
markseen_msgs(alice, vec![msg.id]).await?;
2655+
let msg = Message::load_from_db(alice, msg.id).await?;
26182656
assert_eq!(msg.state, MessageState::InSeen);
2619-
2657+
assert_eq!(
2658+
alice
2659+
.sql
2660+
.count("SELECT COUNT(*) FROM smtp_mdns", ())
2661+
.await?,
2662+
1
2663+
);
26202664
Ok(())
26212665
}
26222666

0 commit comments

Comments
 (0)