text stringlengths 0 357 |
|---|
if (dc_is_contact_in_chat(context, chat_id, contact_id)) |
{ |
if (!(flags&DC_FROM_HANDSHAKE)) { |
success = 1; |
goto cleanup; |
} |
// else continue and send status mail |
} |
else |
{ |
if (chat->type==DC_CHAT_TYPE_VERIFIED_GROUP) |
{ |
if (dc_contact_is_verified(contact)!=DC_BIDIRECT_VERIFIED) { |
dc_log_error(context, 0, "Only bidirectional verified contacts can be added to verified groups."); |
goto cleanup; |
} |
} |
if (0==dc_add_to_chat_contacts_table(context, chat_id, contact_id)) { |
goto cleanup; |
} |
} |
/* send a status mail to all group members */ |
if (DO_SEND_STATUS_MAILS) |
{ |
msg->type = DC_MSG_TEXT; |
msg->text = dc_stock_system_msg(context, DC_STR_MSGADDMEMBER, contact->addr, NULL, DC_CONTACT_ID_SELF); |
dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_MEMBER_ADDED_TO_GROUP); |
dc_param_set (msg->param, DC_PARAM_CMD_ARG, contact->addr); |
dc_param_set_int(msg->param, DC_PARAM_CMD_ARG2, flags); // combine the Secure-Join protocol headers with the Chat-Group-Member-Added header |
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_contact_unref(contact); |
dc_msg_unref(msg); |
free(self_addr); |
return success; |
} |
/** |
* Add a member to a group. |
* |
* If the group is already _promoted_ (any message was sent to the group), |
* all group members are informed by a special status message that is sent automatically by this function. |
* |
* If the group is a verified group, only verified contacts can be added to the group. |
* |
* Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @param chat_id The chat ID to add the contact to. Must be a group chat. |
* @param contact_id The contact ID to add to the chat. |
* @return 1=member added to group, 0=error |
*/ |
int dc_add_contact_to_chat(dc_context_t* context, uint32_t chat_id, uint32_t contact_id /*may be DC_CONTACT_ID_SELF*/) |
{ |
return dc_add_contact_to_chat_ex(context, chat_id, contact_id, 0); |
} |
/** |
* Remove a member from a group. |
* |
* If the group is already _promoted_ (any message was sent to the group), |
* all group members are informed by a special status message that is sent automatically by this function. |
* |
* Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @param chat_id The chat ID to remove the contact from. Must be a group chat. |
* @param contact_id The contact ID to remove from the chat. |
* @return 1=member removed from group, 0=error |
*/ |
int dc_remove_contact_from_chat(dc_context_t* context, uint32_t chat_id, uint32_t contact_id /*may be DC_CONTACT_ID_SELF*/) |
{ |
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* q3 = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_id<=DC_CHAT_ID_LAST_SPECIAL || (contact_id<=DC_CONTACT_ID_LAST_SPECIAL && contact_id!=DC_CONTACT_ID_SELF)) { |
goto cleanup; /* we do not check if "contact_id" exists but just delete all records with the id from chats_contacts */ |
} /* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */ |
if (0==real_group_exists(context, chat_id) |
|| 0==dc_chat_load_from_db(chat, chat_id)) { |
goto cleanup; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.