text
stringlengths
0
357
}
static int set_from_stmt(dc_chat_t* chat, sqlite3_stmt* row)
{
int row_offset = 0;
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC || row==NULL) {
return 0;
}
dc_chat_empty(chat);
#define CHAT_FIELDS " c.id,c.type,c.name, c.grpid,c.param,c.archived, c.blocked, c.gossiped_timestamp, c.locations_send_until "
chat->id = sqlite3_column_int (row, row_offset++); /* the columns are defined in CHAT_FIELDS */
chat->type = sqlite3_column_int (row, row_offset++);
chat->name = dc_strdup((char*)sqlite3_column_text (row, row_offset++));
chat->grpid = dc_strdup((char*)sqlite3_column_text (row, row_offset++));
dc_param_set_packed(chat->param, (char*)sqlite3_column_text (row, row_offset++));
chat->archived = sqlite3_column_int (row, row_offset++);
chat->blocked = sqlite3_column_int (row, row_offset++);
chat->gossiped_timestamp = sqlite3_column_int64(row, row_offset++);
chat->is_sending_locations = (sqlite3_column_int64(row, row_offset++)>time(NULL));
/* correct the title of some special groups */
if (chat->id==DC_CHAT_ID_DEADDROP) {
free(chat->name);
chat->name = dc_stock_str(chat->context, DC_STR_DEADDROP);
}
else if (chat->id==DC_CHAT_ID_ARCHIVED_LINK) {
free(chat->name);
char* tempname = dc_stock_str(chat->context, DC_STR_ARCHIVEDCHATS);
chat->name = dc_mprintf("%s (%i)", tempname, dc_get_archived_cnt(chat->context));
free(tempname);
}
else if (chat->id==DC_CHAT_ID_STARRED) {
free(chat->name);
chat->name = dc_stock_str(chat->context, DC_STR_STARREDMSGS);
}
else if (dc_param_exists(chat->param, DC_PARAM_SELFTALK)) {
free(chat->name);
chat->name = dc_stock_str(chat->context, DC_STR_SELF);
}
return row_offset; /* success, return the next row offset */
}
/**
* Load a chat from the database to the chat object.
*
* @private @memberof dc_chat_t
* @param chat The chat object that should be filled with the data from the database.
* Existing data are free()'d before using dc_chat_empty().
* @param chat_id Chat ID that should be loaded from the database.
* @return 1=success, 0=error.
*/
int dc_chat_load_from_db(dc_chat_t* chat, uint32_t chat_id)
{
int success = 0;
sqlite3_stmt* stmt = NULL;
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
goto cleanup;
}
dc_chat_empty(chat);
stmt = dc_sqlite3_prepare(chat->context->sql,
"SELECT " CHAT_FIELDS " FROM chats c WHERE c.id=?;");
sqlite3_bind_int(stmt, 1, chat_id);
if (sqlite3_step(stmt)!=SQLITE_ROW) {
goto cleanup;
}
if (!set_from_stmt(chat, stmt)) {
goto cleanup;
}
success = 1;
cleanup:
sqlite3_finalize(stmt);
return success;
}
void dc_set_gossiped_timestamp(dc_context_t* context,
uint32_t chat_id, time_t timestamp)
{
sqlite3_stmt* stmt = NULL;
if (chat_id) {
dc_log_info(context, 0, "set gossiped_timestamp for chat #%i to %i.",
(int)chat_id, (int)timestamp);
stmt = dc_sqlite3_prepare(context->sql,
"UPDATE chats SET gossiped_timestamp=? WHERE id=?;");
sqlite3_bind_int64(stmt, 1, timestamp);