move create_multiuser_record() to ChatId (#2706)

this is needed for targeting "non-blocking group QR joins"
as create_multiuser_record() would also be needed from other places.

this will make rebasing/rewriting and finally reviewing #2508 easier.
This commit is contained in:
bjoern
2021-09-27 20:24:25 +02:00
committed by GitHub
parent 95bce993ad
commit 941b8caa8b
2 changed files with 38 additions and 36 deletions

View File

@@ -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<str>,
grpname: impl AsRef<str>,
create_blocked: Blocked,
create_protected: ProtectionStatus,
) -> Result<Self> {
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