let dc_marknoticed_chat() also handle the virtual deaddrop chat

This commit is contained in:
B. Petersen
2021-04-22 15:31:19 +02:00
committed by bjoern
parent 949e671d9c
commit 39d3a594af
2 changed files with 31 additions and 4 deletions

View File

@@ -1078,9 +1078,9 @@ int dc_estimate_deletion_cnt (dc_context_t* context, int from_ser
* or badge counters eg. on the app-icon. * or badge counters eg. on the app-icon.
* The list is already sorted and starts with the most recent fresh message. * The list is already sorted and starts with the most recent fresh message.
* *
* Messages belonging to muted chats are not returned, * Messages belonging to muted chats or to the deaddrop are not returned;
* as they should not be notified * these messages should not be notified
* and also a badge counters should not include messages of muted chats. * and also badge counters should not include these messages.
* *
* To get the number of fresh messages for a single chat, muted or not, * To get the number of fresh messages for a single chat, muted or not,
* use dc_get_fresh_msg_cnt(). * 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 * @memberof dc_context_t
* @param context The context object as returned from dc_context_new(). * @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); void dc_marknoticed_chat (dc_context_t* context, uint32_t chat_id);

View File

@@ -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> { 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 // "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 let exists = context
.sql .sql
.exists( .exists(