text stringlengths 0 357 |
|---|
if (ret_chat_id) { *ret_chat_id = chat_id; } |
if (ret_chat_blocked) { *ret_chat_blocked = create_blocked; } |
} |
/** |
* Get the total number of messages in a chat. |
* |
* @memberof dc_context_t |
* @param context The context object as returned from dc_context_new(). |
* @param chat_id The ID of the chat to count the messages for. |
* @return Number of total messages in the given chat. 0 for errors or empty chats. |
*/ |
int dc_get_msg_cnt(dc_context_t* context, uint32_t chat_id) |
{ |
int ret = 0; |
sqlite3_stmt* stmt = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT COUNT(*) FROM msgs WHERE chat_id=?;"); |
sqlite3_bind_int(stmt, 1, chat_id); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
ret = sqlite3_column_int(stmt, 0); |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
void dc_unarchive_chat(dc_context_t* context, uint32_t chat_id) |
{ |
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, |
"UPDATE chats SET archived=0 WHERE id=?"); |
sqlite3_bind_int (stmt, 1, chat_id); |
sqlite3_step(stmt); |
sqlite3_finalize(stmt); |
} |
/** |
* Get the number of _fresh_ messages in a chat. Typically used to implement |
* a badge with a number in the chatlist. |
* |
* @memberof dc_context_t |
* @param context The context object as returned from dc_context_new(). |
* @param chat_id The ID of the chat to count the messages for. |
* @return Number of fresh messages in the given chat. 0 for errors or if there are no fresh messages. |
*/ |
int dc_get_fresh_msg_cnt(dc_context_t* context, uint32_t chat_id) |
{ |
int ret = 0; |
sqlite3_stmt* stmt = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT COUNT(*) FROM msgs " |
" WHERE state=" DC_STRINGIFY(DC_STATE_IN_FRESH) |
" AND hidden=0 " |
" AND chat_id=?;"); /* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */ |
sqlite3_bind_int(stmt, 1, chat_id); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
ret = sqlite3_column_int(stmt, 0); |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
/** |
* Archive or unarchive a chat. |
* |
* Archived chats are not included in the default chatlist returned |
* by dc_get_chatlist(). Instead, if there are _any_ archived chats, |
* the pseudo-chat with the chat_id DC_CHAT_ID_ARCHIVED_LINK will be added the the |
* end of the chatlist. |
* |
* - To get a list of archived chats, use dc_get_chatlist() with the flag DC_GCL_ARCHIVED_ONLY. |
* - To find out the archived state of a given chat, use dc_chat_get_archived() |
* - Messages in archived chats are marked as being noticed, so they do not count as "fresh" |
* - Calling this function usually results in the event #DC_EVENT_MSGS_CHANGED |
* |
* @memberof dc_context_t |
* @param context The context object as returned from dc_context_new(). |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.