Skip to content

Commit 5399cbf

Browse files
committed
fix: Update state of message when fully downloading it
If a message partially downloaded before is already IMAP-seen upon a full download, it should be updated to `InSeen`. OTOH if it's not IMAP-seen, but already `InNoticed` locally, its state should be preserved. So we take the maximum of two states.
1 parent 8da1fae commit 5399cbf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/message.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,40 @@ mod tests {
26642664
Ok(())
26652665
}
26662666

2667+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2668+
async fn test_msg_seen_on_imap_when_downloaded() -> Result<()> {
2669+
let mut tcm = TestContextManager::new();
2670+
let alice = &tcm.alice().await;
2671+
alice.set_config(Config::DownloadLimit, Some("1")).await?;
2672+
let bob = &tcm.bob().await;
2673+
let bob_chat_id = tcm.send_recv_accept(alice, bob, "hi").await.chat_id;
2674+
2675+
let file_bytes = include_bytes!("../test-data/image/screenshot.png");
2676+
let mut msg = Message::new(Viewtype::Image);
2677+
msg.set_file_from_bytes(bob, "a.jpg", file_bytes, None)
2678+
.await?;
2679+
let sent_msg = bob.send_msg(bob_chat_id, &mut msg).await;
2680+
let msg = alice.recv_msg(&sent_msg).await;
2681+
assert_eq!(msg.download_state, DownloadState::Available);
2682+
assert_eq!(msg.state, MessageState::InFresh);
2683+
2684+
alice.set_config(Config::DownloadLimit, None).await?;
2685+
let seen = true;
2686+
let rcvd_msg = receive_imf(alice, sent_msg.payload().as_bytes(), seen)
2687+
.await
2688+
.unwrap()
2689+
.unwrap();
2690+
assert_eq!(rcvd_msg.chat_id, msg.chat_id);
2691+
let msg = Message::load_from_db(alice, *rcvd_msg.msg_ids.last().unwrap())
2692+
.await
2693+
.unwrap();
2694+
assert_eq!(msg.download_state, DownloadState::Done);
2695+
assert!(msg.param.get_bool(Param::WantsMdn).unwrap_or_default());
2696+
assert!(msg.get_showpadlock());
2697+
assert_eq!(msg.state, MessageState::InSeen);
2698+
Ok(())
2699+
}
2700+
26672701
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
26682702
async fn test_get_state() -> Result<()> {
26692703
let alice = TestContext::new_alice().await;

src/receive_imf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ INSERT INTO msgs
15751575
ON CONFLICT (id) DO UPDATE
15761576
SET rfc724_mid=excluded.rfc724_mid, chat_id=excluded.chat_id,
15771577
from_id=excluded.from_id, to_id=excluded.to_id, timestamp_sent=excluded.timestamp_sent,
1578-
type=excluded.type, msgrmsg=excluded.msgrmsg,
1578+
type=excluded.type, state=max(state,excluded.state), msgrmsg=excluded.msgrmsg,
15791579
txt=excluded.txt, txt_normalized=excluded.txt_normalized, subject=excluded.subject,
15801580
txt_raw=excluded.txt_raw, param=excluded.param,
15811581
hidden=excluded.hidden,bytes=excluded.bytes, mime_headers=excluded.mime_headers,

0 commit comments

Comments
 (0)