@@ -3657,30 +3657,45 @@ pub async fn get_past_chat_contacts(context: &Context, chat_id: ChatId) -> Resul
3657
3657
}
3658
3658
3659
3659
/// Creates a group chat with a given `name`.
3660
- /// Deprecated on 2025-06-21, use `create_group_ex ()`.
3660
+ /// Deprecated on 2025-06-21, use `create_group ()`.
3661
3661
pub async fn create_group_chat (
3662
3662
context : & Context ,
3663
3663
protect : ProtectionStatus ,
3664
3664
name : & str ,
3665
3665
) -> Result < ChatId > {
3666
- create_group_ex ( context, Some ( protect) , name) . await
3666
+ create_group ( context, Some ( protect) , name) . await
3667
3667
}
3668
3668
3669
3669
/// Creates a group chat.
3670
3670
///
3671
3671
/// * `encryption` - If `Some`, the chat is encrypted (with key-contacts) and can be protected.
3672
3672
/// * `name` - Chat name.
3673
- pub async fn create_group_ex (
3673
+ pub async fn create_group (
3674
3674
context : & Context ,
3675
3675
encryption : Option < ProtectionStatus > ,
3676
3676
name : & str ,
3677
+ ) -> Result < ChatId > {
3678
+ create_group_ex ( context, Sync , encryption. map ( |p| ( create_id ( ) , p) ) , name) . await
3679
+ }
3680
+
3681
+ /// Creates a group chat.
3682
+ ///
3683
+ /// * `sync` - Whether a multi-device synchronization message should be sent. Ignored for
3684
+ /// unencrypted chats currently.
3685
+ ///
3686
+ /// See [`create_group`] for other parameters.
3687
+ pub ( crate ) async fn create_group_ex (
3688
+ context : & Context ,
3689
+ sync : sync:: Sync ,
3690
+ encryption : Option < ( String /* grpid */ , ProtectionStatus ) > ,
3691
+ name : & str ,
3677
3692
) -> Result < ChatId > {
3678
3693
let chat_name = sanitize_single_line ( name) ;
3679
3694
ensure ! ( !chat_name. is_empty( ) , "Invalid chat name" ) ;
3680
3695
3681
- let grpid = match encryption {
3682
- Some ( _ ) => create_id ( ) ,
3683
- None => String :: new ( ) ,
3696
+ let ( grpid, protection ) = match encryption {
3697
+ Some ( ( grpid , protection ) ) => ( grpid , Some ( protection ) ) ,
3698
+ None => ( String :: new ( ) , None ) ,
3684
3699
} ;
3685
3700
3686
3701
let timestamp = create_smeared_timestamp ( context) ;
@@ -3690,7 +3705,7 @@ pub async fn create_group_ex(
3690
3705
"INSERT INTO chats
3691
3706
(type, name, grpid, param, created_timestamp)
3692
3707
VALUES(?, ?, ?, \' U=1\' , ?);" ,
3693
- ( Chattype :: Group , chat_name, grpid, timestamp) ,
3708
+ ( Chattype :: Group , & chat_name, & grpid, timestamp) ,
3694
3709
)
3695
3710
. await ?;
3696
3711
@@ -3701,7 +3716,7 @@ pub async fn create_group_ex(
3701
3716
chatlist_events:: emit_chatlist_changed ( context) ;
3702
3717
chatlist_events:: emit_chatlist_item_changed ( context, chat_id) ;
3703
3718
3704
- if encryption == Some ( ProtectionStatus :: Protected ) {
3719
+ if protection == Some ( ProtectionStatus :: Protected ) {
3705
3720
let protect = ProtectionStatus :: Protected ;
3706
3721
chat_id
3707
3722
. set_protection_for_timestamp_sort ( context, protect, timestamp, None )
@@ -3714,7 +3729,11 @@ pub async fn create_group_ex(
3714
3729
let text = stock_str:: new_group_send_first_message ( context) . await ;
3715
3730
add_info_msg ( context, chat_id, & text, create_smeared_timestamp ( context) ) . await ?;
3716
3731
}
3717
-
3732
+ if let ( true , Some ( protection) ) = ( sync. into ( ) , protection) {
3733
+ let id = SyncId :: Grpid ( grpid) ;
3734
+ let action = SyncAction :: CreateGroupEncrypted ( protection, chat_name) ;
3735
+ self :: sync ( context, id, action) . await . log_err ( context) . ok ( ) ;
3736
+ }
3718
3737
Ok ( chat_id)
3719
3738
}
3720
3739
@@ -4985,7 +5004,7 @@ pub(crate) enum SyncId {
4985
5004
/// "Message-ID"-s, from oldest to latest. Used for ad-hoc groups.
4986
5005
Msgids ( Vec < String > ) ,
4987
5006
4988
- // Special id for device chat.
5007
+ /// Special id for device chat.
4989
5008
Device ,
4990
5009
}
4991
5010
@@ -4999,6 +5018,8 @@ pub(crate) enum SyncAction {
4999
5018
SetMuted ( MuteDuration ) ,
5000
5019
/// Create broadcast channel with the given name.
5001
5020
CreateBroadcast ( String ) ,
5021
+ /// Create encrypted group chat with the given name.
5022
+ CreateGroupEncrypted ( ProtectionStatus , String ) ,
5002
5023
Rename ( String ) ,
5003
5024
/// Set chat contacts by their addresses.
5004
5025
SetContacts ( Vec < String > ) ,
@@ -5064,6 +5085,9 @@ impl Context {
5064
5085
if let SyncAction :: CreateBroadcast ( name) = action {
5065
5086
create_broadcast_ex ( self , Nosync , grpid. clone ( ) , name. clone ( ) ) . await ?;
5066
5087
return Ok ( ( ) ) ;
5088
+ } else if let SyncAction :: CreateGroupEncrypted ( protection, name) = action {
5089
+ create_group_ex ( self , Nosync , Some ( ( grpid. clone ( ) , * protection) ) , name) . await ?;
5090
+ return Ok ( ( ) ) ;
5067
5091
}
5068
5092
get_chat_id_by_grpid ( self , grpid)
5069
5093
. await ?
@@ -5085,7 +5109,7 @@ impl Context {
5085
5109
SyncAction :: Accept => chat_id. accept_ex ( self , Nosync ) . await ,
5086
5110
SyncAction :: SetVisibility ( v) => chat_id. set_visibility_ex ( self , Nosync , * v) . await ,
5087
5111
SyncAction :: SetMuted ( duration) => set_muted_ex ( self , Nosync , chat_id, * duration) . await ,
5088
- SyncAction :: CreateBroadcast ( _) => {
5112
+ SyncAction :: CreateBroadcast ( _) | SyncAction :: CreateGroupEncrypted ( .. ) => {
5089
5113
Err ( anyhow ! ( "sync_alter_chat({id:?}, {action:?}): Bad request." ) )
5090
5114
}
5091
5115
SyncAction :: Rename ( to) => rename_ex ( self , Nosync , chat_id, to) . await ,
0 commit comments