text stringlengths 0 357 |
|---|
/* add user marker */ |
if (curr_id==marker1before) { |
dc_array_add_id(ret, DC_MSG_ID_MARKER1); |
} |
/* add daymarker, if needed */ |
if (flags&DC_GCM_ADDDAYMARKER) { |
curr_local_timestamp = (time_t)sqlite3_column_int64(stmt, 1) + cnv_to_local; |
curr_day = curr_local_timestamp/DC_SECONDS_PER_DAY; |
if (curr_day!=last_day) { |
dc_array_add_id(ret, DC_MSG_ID_DAYMARKER); |
last_day = curr_day; |
} |
} |
dc_array_add_id(ret, curr_id); |
} |
success = 1; |
cleanup: |
sqlite3_finalize(stmt); |
//dc_log_info(context, 0, "Message list for chat #%i created in %.3f ms.", chat_id, (double)(clock()-start)*1000.0/CLOCKS_PER_SEC); |
if (success) { |
return ret; |
} |
else { |
if (ret) { |
dc_array_unref(ret); |
} |
return NULL; |
} |
} |
static uint32_t get_draft_msg_id(dc_context_t* context, uint32_t chat_id) |
{ |
uint32_t draft_msg_id = 0; |
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, |
"SELECT id FROM msgs WHERE chat_id=? AND state=?;"); |
sqlite3_bind_int(stmt, 1, chat_id); |
sqlite3_bind_int(stmt, 2, DC_STATE_OUT_DRAFT); |
if (sqlite3_step(stmt)==SQLITE_ROW) { |
draft_msg_id = sqlite3_column_int(stmt, 0); |
} |
sqlite3_finalize(stmt); |
return draft_msg_id; |
} |
static int set_draft_raw(dc_context_t* context, uint32_t chat_id, dc_msg_t* msg) |
{ |
// similar to as dc_set_draft() but does not emit an event |
sqlite3_stmt* stmt = NULL; |
char* pathNfilename = NULL; |
uint32_t prev_draft_msg_id = 0; |
int sth_changed = 0; |
// delete old draft |
prev_draft_msg_id = get_draft_msg_id(context, chat_id); |
if (prev_draft_msg_id) { |
dc_delete_msg_from_db(context, prev_draft_msg_id); |
sth_changed = 1; |
} |
// save new draft |
if (msg==NULL) |
{ |
goto cleanup; |
} |
else if (msg->type==DC_MSG_TEXT) |
{ |
if (msg->text==NULL || msg->text[0]==0) { |
goto cleanup; |
} |
} |
else if (DC_MSG_NEEDS_ATTACHMENT(msg->type)) |
{ |
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL); |
if (pathNfilename==NULL) { |
goto cleanup; |
} |
if (dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, pathNfilename)) { |
goto cleanup; |
} |
if (!dc_make_rel_and_copy(context, &pathNfilename)) { |
goto cleanup; |
} |
dc_param_set(msg->param, DC_PARAM_FILE, pathNfilename); |
} |
else |
{ |
goto cleanup; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.