text
stringlengths
0
357
* @param chat_id The ID of the chat to archive or unarchive.
* @param archive 1=archive chat, 0=unarchive chat, all other values are reserved for future use
* @return None.
*/
void dc_archive_chat(dc_context_t* context, uint32_t chat_id, int archive)
{
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_id<=DC_CHAT_ID_LAST_SPECIAL || (archive!=0 && archive!=1)) {
return;
}
if (archive) {
sqlite3_stmt* stmt = 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(stmt, 1, chat_id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql,
"UPDATE chats SET archived=? WHERE id=?;");
sqlite3_bind_int (stmt, 1, archive);
sqlite3_bind_int (stmt, 2, chat_id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0);
}
void dc_block_chat(dc_context_t* context, uint32_t chat_id, int new_blocking)
{
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
return;
}
stmt = dc_sqlite3_prepare(context->sql,
"UPDATE chats SET blocked=? WHERE id=?;");
sqlite3_bind_int(stmt, 1, new_blocking);
sqlite3_bind_int(stmt, 2, chat_id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
void dc_unblock_chat(dc_context_t* context, uint32_t chat_id)
{
dc_block_chat(context, chat_id, DC_CHAT_NOT_BLOCKED);
}
/**
* Delete a chat.
*
* Messages are deleted from the device and the chat database entry is deleted.
* After that, the event #DC_EVENT_MSGS_CHANGED is posted.
*
* Things that are _not_ done implicitly:
*
* - Messages are **not deleted from the server**.
* - The chat or the contact is **not blocked**, so new messages from the user/the group may appear
* and the user may create the chat again.
* - **Groups are not left** - this would
* be unexpected as (1) deleting a normal chat also does not prevent new mails
* from arriving, (2) leaving a group requires sending a message to
* all group members - especially for groups not used for a longer time, this is
* really unexpected when deletion results in contacting all members again,
* (3) only leaving groups is also a valid usecase.
*
* To leave a chat explicitly, use dc_remove_contact_from_chat() with
* chat_id=DC_CONTACT_ID_SELF)
*
* @memberof dc_context_t
* @param context The context object as returned from dc_context_new().
* @param chat_id The ID of the chat to delete.
* @return None.
*/
void dc_delete_chat(dc_context_t* context, uint32_t chat_id)
{
/* Up to 2017-11-02 deleting a group also implied leaving it, see above why we have changed this. */
int pending_transaction = 0;
dc_chat_t* obj = dc_chat_new(context);
char* q3 = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_id<=DC_CHAT_ID_LAST_SPECIAL) {
goto cleanup;
}
if (!dc_chat_load_from_db(obj, chat_id)) {
goto cleanup;
}
dc_sqlite3_begin_transaction(context->sql);
pending_transaction = 1;
q3 = sqlite3_mprintf("DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=%i);", chat_id);
if (!dc_sqlite3_execute(context->sql, q3)) {
goto cleanup;