Skip to content

Commit

Permalink
fix: Downgrade message state to InNoticed when it's fully downloaded (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
iequidoo committed Oct 16, 2024
1 parent e37dd84 commit f2abfd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2618,12 +2618,29 @@ mod tests {
);

alice.set_config(Config::DownloadLimit, None).await?;
let msg = alice.recv_msg(&sent_msg).await;
// Simulate that the message is even marked as `\Seen` on IMAP.
let rcvd_msg = receive_imf(alice, sent_msg.payload().as_bytes(), true)
.await
.unwrap()
.unwrap();
assert_eq!(rcvd_msg.chat_id, msg.chat_id);
let msg = Message::load_from_db(alice, *rcvd_msg.msg_ids.last().unwrap())
.await
.unwrap();
assert_eq!(msg.download_state, DownloadState::Done);
assert!(msg.param.get_bool(Param::WantsMdn).unwrap_or_default());
assert!(msg.get_showpadlock());
assert_eq!(msg.state, MessageState::InNoticed);
markseen_msgs(alice, vec![msg.id]).await?;
let msg = Message::load_from_db(alice, msg.id).await?;
assert_eq!(msg.state, MessageState::InSeen);

assert_eq!(
alice
.sql
.count("SELECT COUNT(*) FROM smtp_mdns", ())
.await?,
1
);
Ok(())
}

Expand Down
6 changes: 4 additions & 2 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,15 @@ async fn add_parts(
}
}

state = if seen
state = if (seen && replace_msg_id.is_none())
|| fetching_existing_messages
|| is_mdn
|| is_reaction
|| chat_id_blocked == Blocked::Yes
{
MessageState::InSeen
} else if seen {
MessageState::InNoticed
} else {
MessageState::InFresh
};
Expand Down Expand Up @@ -1562,7 +1564,7 @@ INSERT INTO msgs
ON CONFLICT (id) DO UPDATE
SET rfc724_mid=excluded.rfc724_mid, chat_id=excluded.chat_id,
from_id=excluded.from_id, to_id=excluded.to_id, timestamp_sent=excluded.timestamp_sent,
type=excluded.type, msgrmsg=excluded.msgrmsg,
type=excluded.type, state=min(state,max(excluded.state,13)), msgrmsg=excluded.msgrmsg,
txt=excluded.txt, txt_normalized=excluded.txt_normalized, subject=excluded.subject,
txt_raw=excluded.txt_raw, param=excluded.param,
hidden=excluded.hidden,bytes=excluded.bytes, mime_headers=excluded.mime_headers,
Expand Down

0 comments on commit f2abfd5

Please sign in to comment.