text
stringlengths
0
357
/* the event is needed eg. to remove the deaddrop from the chatlist */
if (send_event) {
context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0);
}
cleanup:
if (transaction_pending) { dc_sqlite3_rollback(context->sql); }
sqlite3_finalize(stmt);
}
int dc_mdn_from_ext(dc_context_t* context, uint32_t from_id, const char* rfc724_mid, time_t timestamp_sent,
uint32_t* ret_chat_id, uint32_t* ret_msg_id)
{
int read_by_all = 0;
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || from_id<=DC_CONTACT_ID_LAST_SPECIAL || rfc724_mid==NULL || ret_chat_id==NULL || ret_msg_id==NULL
|| *ret_chat_id!=0 || *ret_msg_id!=0) {
goto cleanup;
}
stmt = dc_sqlite3_prepare(context->sql,
"SELECT m.id, c.id, c.type, m.state FROM msgs m "
" LEFT JOIN chats c ON m.chat_id=c.id "
" WHERE rfc724_mid=? AND from_id=1 "
" ORDER BY m.id;"); /* the ORDER BY makes sure, if one rfc724_mid is splitted into its parts, we always catch the same one. However, we do not send multiparts, we do not request MDNs for multiparts, and should not receive read requests for multiparts. So this is currently more theoretical. */
sqlite3_bind_text(stmt, 1, rfc724_mid, -1, SQLITE_STATIC);
if (sqlite3_step(stmt)!=SQLITE_ROW) {
goto cleanup;
}
*ret_msg_id = sqlite3_column_int(stmt, 0);
*ret_chat_id = sqlite3_column_int(stmt, 1);
int chat_type = sqlite3_column_int(stmt, 2);
int msg_state = sqlite3_column_int(stmt, 3);
sqlite3_finalize(stmt);
stmt = NULL;
if (msg_state!=DC_STATE_OUT_PREPARING &&
msg_state!=DC_STATE_OUT_PENDING &&
msg_state!=DC_STATE_OUT_DELIVERED)
{
goto cleanup; /* eg. already marked as MDNS_RCVD. however, it is importent, that the message ID is set above as this will allow the caller eg. to move the message away */
}
// collect receipt senders, we do this also for normal chats as we may want to show the timestamp
stmt = dc_sqlite3_prepare(context->sql,
"SELECT contact_id FROM msgs_mdns WHERE msg_id=? AND contact_id=?;");
sqlite3_bind_int(stmt, 1, *ret_msg_id);
sqlite3_bind_int(stmt, 2, from_id);
int mdn_already_in_table = (sqlite3_step(stmt)==SQLITE_ROW)? 1 : 0;
sqlite3_finalize(stmt);
stmt = NULL;
if (!mdn_already_in_table) {
stmt = dc_sqlite3_prepare(context->sql,
"INSERT INTO msgs_mdns (msg_id, contact_id, timestamp_sent) VALUES (?, ?, ?);");
sqlite3_bind_int (stmt, 1, *ret_msg_id);
sqlite3_bind_int (stmt, 2, from_id);
sqlite3_bind_int64(stmt, 3, timestamp_sent);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
stmt = NULL;
}
// Normal chat? that's quite easy.
if (chat_type==DC_CHAT_TYPE_SINGLE) {
dc_update_msg_state(context, *ret_msg_id, DC_STATE_OUT_MDN_RCVD);
read_by_all = 1;
goto cleanup; /* send event about new state */
}
// Group chat: get the number of receipt senders
stmt = dc_sqlite3_prepare(context->sql,
"SELECT COUNT(*) FROM msgs_mdns WHERE msg_id=?;");
sqlite3_bind_int(stmt, 1, *ret_msg_id);
if (sqlite3_step(stmt)!=SQLITE_ROW) {
goto cleanup; /* error */
}
int ist_cnt = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
stmt = NULL;
/*
Groupsize: Min. MDNs
1 S n/a
2 SR 1
3 SRR 2
4 SRRR 2
5 SRRRR 3
6 SRRRRR 3
(S=Sender, R=Recipient)
*/
int soll_cnt = (dc_get_chat_contact_cnt(context, *ret_chat_id)+1/*for rounding, SELF is already included!*/) / 2;
if (ist_cnt < soll_cnt) {
goto cleanup; /* wait for more receipts */
}