text
stringlengths
0
357
/**
* Mark all messages in a chat as _noticed_.
* _Noticed_ messages are no longer _fresh_ and do not count as being unseen
* but are still waiting for being marked as "seen" using dc_markseen_msgs()
* (IMAP/MDNs is not done for noticed messages).
*
* Calling this function usually results in the event #DC_EVENT_MSGS_CHANGED.
* See also dc_marknoticed_all_chats(), dc_marknoticed_contact() and dc_markseen_msgs().
*
* @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.
* @return None.
*/
void dc_marknoticed_chat(dc_context_t* context, uint32_t chat_id)
{
sqlite3_stmt* check = NULL;
sqlite3_stmt* update = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
// as there is no thread-safe way to find out the affected rows
// and as we want to send the event only on changes,
// we first check if there is sth. to update.
// there is a chance of a race condition,
// however, this would result in an additional event only.
check = dc_sqlite3_prepare(context->sql,
"SELECT id FROM msgs "
" WHERE chat_id=? AND state=" DC_STRINGIFY(DC_STATE_IN_FRESH) ";");
sqlite3_bind_int(check, 1, chat_id);
if (sqlite3_step(check)!=SQLITE_ROW) {
goto cleanup;
}
update = dc_sqlite3_prepare(context->sql,
"UPDATE msgs "
" SET state=" DC_STRINGIFY(DC_STATE_IN_NOTICED)
" WHERE chat_id=? AND state=" DC_STRINGIFY(DC_STATE_IN_FRESH) ";");
sqlite3_bind_int(update, 1, chat_id);
sqlite3_step(update);
context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0);
cleanup:
sqlite3_finalize(check);
sqlite3_finalize(update);
}
/**
* Same as dc_marknoticed_chat() but for _all_ chats.
*
* @memberof dc_context_t
* @param context The context object as returned from dc_context_new().
* @return None.
*/
void dc_marknoticed_all_chats(dc_context_t* context)
{
sqlite3_stmt* check = NULL;
sqlite3_stmt* update = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
check = dc_sqlite3_prepare(context->sql,
"SELECT id FROM msgs "
" WHERE state=" DC_STRINGIFY(DC_STATE_IN_FRESH) ";");
if (sqlite3_step(check)!=SQLITE_ROW) {
goto cleanup;
}
update = dc_sqlite3_prepare(context->sql,
"UPDATE msgs "
" SET state=" DC_STRINGIFY(DC_STATE_IN_NOTICED)
" WHERE state=" DC_STRINGIFY(DC_STATE_IN_FRESH) ";");
sqlite3_step(update);
context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0);
cleanup:
sqlite3_finalize(check);
sqlite3_finalize(update);
}
/**
* Check, if there is a normal chat with a given contact.
* To get the chat messages, use dc_get_chat_msgs().
*
* @memberof dc_context_t
* @param context The context object as returned from dc_context_new().
* @param contact_id The contact ID to check.
* @return If there is a normal chat with the given contact_id, this chat_id is
* returned. If there is no normal chat with the contact_id, the function
* returns 0.
*/
uint32_t dc_get_chat_id_by_contact_id(dc_context_t* context, uint32_t contact_id)
{