MCPcopy Create free account
hub / github.com/chatmail/core / create_group_ex

Function create_group_ex

src/chat.rs:3555–3616  ·  view source on GitHub ↗

Creates a group chat. `sync` - Whether a multi-device synchronization message should be sent. Ignored for unencrypted chats currently. `grpid` - Group ID. Iff nonempty, the chat is encrypted (with key-contacts). `name` - Chat name.

(
    context: &Context,
    sync: sync::Sync,
    grpid: String,
    name: &str,
)

Source from the content-addressed store, hash-verified

3553/// * `grpid` - Group ID. Iff nonempty, the chat is encrypted (with key-contacts).
3554/// * `name` - Chat name.
3555pub(crate) async fn create_group_ex(
3556 context: &Context,
3557 sync: sync::Sync,
3558 grpid: String,
3559 name: &str,
3560) -> Result<ChatId> {
3561 let mut chat_name = sanitize_single_line(name);
3562 if chat_name.is_empty() {
3563 // We can't just fail because the user would lose the work already done in the UI like
3564 // selecting members.
3565 error!(context, "Invalid chat name: {name}.");
3566 chat_name = "…".to_string();
3567 }
3568
3569 let timestamp = time();
3570 let row_id = context
3571 .sql
3572 .insert(
3573 "INSERT INTO chats
3574 (type, name, name_normalized, grpid, param, created_timestamp)
3575 VALUES(?, ?, ?, ?, \'U=1\', ?)",
3576 (
3577 Chattype::Group,
3578 &chat_name,
3579 normalize_text(&chat_name),
3580 &grpid,
3581 timestamp,
3582 ),
3583 )
3584 .await?;
3585
3586 let chat_id = ChatId::new(u32::try_from(row_id)?);
3587 add_to_chat_contacts_table(context, timestamp, chat_id, &[ContactId::SELF]).await?;
3588
3589 context.emit_msgs_changed_without_ids();
3590 chatlist_events::emit_chatlist_changed(context);
3591 chatlist_events::emit_chatlist_item_changed(context, chat_id);
3592
3593 if !grpid.is_empty() {
3594 // Add "Messages are end-to-end encrypted." message.
3595 chat_id.add_e2ee_notice(context, timestamp).await?;
3596 }
3597
3598 if !context.get_config_bool(Config::Bot).await?
3599 && !context.get_config_bool(Config::SkipStartMessages).await?
3600 {
3601 let text = if !grpid.is_empty() {
3602 // Add "Others will only see this group after you sent a first message." message.
3603 stock_str::new_group_send_first_message(context)
3604 } else {
3605 // Add "Messages in this chat use classic email and are not encrypted." message.
3606 stock_str::chat_unencrypted_explanation(context)
3607 };
3608 chat_id.add_start_info_message(context, &text).await?;
3609 }
3610 if let (true, true) = (sync.into(), !grpid.is_empty()) {
3611 let id = SyncId::Grpid(grpid);
3612 let action = SyncAction::CreateGroupEncrypted(chat_name);

Callers 3

create_groupFunction · 0.85
create_group_unencryptedFunction · 0.85
sync_alter_chatMethod · 0.85

Calls 15

sanitize_single_lineFunction · 0.85
timeFunction · 0.85
normalize_textFunction · 0.85
emit_chatlist_changedFunction · 0.85
insertMethod · 0.80
add_e2ee_noticeMethod · 0.80
get_config_boolMethod · 0.80

Tested by

no test coverage detected