Merge pull request #2050 from deltachat/restore-saved-messages-hint

add hint about how to restore saved-messages chat
This commit is contained in:
bjoern
2020-10-31 11:59:04 +01:00
committed by GitHub
3 changed files with 43 additions and 3 deletions

View File

@@ -4990,6 +4990,7 @@ void dc_event_unref(dc_event_t* event);
#define DC_STR_PROTECTION_ENABLED 88 #define DC_STR_PROTECTION_ENABLED 88
#define DC_STR_PROTECTION_DISABLED 89 #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_REPLY_NOUN 90 /* eg. "Reply", used in summaries, a noun, not a verb (not: "to reply") */
#define DC_STR_SELF_DELETED_MSG_BODY 91
/* /*
* @} * @}

View File

@@ -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. */ /* 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 context
.sql .sql
.execute( .execute(
@@ -373,6 +373,17 @@ impl ChatId {
let j = job::Job::new(Action::Housekeeping, 0, Params::new(), 10); let j = job::Job::new(Action::Housekeeping, 0, Params::new(), 10);
job::add(context, j).await; 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(()) Ok(())
} }

View File

@@ -244,6 +244,10 @@ pub enum StockMessage {
// used in summaries, a noun, not a verb (not: "to reply") // used in summaries, a noun, not a verb (not: "to reply")
#[strum(props(fallback = "Reply"))] #[strum(props(fallback = "Reply"))]
ReplyNoun = 90, 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,
} }
/* /*
@@ -463,6 +467,7 @@ mod tests {
use crate::constants::DC_CONTACT_ID_SELF; use crate::constants::DC_CONTACT_ID_SELF;
use crate::chat::Chat;
use crate::chatlist::Chatlist; use crate::chatlist::Chatlist;
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
@@ -654,8 +659,31 @@ mod tests {
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 2); assert_eq!(chats.len(), 2);
chats.get_chat_id(0).delete(&t.ctx).await.ok(); let chat0 = Chat::load_from_db(&t.ctx, chats.get_chat_id(0))
chats.get_chat_id(1).delete(&t.ctx).await.ok(); .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(); let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);