text
stringlengths
0
357
if (!IS_SELF_IN_GROUP) {
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0,
"Cannot remove contact from chat; self not in group.");
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
}
/* send a status mail to all group members - we need to do this before we update the database -
otherwise the !IS_SELF_IN_GROUP__-check in dc_chat_send_msg() will fail. */
if (contact)
{
if (DO_SEND_STATUS_MAILS)
{
msg->type = DC_MSG_TEXT;
if (contact->id==DC_CONTACT_ID_SELF) {
dc_set_group_explicitly_left(context, chat->grpid);
msg->text = dc_stock_system_msg(context, DC_STR_MSGGROUPLEFT, NULL, NULL, DC_CONTACT_ID_SELF);
}
else {
msg->text = dc_stock_system_msg(context, DC_STR_MSGDELMEMBER, contact->addr, NULL, DC_CONTACT_ID_SELF);
}
dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_MEMBER_REMOVED_FROM_GROUP);
dc_param_set (msg->param, DC_PARAM_CMD_ARG, contact->addr);
msg->id = dc_send_msg(context, chat_id, msg);
context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->id);
}
}
q3 = sqlite3_mprintf("DELETE FROM chats_contacts WHERE chat_id=%i AND contact_id=%i;", chat_id, contact_id);
if (!dc_sqlite3_execute(context->sql, q3)) {
goto cleanup;
}
context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0);
success = 1;
cleanup:
sqlite3_free(q3);
dc_chat_unref(chat);
dc_contact_unref(contact);
dc_msg_unref(msg);
return success;
}
/*******************************************************************************
* Sending messages
******************************************************************************/
static int last_msg_in_chat_encrypted(dc_sqlite3_t* sql, uint32_t chat_id)
{
int last_is_encrypted = 0;
sqlite3_stmt* stmt = dc_sqlite3_prepare(sql,
"SELECT param "
" FROM msgs "
" WHERE timestamp=(SELECT MAX(timestamp) FROM msgs WHERE chat_id=?) "
" ORDER BY id DESC;");
sqlite3_bind_int(stmt, 1, chat_id);
if (sqlite3_step(stmt)==SQLITE_ROW) {
dc_param_t* msg_param = dc_param_new();
dc_param_set_packed(msg_param, (char*)sqlite3_column_text(stmt, 0));
if (dc_param_exists(msg_param, DC_PARAM_GUARANTEE_E2EE)) {
last_is_encrypted = 1;
}
dc_param_unref(msg_param);
}
sqlite3_finalize(stmt);
return last_is_encrypted;
}
static int get_parent_mime_headers(const dc_chat_t* chat,
char** parent_rfc724_mid,
char** parent_in_reply_to,
char** parent_references)
{
int success = 0;
sqlite3_stmt* stmt = NULL;
if (chat==NULL
|| parent_rfc724_mid==NULL || parent_in_reply_to==NULL || parent_references==NULL) {
goto cleanup;
}
// use the last messsage of another user in the group as the parent
stmt = dc_sqlite3_prepare(chat->context->sql,
"SELECT rfc724_mid, mime_in_reply_to, mime_references"
" FROM msgs"
" WHERE chat_id=? AND timestamp=(SELECT max(timestamp) FROM msgs WHERE chat_id=? AND from_id!=?);");
sqlite3_bind_int (stmt, 1, chat->id);
sqlite3_bind_int (stmt, 2, chat->id);
sqlite3_bind_int (stmt, 3, DC_CONTACT_ID_SELF);
if (sqlite3_step(stmt)==SQLITE_ROW) {
*parent_rfc724_mid = dc_strdup((const char*)sqlite3_column_text(stmt, 0));
*parent_in_reply_to = dc_strdup((const char*)sqlite3_column_text(stmt, 1));
*parent_references = dc_strdup((const char*)sqlite3_column_text(stmt, 2));
success = 1;
}
sqlite3_finalize(stmt);