@@ -3699,30 +3699,45 @@ pub async fn get_past_chat_contacts(context: &Context, chat_id: ChatId) -> Resul
3699
3699
}
3700
3700
3701
3701
/// Creates a group chat with a given `name`.
3702
- /// Deprecated on 2025-06-21, use `create_group_ex ()`.
3702
+ /// Deprecated on 2025-06-21, use `create_group ()`.
3703
3703
pub async fn create_group_chat (
3704
3704
context : & Context ,
3705
3705
protect : ProtectionStatus ,
3706
3706
name : & str ,
3707
3707
) -> Result < ChatId > {
3708
- create_group_ex ( context, Some ( protect) , name) . await
3708
+ create_group ( context, Some ( protect) , name) . await
3709
3709
}
3710
3710
3711
3711
/// Creates a group chat.
3712
3712
///
3713
3713
/// * `encryption` - If `Some`, the chat is encrypted (with key-contacts) and can be protected.
3714
3714
/// * `name` - Chat name.
3715
- pub async fn create_group_ex (
3715
+ pub async fn create_group (
3716
3716
context : & Context ,
3717
3717
encryption : Option < ProtectionStatus > ,
3718
3718
name : & str ,
3719
+ ) -> Result < ChatId > {
3720
+ create_group_ex ( context, Sync , encryption. map ( |p| ( create_id ( ) , p) ) , name) . await
3721
+ }
3722
+
3723
+ /// Creates a group chat.
3724
+ ///
3725
+ /// * `sync` - Whether a multi-device synchronization message should be sent. Ignored for
3726
+ /// unencrypted chats currently.
3727
+ ///
3728
+ /// See [`create_group`] for other parameters.
3729
+ pub ( crate ) async fn create_group_ex (
3730
+ context : & Context ,
3731
+ sync : sync:: Sync ,
3732
+ encryption : Option < ( String /* grpid */ , ProtectionStatus ) > ,
3733
+ name : & str ,
3719
3734
) -> Result < ChatId > {
3720
3735
let chat_name = sanitize_single_line ( name) ;
3721
3736
ensure ! ( !chat_name. is_empty( ) , "Invalid chat name" ) ;
3722
3737
3723
- let grpid = match encryption {
3724
- Some ( _ ) => create_id ( ) ,
3725
- None => String :: new ( ) ,
3738
+ let ( grpid, protection ) = match encryption {
3739
+ Some ( ( grpid , protection ) ) => ( grpid , Some ( protection ) ) ,
3740
+ None => ( String :: new ( ) , None ) ,
3726
3741
} ;
3727
3742
3728
3743
let timestamp = create_smeared_timestamp ( context) ;
@@ -3732,7 +3747,7 @@ pub async fn create_group_ex(
3732
3747
"INSERT INTO chats
3733
3748
(type, name, grpid, param, created_timestamp)
3734
3749
VALUES(?, ?, ?, \' U=1\' , ?);" ,
3735
- ( Chattype :: Group , chat_name, grpid, timestamp) ,
3750
+ ( Chattype :: Group , & chat_name, & grpid, timestamp) ,
3736
3751
)
3737
3752
. await ?;
3738
3753
@@ -3743,7 +3758,7 @@ pub async fn create_group_ex(
3743
3758
chatlist_events:: emit_chatlist_changed ( context) ;
3744
3759
chatlist_events:: emit_chatlist_item_changed ( context, chat_id) ;
3745
3760
3746
- if encryption == Some ( ProtectionStatus :: Protected ) {
3761
+ if protection == Some ( ProtectionStatus :: Protected ) {
3747
3762
let protect = ProtectionStatus :: Protected ;
3748
3763
chat_id
3749
3764
. set_protection_for_timestamp_sort ( context, protect, timestamp, None )
@@ -3756,7 +3771,11 @@ pub async fn create_group_ex(
3756
3771
let text = stock_str:: new_group_send_first_message ( context) . await ;
3757
3772
add_info_msg ( context, chat_id, & text, create_smeared_timestamp ( context) ) . await ?;
3758
3773
}
3759
-
3774
+ if let ( true , Some ( protection) ) = ( sync. into ( ) , protection) {
3775
+ let id = SyncId :: Grpid ( grpid) ;
3776
+ let action = SyncAction :: CreateGroupEncrypted ( protection, chat_name) ;
3777
+ self :: sync ( context, id, action) . await . log_err ( context) . ok ( ) ;
3778
+ }
3760
3779
Ok ( chat_id)
3761
3780
}
3762
3781
@@ -5027,7 +5046,7 @@ pub(crate) enum SyncId {
5027
5046
/// "Message-ID"-s, from oldest to latest. Used for ad-hoc groups.
5028
5047
Msgids ( Vec < String > ) ,
5029
5048
5030
- // Special id for device chat.
5049
+ /// Special id for device chat.
5031
5050
Device ,
5032
5051
}
5033
5052
@@ -5041,6 +5060,8 @@ pub(crate) enum SyncAction {
5041
5060
SetMuted ( MuteDuration ) ,
5042
5061
/// Create broadcast channel with the given name.
5043
5062
CreateBroadcast ( String ) ,
5063
+ /// Create encrypted group chat with the given name.
5064
+ CreateGroupEncrypted ( ProtectionStatus , String ) ,
5044
5065
Rename ( String ) ,
5045
5066
/// Set chat contacts by their addresses.
5046
5067
SetContacts ( Vec < String > ) ,
@@ -5106,6 +5127,9 @@ impl Context {
5106
5127
if let SyncAction :: CreateBroadcast ( name) = action {
5107
5128
create_broadcast_ex ( self , Nosync , grpid. clone ( ) , name. clone ( ) ) . await ?;
5108
5129
return Ok ( ( ) ) ;
5130
+ } else if let SyncAction :: CreateGroupEncrypted ( protection, name) = action {
5131
+ create_group_ex ( self , Nosync , Some ( ( grpid. clone ( ) , * protection) ) , name) . await ?;
5132
+ return Ok ( ( ) ) ;
5109
5133
}
5110
5134
get_chat_id_by_grpid ( self , grpid)
5111
5135
. await ?
@@ -5127,7 +5151,7 @@ impl Context {
5127
5151
SyncAction :: Accept => chat_id. accept_ex ( self , Nosync ) . await ,
5128
5152
SyncAction :: SetVisibility ( v) => chat_id. set_visibility_ex ( self , Nosync , * v) . await ,
5129
5153
SyncAction :: SetMuted ( duration) => set_muted_ex ( self , Nosync , chat_id, * duration) . await ,
5130
- SyncAction :: CreateBroadcast ( _) => {
5154
+ SyncAction :: CreateBroadcast ( _) | SyncAction :: CreateGroupEncrypted ( .. ) => {
5131
5155
Err ( anyhow ! ( "sync_alter_chat({id:?}, {action:?}): Bad request." ) )
5132
5156
}
5133
5157
SyncAction :: Rename ( to) => rename_ex ( self , Nosync , chat_id, to) . await ,
0 commit comments