From d3908d6b36afc982ed7a53ff9fc074c2558503a1 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sun, 22 Jun 2025 08:11:15 -0300 Subject: [PATCH] api: Add chat::create_group_ex(), deprecate create_group_chat() (#6927) `chat::create_group_ex()` gains an `encryption: Option` parameter to support unencrypted chats. --- src/chat.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index ebc7bad5d..2112cc8f7 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3657,15 +3657,31 @@ pub async fn get_past_chat_contacts(context: &Context, chat_id: ChatId) -> Resul } /// Creates a group chat with a given `name`. +/// Deprecated on 2025-06-21, use `create_group_ex()`. pub async fn create_group_chat( context: &Context, protect: ProtectionStatus, - chat_name: &str, + name: &str, ) -> Result { - let chat_name = sanitize_single_line(chat_name); + create_group_ex(context, Some(protect), name).await +} + +/// Creates a group chat. +/// +/// * `encryption` - If `Some`, the chat is encrypted (with key-contacts) and can be protected. +/// * `name` - Chat name. +pub async fn create_group_ex( + context: &Context, + encryption: Option, + name: &str, +) -> Result { + let chat_name = sanitize_single_line(name); ensure!(!chat_name.is_empty(), "Invalid chat name"); - let grpid = create_id(); + let grpid = match encryption { + Some(_) => create_id(), + None => String::new(), + }; let timestamp = create_smeared_timestamp(context); let row_id = context @@ -3685,7 +3701,8 @@ pub async fn create_group_chat( chatlist_events::emit_chatlist_changed(context); chatlist_events::emit_chatlist_item_changed(context, chat_id); - if protect == ProtectionStatus::Protected { + if encryption == Some(ProtectionStatus::Protected) { + let protect = ProtectionStatus::Protected; chat_id .set_protection_for_timestamp_sort(context, protect, timestamp, None) .await?;