text
stringlengths
0
357
goto cleanup;
}
stmt = dc_sqlite3_prepare(context->sql,
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);");
sqlite3_bind_int (stmt, 1, chat_id);
sqlite3_bind_int (stmt, 2, DC_CONTACT_ID_DEVICE);
sqlite3_bind_int (stmt, 3, DC_CONTACT_ID_DEVICE);
sqlite3_bind_int64(stmt, 4, dc_create_smeared_timestamp(context));
sqlite3_bind_int (stmt, 5, DC_MSG_TEXT);
sqlite3_bind_int (stmt, 6, DC_STATE_IN_NOTICED);
sqlite3_bind_text (stmt, 7, text, -1, SQLITE_STATIC);
sqlite3_bind_text (stmt, 8, rfc724_mid, -1, SQLITE_STATIC);
if (sqlite3_step(stmt)!=SQLITE_DONE) {
goto cleanup;
}
msg_id = dc_sqlite3_get_rowid(context->sql, "msgs", "rfc724_mid", rfc724_mid);
context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg_id);
cleanup:
free(rfc724_mid);
sqlite3_finalize(stmt);
}
/**
* Forward messages to another chat.
*
* @memberof dc_context_t
* @param context The context object as created by dc_context_new()
* @param msg_ids An array of uint32_t containing all message IDs that should be forwarded
* @param msg_cnt The number of messages IDs in the msg_ids array
* @param chat_id The destination chat ID.
* @return None.
*/
void dc_forward_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt, uint32_t chat_id)
{
dc_msg_t* msg = dc_msg_new_untyped(context);
dc_chat_t* chat = dc_chat_new(context);
dc_contact_t* contact = dc_contact_new(context);
int transaction_pending = 0;
carray* created_db_entries = carray_new(16);
char* idsstr = NULL;
char* q3 = NULL;
sqlite3_stmt* stmt = NULL;
time_t curr_timestamp = 0;
dc_param_t* original_param = dc_param_new();
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || msg_ids==NULL || msg_cnt<=0 || chat_id<=DC_CHAT_ID_LAST_SPECIAL) {
goto cleanup;
}
dc_sqlite3_begin_transaction(context->sql);
transaction_pending = 1;
dc_unarchive_chat(context, chat_id);
context->smtp->log_connect_errors = 1;
if (!dc_chat_load_from_db(chat, chat_id)) {
goto cleanup;
}
curr_timestamp = dc_create_smeared_timestamps(context, msg_cnt);
idsstr = dc_arr_to_string(msg_ids, msg_cnt);
q3 = sqlite3_mprintf("SELECT id FROM msgs WHERE id IN(%s) ORDER BY timestamp,id", idsstr);
stmt = dc_sqlite3_prepare(context->sql, q3);
while (sqlite3_step(stmt)==SQLITE_ROW)
{
int src_msg_id = sqlite3_column_int(stmt, 0);
if (!dc_msg_load_from_db(msg, context, src_msg_id)) {
goto cleanup;
}
dc_param_set_packed(original_param, msg->param->packed);
// do not mark own messages as being forwarded.
// this allows sort of broadcasting
// by just forwarding messages to other chats.
if (msg->from_id!=DC_CONTACT_ID_SELF) {
dc_param_set_int(msg->param, DC_PARAM_FORWARDED, 1);
}
dc_param_set(msg->param, DC_PARAM_GUARANTEE_E2EE, NULL);
dc_param_set(msg->param, DC_PARAM_FORCE_PLAINTEXT, NULL);
dc_param_set(msg->param, DC_PARAM_CMD, NULL);
uint32_t new_msg_id;
// PREPARING messages can't be forwarded immediately
if (msg->state==DC_STATE_OUT_PREPARING) {
new_msg_id = prepare_msg_raw(context, chat, msg, curr_timestamp++);
// to update the original message, perform in-place surgery
// on msg to avoid copying the entire structure, text, etc.
dc_param_t* save_param = msg->param;
msg->param = original_param;
msg->id = src_msg_id;
{
// append new id to the original's param.