text stringlengths 0 357 |
|---|
* the draft of the chat is set to a default text, |
* the group has one member with the ID DC_CONTACT_ID_SELF |
* and is in _unpromoted_ state. |
* This means, you can add or remove members, change the name, |
* the group image and so on without messages being sent to all group members. |
* |
* This changes as soon as the first message is sent to the group members |
* and the group becomes _promoted_. |
* After that, all changes are synced with all group members |
* by sending status message. |
* |
* To check, if a chat is still unpromoted, you dc_chat_is_unpromoted(). |
* This may be useful if you want to show some help for just created groups. |
* |
* @memberof dc_context_t |
* @param context The context as created by dc_context_new(). |
* @param verified If set to 1 the function creates a secure verified group. |
* Only secure-verified members are allowed in these groups |
* and end-to-end-encryption is always enabled. |
* @param chat_name The name of the group chat to create. |
* The name may be changed later using dc_set_chat_name(). |
* To find out the name of a group later, see dc_chat_get_name() |
* @return The chat ID of the new group chat, 0 on errors. |
*/ |
uint32_t dc_create_group_chat(dc_context_t* context, int verified, const char* chat_name) |
{ |
uint32_t chat_id = 0; |
char* draft_txt = NULL; |
dc_msg_t* draft_msg = NULL; |
char* grpid = NULL; |
sqlite3_stmt* stmt = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_name==NULL || chat_name[0]==0) { |
return 0; |
} |
draft_txt = dc_stock_str_repl_string(context, DC_STR_NEWGROUPDRAFT, chat_name); |
grpid = dc_create_id(); |
stmt = dc_sqlite3_prepare(context->sql, |
"INSERT INTO chats (type, name, grpid, param) VALUES(?, ?, ?, 'U=1');" /*U=DC_PARAM_UNPROMOTED*/); |
sqlite3_bind_int (stmt, 1, verified? DC_CHAT_TYPE_VERIFIED_GROUP : DC_CHAT_TYPE_GROUP); |
sqlite3_bind_text (stmt, 2, chat_name, -1, SQLITE_STATIC); |
sqlite3_bind_text (stmt, 3, grpid, -1, SQLITE_STATIC); |
if ( sqlite3_step(stmt)!=SQLITE_DONE) { |
goto cleanup; |
} |
if ((chat_id=dc_sqlite3_get_rowid(context->sql, "chats", "grpid", grpid))==0) { |
goto cleanup; |
} |
if (!dc_add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF)) { |
goto cleanup; |
} |
draft_msg = dc_msg_new(context, DC_MSG_TEXT); |
dc_msg_set_text(draft_msg, draft_txt); |
set_draft_raw(context, chat_id, draft_msg); |
cleanup: |
sqlite3_finalize(stmt); |
free(draft_txt); |
dc_msg_unref(draft_msg); |
free(grpid); |
if (chat_id) { |
context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); |
} |
return chat_id; |
} |
/** |
* Set group name. |
* |
* 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 chat_id The chat ID to set the name for. Must be a group chat. |
* @param new_name New name of the group. |
* @param context The context as created by dc_context_new(). |
* @return 1=success, 0=error |
*/ |
int dc_set_chat_name(dc_context_t* context, uint32_t chat_id, const char* new_name) |
{ |
/* the function only sets the names of group chats; normal chats get their names from the contacts */ |
int success = 0; |
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 || new_name==NULL || new_name[0]==0 || chat_id<=DC_CHAT_ID_LAST_SPECIAL) { |
goto cleanup; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.