From 39d3a594af2b6775c84d8eddf64c39f21ce078c6 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 22 Apr 2021 15:31:19 +0200 Subject: [PATCH] let dc_marknoticed_chat() also handle the virtual deaddrop chat --- deltachat-ffi/deltachat.h | 9 +++++---- src/chat.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index b92a23aed..5134ee60a 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -1078,9 +1078,9 @@ int dc_estimate_deletion_cnt (dc_context_t* context, int from_ser * or badge counters eg. on the app-icon. * The list is already sorted and starts with the most recent fresh message. * - * Messages belonging to muted chats are not returned, - * as they should not be notified - * and also a badge counters should not include messages of muted chats. + * Messages belonging to muted chats or to the deaddrop are not returned; + * these messages should not be notified + * and also badge counters should not include these messages. * * To get the number of fresh messages for a single chat, muted or not, * use dc_get_fresh_msg_cnt(). @@ -1104,7 +1104,8 @@ dc_array_t* dc_get_fresh_msgs (dc_context_t* context); * * @memberof dc_context_t * @param context The context object as returned from dc_context_new(). - * @param chat_id The chat ID of which all messages should be marked as being noticed. + * @param chat_id The chat ID of which all messages should be marked as being noticed + * (this also works for the virtual chat ID DC_CHAT_ID_DEADDROP). */ void dc_marknoticed_chat (dc_context_t* context, uint32_t chat_id); diff --git a/src/chat.rs b/src/chat.rs index eb5c11336..df1f10d57 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1987,7 +1987,33 @@ pub(crate) async fn marknoticed_chat_if_older_than( } pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(), Error> { + // for the virtual deaddrop chat-id, + // mark all messages that will appear in the deaddrop as noticed + if chat_id.is_deaddrop() { + if context + .sql + .execute( + "UPDATE msgs + SET state=?1 + WHERE state=?2 + AND hidden=0 + AND chat_id IN (SELECT id FROM chats WHERE blocked=?3);", + paramsv![ + MessageState::InNoticed, + MessageState::InFresh, + Blocked::Deaddrop + ], + ) + .await? + > 0 + { + context.emit_event(EventType::MsgsNoticed(chat_id)); + } + return Ok(()); + } + // "WHERE" below uses the index `(state, hidden, chat_id)`, see get_fresh_msg_cnt() for reasoning + // the additional SELECT statement may speed up things as no write-blocking is needed. let exists = context .sql .exists(