diff --git a/src/chat.rs b/src/chat.rs index e25a67363..21b6fd78a 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -201,6 +201,41 @@ impl ChatId { Ok(chat_id) } + /// Create a group or mailinglist raw database record with the given parameters. + /// The function does not add SELF nor checks if the record already exists. + pub(crate) async fn create_multiuser_record( + context: &Context, + chattype: Chattype, + grpid: impl AsRef, + grpname: impl AsRef, + create_blocked: Blocked, + create_protected: ProtectionStatus, + ) -> Result { + let row_id = + context.sql.insert( + "INSERT INTO chats (type, name, grpid, blocked, created_timestamp, protected) VALUES(?, ?, ?, ?, ?, ?);", + paramsv![ + chattype, + grpname.as_ref(), + grpid.as_ref(), + create_blocked, + dc_create_smeared_timestamp(context).await, + create_protected, + ], + ).await?; + + let chat_id = ChatId::new(u32::try_from(row_id)?); + info!( + context, + "Created group/mailinglist '{}' grpid={} as {}", + grpname.as_ref(), + grpid.as_ref(), + chat_id + ); + + Ok(chat_id) + } + pub async fn set_selfavatar_timestamp(self, context: &Context, timestamp: i64) -> Result<()> { context .sql diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index e2d122df6..b437da552 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1567,7 +1567,7 @@ async fn create_or_lookup_group( return Ok(None); } - chat_id = create_multiuser_record( + chat_id = ChatId::create_multiuser_record( context, Chattype::Group, &grpid, @@ -1818,7 +1818,7 @@ async fn create_or_lookup_mailinglist( if allow_creation { // list does not exist but should be created - let chat_id = create_multiuser_record( + let chat_id = ChatId::create_multiuser_record( context, Chattype::Mailinglist, &listid, @@ -1918,7 +1918,7 @@ async fn create_adhoc_group( .get_subject() .unwrap_or_else(|| "Unnamed group".to_string()); - let new_chat_id: ChatId = create_multiuser_record( + let new_chat_id: ChatId = ChatId::create_multiuser_record( context, Chattype::Group, &grpid, @@ -1936,39 +1936,6 @@ async fn create_adhoc_group( Ok(Some(new_chat_id)) } -async fn create_multiuser_record( - context: &Context, - chattype: Chattype, - grpid: impl AsRef, - grpname: impl AsRef, - create_blocked: Blocked, - create_protected: ProtectionStatus, -) -> Result { - let row_id = - context.sql.insert( - "INSERT INTO chats (type, name, grpid, blocked, created_timestamp, protected) VALUES(?, ?, ?, ?, ?, ?);", - paramsv![ - chattype, - grpname.as_ref(), - grpid.as_ref(), - create_blocked, - dc_create_smeared_timestamp(context).await, - create_protected, - ], - ).await?; - - let chat_id = ChatId::new(u32::try_from(row_id)?); - info!( - context, - "Created group/mailinglist '{}' grpid={} as {}", - grpname.as_ref(), - grpid.as_ref(), - chat_id - ); - - Ok(chat_id) -} - /// Creates ad-hoc group ID. /// /// Algorithm: