mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
Fix: Dont overwrite equal drafts (#6212)
This PR prevents overwriting drafts when the text and file are the same. close #6211 --------- Co-authored-by: l <link2xt@testrun.org>
This commit is contained in:
34
src/chat.rs
34
src/chat.rs
@@ -922,12 +922,16 @@ impl ChatId {
|
|||||||
&& old_draft.chat_id == self
|
&& old_draft.chat_id == self
|
||||||
&& old_draft.state == MessageState::OutDraft
|
&& old_draft.state == MessageState::OutDraft
|
||||||
{
|
{
|
||||||
context
|
let affected_rows = context
|
||||||
.sql
|
.sql.execute(
|
||||||
.execute(
|
|
||||||
"UPDATE msgs
|
"UPDATE msgs
|
||||||
SET timestamp=?,type=?,txt=?,txt_normalized=?,param=?,mime_in_reply_to=?
|
SET timestamp=?1,type=?2,txt=?3,txt_normalized=?4,param=?5,mime_in_reply_to=?6
|
||||||
WHERE id=?;",
|
WHERE id=?7
|
||||||
|
AND (type <> ?2
|
||||||
|
OR txt <> ?3
|
||||||
|
OR txt_normalized <> ?4
|
||||||
|
OR param <> ?5
|
||||||
|
OR mime_in_reply_to <> ?6);",
|
||||||
(
|
(
|
||||||
time(),
|
time(),
|
||||||
msg.viewtype,
|
msg.viewtype,
|
||||||
@@ -937,9 +941,8 @@ impl ChatId {
|
|||||||
msg.in_reply_to.as_deref().unwrap_or_default(),
|
msg.in_reply_to.as_deref().unwrap_or_default(),
|
||||||
msg.id,
|
msg.id,
|
||||||
),
|
),
|
||||||
)
|
).await?;
|
||||||
.await?;
|
return Ok(affected_rows > 0);
|
||||||
return Ok(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7696,4 +7699,19 @@ mod tests {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_do_not_overwrite_draft() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let alice = tcm.alice().await;
|
||||||
|
let mut msg = Message::new_text("This is a draft message".to_string());
|
||||||
|
let self_chat = alice.get_self_chat().await.id;
|
||||||
|
self_chat.set_draft(&alice, Some(&mut msg)).await.unwrap();
|
||||||
|
let draft1 = self_chat.get_draft(&alice).await?.unwrap();
|
||||||
|
SystemTime::shift(Duration::from_secs(1));
|
||||||
|
self_chat.set_draft(&alice, Some(&mut msg)).await.unwrap();
|
||||||
|
let draft2 = self_chat.get_draft(&alice).await?.unwrap();
|
||||||
|
assert_eq!(draft1.timestamp_sort, draft2.timestamp_sort);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user