Skip to content

Commit d3908d6

Browse files
committed
api: Add chat::create_group_ex(), deprecate create_group_chat() (#6927)
`chat::create_group_ex()` gains an `encryption: Option<ProtectionStatus>` parameter to support unencrypted chats.
1 parent 2cf979d commit d3908d6

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/chat.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,15 +3657,31 @@ pub async fn get_past_chat_contacts(context: &Context, chat_id: ChatId) -> Resul
36573657
}
36583658

36593659
/// Creates a group chat with a given `name`.
3660+
/// Deprecated on 2025-06-21, use `create_group_ex()`.
36603661
pub async fn create_group_chat(
36613662
context: &Context,
36623663
protect: ProtectionStatus,
3663-
chat_name: &str,
3664+
name: &str,
36643665
) -> Result<ChatId> {
3665-
let chat_name = sanitize_single_line(chat_name);
3666+
create_group_ex(context, Some(protect), name).await
3667+
}
3668+
3669+
/// Creates a group chat.
3670+
///
3671+
/// * `encryption` - If `Some`, the chat is encrypted (with key-contacts) and can be protected.
3672+
/// * `name` - Chat name.
3673+
pub async fn create_group_ex(
3674+
context: &Context,
3675+
encryption: Option<ProtectionStatus>,
3676+
name: &str,
3677+
) -> Result<ChatId> {
3678+
let chat_name = sanitize_single_line(name);
36663679
ensure!(!chat_name.is_empty(), "Invalid chat name");
36673680

3668-
let grpid = create_id();
3681+
let grpid = match encryption {
3682+
Some(_) => create_id(),
3683+
None => String::new(),
3684+
};
36693685

36703686
let timestamp = create_smeared_timestamp(context);
36713687
let row_id = context
@@ -3685,7 +3701,8 @@ pub async fn create_group_chat(
36853701
chatlist_events::emit_chatlist_changed(context);
36863702
chatlist_events::emit_chatlist_item_changed(context, chat_id);
36873703

3688-
if protect == ProtectionStatus::Protected {
3704+
if encryption == Some(ProtectionStatus::Protected) {
3705+
let protect = ProtectionStatus::Protected;
36893706
chat_id
36903707
.set_protection_for_timestamp_sort(context, protect, timestamp, None)
36913708
.await?;

0 commit comments

Comments
 (0)