From e04c4446d686f5821a38469ee4aa46fd48affdf2 Mon Sep 17 00:00:00 2001 From: Septias Date: Wed, 20 Nov 2024 12:52:17 +0100 Subject: [PATCH] fix: Disable setting draft if not in chat --- src/chat.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 84aebb78a..6af2f2d68 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -809,7 +809,8 @@ impl ChatId { /// /// Passing `None` as message just deletes the draft pub async fn set_draft(self, context: &Context, mut msg: Option<&mut Message>) -> Result<()> { - if self.is_special() { + let self_in_chat = is_contact_in_chat(context, self, ContactId::SELF).await?; + if self.is_special() || !self_in_chat { return Ok(()); } @@ -4919,7 +4920,7 @@ mod tests { // Alice removes bob, so draft is not shown in chat info. remove_contact_from_chat(&alice, chat_id, bob_contact).await?; - bob.recv_msg(&mut alice.pop_sent_msg().await).await; + bob.recv_msg(&alice.pop_sent_msg().await).await; let chat = Chat::load_from_db(&bob, bob_chat_id).await?; assert!(!chat.can_send(&bob).await?); let info = chat.get_info(&bob).await?; @@ -4944,6 +4945,17 @@ mod tests { let info = chat.get_info(&bob).await?; assert_eq!(info.draft, String::from("")); + // Bob can not set a draft if not in chat. + bob_chat_id + .set_draft( + &bob, + Some(&mut Message::new_text(String::from( + "I'm gonna send this fr fr!!", + ))), + ) + .await?; + assert_eq!(bob_chat_id.get_draft(&bob).await?.unwrap().text, draft); + Ok(()) }