From 4c4a9b52de6a0108182a74ebd59e6cd421f4c4b9 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 27 Oct 2020 14:26:23 +0100 Subject: [PATCH 1/2] show hint how to restore saved-messages the saved-messages can be deleted as any other chat; if the feature is unneeded, this probably also makes some sense. however, if saved-messages was deleted accidentally (yeah, i've seen that :), it is not intuitive to see how the saved-messages feature can be restored. this change just drops a note about how-to-restore to the device chat. --- deltachat-ffi/deltachat.h | 1 + src/chat.rs | 13 ++++++++++++- src/stock.rs | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 1843c4f0b..5e01cd239 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -4988,6 +4988,7 @@ void dc_event_unref(dc_event_t* event); #define DC_STR_PROTECTION_ENABLED 88 #define DC_STR_PROTECTION_DISABLED 89 #define DC_STR_REPLY_NOUN 90 /* eg. "Reply", used in summaries, a noun, not a verb (not: "to reply") */ +#define DC_STR_SELF_DELETED_MSG_BODY 91 /* * @} diff --git a/src/chat.rs b/src/chat.rs index 86bae829a..10f375041 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -337,7 +337,7 @@ impl ChatId { ); /* Up to 2017-11-02 deleting a group also implied leaving it, see above why we have changed this. */ - let _chat = Chat::load_from_db(context, self).await?; + let chat = Chat::load_from_db(context, self).await?; context .sql .execute( @@ -373,6 +373,17 @@ impl ChatId { let j = job::Job::new(Action::Housekeeping, 0, Params::new(), 10); job::add(context, j).await; + if chat.is_self_talk() { + let mut msg = Message::new(Viewtype::Text); + msg.text = Some( + context + .stock_str(StockMessage::SelfDeletedMsgBody) + .await + .into(), + ); + add_device_msg(&context, None, Some(&mut msg)).await?; + } + Ok(()) } diff --git a/src/stock.rs b/src/stock.rs index 29ee70c35..787772411 100644 --- a/src/stock.rs +++ b/src/stock.rs @@ -244,6 +244,10 @@ pub enum StockMessage { // used in summaries, a noun, not a verb (not: "to reply") #[strum(props(fallback = "Reply"))] ReplyNoun = 90, + + #[strum(props(fallback = "You deleted the \"Saved messages\" chat.\n\n\ + To use the \"Saved messages\" feature again, create a new chat with yourself."))] + SelfDeletedMsgBody = 91, } /* From b2b59852a73c4f7f074364a2a8600287b758544a Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Tue, 27 Oct 2020 14:30:23 +0100 Subject: [PATCH 2/2] adapt test for updating device chats --- src/stock.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/stock.rs b/src/stock.rs index 787772411..77b2bdb3c 100644 --- a/src/stock.rs +++ b/src/stock.rs @@ -467,6 +467,7 @@ mod tests { use crate::constants::DC_CONTACT_ID_SELF; + use crate::chat::Chat; use crate::chatlist::Chatlist; use num_traits::ToPrimitive; @@ -658,8 +659,31 @@ mod tests { let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); assert_eq!(chats.len(), 2); - chats.get_chat_id(0).delete(&t.ctx).await.ok(); - chats.get_chat_id(1).delete(&t.ctx).await.ok(); + let chat0 = Chat::load_from_db(&t.ctx, chats.get_chat_id(0)) + .await + .unwrap(); + let (self_talk_id, device_chat_id) = if chat0.is_self_talk() { + (chats.get_chat_id(0), chats.get_chat_id(1)) + } else { + (chats.get_chat_id(1), chats.get_chat_id(0)) + }; + + // delete self-talk first; this adds a message to device-chat about how self-talk can be restored + let device_chat_msgs_before = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None) + .await + .len(); + self_talk_id.delete(&t.ctx).await.ok(); + assert_eq!( + chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None) + .await + .len(), + device_chat_msgs_before + 1 + ); + + // delete device chat + device_chat_id.delete(&t.ctx).await.ok(); + + // check, that the chatlist is empty let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); assert_eq!(chats.len(), 0);