text
stringlengths
0
357
if (0==real_group_exists(context, chat_id)
|| 0==dc_chat_load_from_db(chat, chat_id)) {
goto cleanup;
}
if (strcmp(chat->name, new_name)==0) {
success = 1;
goto cleanup; /* name not modified */
}
if (!IS_SELF_IN_GROUP) {
dc_log_event(context, DC_EVENT_ERROR_SELF_NOT_IN_GROUP, 0,
"Cannot set chat name; self not in group");
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
}
q3 = sqlite3_mprintf("UPDATE chats SET name=%Q WHERE id=%i;", new_name, chat_id);
if (!dc_sqlite3_execute(context->sql, q3)) {
goto cleanup;
}
/* send a status mail to all group members, also needed for outself to allow multi-client */
if (DO_SEND_STATUS_MAILS)
{
msg->type = DC_MSG_TEXT;
msg->text = dc_stock_system_msg(context, DC_STR_MSGGRPNAME, chat->name, new_name, DC_CONTACT_ID_SELF);
dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_GROUPNAME_CHANGED);
dc_param_set (msg->param, DC_PARAM_CMD_ARG, chat->name);
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:
sqlite3_free(q3);
dc_chat_unref(chat);
dc_msg_unref(msg);
return success;
}
/**
* Set group profile image.
*
* 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.
*
* To find out the profile image of a chat, use dc_chat_get_profile_image()
*
* @memberof dc_context_t
* @param context The context as created by dc_context_new().
* @param chat_id The chat ID to set the image for.
* @param new_image Full path of the image to use as the group image. If you pass NULL here,
* the group image is deleted (for promoted groups, all members are informed about this change anyway).
* @return 1=success, 0=error
*/
int dc_set_chat_profile_image(dc_context_t* context, uint32_t chat_id, const char* new_image /*NULL=remove image*/)
{
int success = 0;
dc_chat_t* chat = dc_chat_new(context);
dc_msg_t* msg = dc_msg_new_untyped(context);
char* new_image_rel = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_id<=DC_CHAT_ID_LAST_SPECIAL) {
goto cleanup;
}
if (0==real_group_exists(context, chat_id)
|| 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 set chat profile image; self not in group.");
goto cleanup; /* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
}
if (new_image) {
new_image_rel = dc_strdup(new_image);
if (!dc_make_rel_and_copy(context, &new_image_rel)) {
goto cleanup;
}
}
dc_param_set(chat->param, DC_PARAM_PROFILE_IMAGE, new_image_rel/*may be NULL*/);
if (!dc_chat_update_param(chat)) {
goto cleanup;
}
/* send a status mail to all group members, also needed for outself to allow multi-client */
if (DO_SEND_STATUS_MAILS)
{
dc_param_set_int(msg->param, DC_PARAM_CMD, DC_CMD_GROUPIMAGE_CHANGED);
dc_param_set (msg->param, DC_PARAM_CMD_ARG, new_image_rel);
msg->type = DC_MSG_TEXT;