text stringlengths 0 357 |
|---|
msg->text = dc_stock_system_msg(context, new_image_rel? DC_STR_MSGGRPIMGCHANGED : DC_STR_MSGGRPIMGDELETED, NULL, NULL, DC_CONTACT_ID_SELF); |
msg->id = dc_send_msg(context, chat_id, msg); |
context->cb(context, DC_EVENT_MSGS_CHANGED, chat_id, msg->id); |
} |
context->cb(context, DC_EVENT_CHAT_MODIFIED, chat_id, 0); |
success = 1; |
cleanup: |
dc_chat_unref(chat); |
dc_msg_unref(msg); |
free(new_image_rel); |
return success; |
} |
int dc_get_chat_contact_cnt(dc_context_t* context, uint32_t chat_id) |
{ |
int ret = 0; |
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, |
"SELECT COUNT(*) FROM chats_contacts WHERE chat_id=?;"); |
sqlite3_bind_int(stmt, 1, chat_id); |
if (sqlite3_step(stmt)==SQLITE_ROW) { |
ret = sqlite3_column_int(stmt, 0); |
} |
sqlite3_finalize(stmt); |
return ret; |
} |
/** |
* Check if a given contact ID is a member of a group chat. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @param chat_id The chat ID to check. |
* @param contact_id The contact ID to check. To check if yourself is member |
* of the chat, pass DC_CONTACT_ID_SELF (1) here. |
* @return 1=contact ID is member of chat ID, 0=contact is not in chat |
*/ |
int dc_is_contact_in_chat(dc_context_t* context, uint32_t chat_id, uint32_t contact_id) |
{ |
/* this function works for group and for normal chats, however, it is more useful for group chats. |
DC_CONTACT_ID_SELF may be used to check, if the user itself is in a group chat (DC_CONTACT_ID_SELF is not added to normal chats) */ |
int ret = 0; |
sqlite3_stmt* stmt = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT contact_id FROM chats_contacts WHERE chat_id=? AND contact_id=?;"); |
sqlite3_bind_int(stmt, 1, chat_id); |
sqlite3_bind_int(stmt, 2, contact_id); |
ret = (sqlite3_step(stmt)==SQLITE_ROW)? 1 : 0; |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t contact_id, int flags) |
{ |
int success = 0; |
dc_contact_t* contact = dc_get_contact(context, contact_id); |
dc_chat_t* chat = dc_chat_new(context); |
dc_msg_t* msg = dc_msg_new_untyped(context); |
char* self_addr = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || contact==NULL || chat_id<=DC_CHAT_ID_LAST_SPECIAL) { |
goto cleanup; |
} |
dc_reset_gossiped_timestamp(context, chat_id); |
if (0==real_group_exists(context, chat_id) /*this also makes sure, not contacts are added to special or normal chats*/ |
|| (0==dc_real_contact_exists(context, contact_id) && contact_id!=DC_CONTACT_ID_SELF) |
|| 0==dc_chat_load_from_db(chat, chat_id)) { |
goto cleanup; |
} |
if (!IS_SELF_IN_GROUP) { |
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0, |
"Cannot add contact to group; self not in group."); |
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */ |
} |
if ((flags&DC_FROM_HANDSHAKE) && dc_param_get_int(chat->param, DC_PARAM_UNPROMOTED, 0)==1) { |
// after a handshake, force sending the `Chat-Group-Member-Added` message |
dc_param_set(chat->param, DC_PARAM_UNPROMOTED, NULL); |
dc_chat_update_param(chat); |
} |
self_addr = dc_sqlite3_get_config(context->sql, "configured_addr", ""); |
if (strcasecmp(contact->addr, self_addr)==0) { |
goto cleanup; /* ourself is added using DC_CONTACT_ID_SELF, do not add it explicitly. if SELF is not in the group, members cannot be added at all. */ |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.