text stringlengths 0 357 |
|---|
stmt = dc_sqlite3_prepare(context->sql, |
"INSERT INTO msgs (chat_id, from_id, timestamp," |
" type, state, txt, param, hidden)" |
" VALUES (?,?,?, ?,?,?,?,?);"); |
sqlite3_bind_int (stmt, 1, chat_id); |
sqlite3_bind_int (stmt, 2, DC_CONTACT_ID_SELF); |
sqlite3_bind_int64(stmt, 3, time(NULL)); |
sqlite3_bind_int (stmt, 4, msg->type); |
sqlite3_bind_int (stmt, 5, DC_STATE_OUT_DRAFT); |
sqlite3_bind_text (stmt, 6, msg->text? msg->text : "", -1, SQLITE_STATIC); |
sqlite3_bind_text (stmt, 7, msg->param->packed, -1, SQLITE_STATIC); |
sqlite3_bind_int (stmt, 8, 1); |
if (sqlite3_step(stmt)!=SQLITE_DONE) { |
goto cleanup; |
} |
sth_changed = 1; |
cleanup: |
sqlite3_finalize(stmt); |
free(pathNfilename); |
return sth_changed; |
} |
/** |
* Save a draft for a chat in the database. |
* |
* The UI should call this function if the user has prepared a message |
* and exits the compose window without clicking the "send" button before. |
* When the user later opens the same chat again, |
* the UI can load the draft using dc_get_draft() |
* allowing the user to continue editing and sending. |
* |
* Drafts are considered when sorting messages |
* and are also returned eg. by dc_chatlist_get_summary(). |
* |
* Each chat can have its own draft but only one draft per chat is possible. |
* |
* If the draft is modified, an #DC_EVENT_MSGS_CHANGED will be sent. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @param chat_id The chat ID to save the draft for. |
* @param msg The message to save as a draft. |
* Existing draft will be overwritten. |
* NULL deletes the existing draft, if any, without sending it. |
* Currently, also non-text-messages |
* will delete the existing drafts. |
* @return None. |
*/ |
void dc_set_draft(dc_context_t* context, uint32_t chat_id, dc_msg_t* msg) |
{ |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_id<=DC_CHAT_ID_LAST_SPECIAL) { |
return; |
} |
if (set_draft_raw(context, chat_id, msg)) { |
context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, 0); |
} |
} |
/** |
* Get draft for a chat, if any. |
* See dc_set_draft() for more details about drafts. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @param chat_id The chat ID to get the draft for. |
* @return Message object. |
* Can be passed directly to dc_send_msg(). |
* Must be freed using dc_msg_unref() after usage. |
* If there is no draft, NULL is returned. |
*/ |
dc_msg_t* dc_get_draft(dc_context_t* context, uint32_t chat_id) |
{ |
uint32_t draft_msg_id = 0; |
dc_msg_t* draft_msg = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC |
|| chat_id<=DC_CHAT_ID_LAST_SPECIAL) { |
return NULL; |
} |
draft_msg_id = get_draft_msg_id(context, chat_id); |
if (draft_msg_id==0) { |
return NULL; |
} |
draft_msg = dc_msg_new_untyped(context); |
if (!dc_msg_load_from_db(draft_msg, context, draft_msg_id)) { |
dc_msg_unref(draft_msg); |
return NULL; |
} |
return draft_msg; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.