Add creating new group chats
This commit is contained in:
parent
bc50c13803
commit
1e7b685f64
@ -581,6 +581,30 @@ impl Mutation {
|
||||
|
||||
Ok(chat_uuid.to_simple().to_string().into())
|
||||
}
|
||||
|
||||
async fn newGroupChat(context: &Context, user: ID, password_hash: String, title: String, description: Option<String>, with: Vec<ID>) -> FieldResult<ID> {
|
||||
let user = id_to_uuid(&user)?.to_simple();
|
||||
user_authentication(&context.db, &user, &password_hash).await?;
|
||||
let mut chat_partners = BTreeSet::new();
|
||||
for u in with {
|
||||
let u = id_to_uuid(&u)?.to_simple();
|
||||
user_exists(&context.db, &u).await?;
|
||||
chat_partners.insert(u);
|
||||
}
|
||||
chat_partners.insert(user);
|
||||
|
||||
let group_chat_uuid = Uuid::new_v4();
|
||||
sqlx::query(format!(
|
||||
r#"INSERT INTO chat_index VALUES ("{}", 1, "{}", {}, "{}")"#,
|
||||
group_chat_uuid.to_simple(),
|
||||
title,
|
||||
description.map(|d| format!(r#""{}""#, d)).unwrap_or("NULL".to_string()),
|
||||
format_array_for_sql(chat_partners)
|
||||
).as_str()).execute(&context.db).await?;
|
||||
crate::sqlite::create_chat(&context.db, &group_chat_uuid).await?;
|
||||
|
||||
Ok(group_chat_uuid.to_simple().to_string().into())
|
||||
}
|
||||
}
|
||||
|
||||
pub type Schema<'root_node> = RootNode<'root_node, Query, Mutation, EmptySubscription<Context>>;
|
||||
|
Loading…
Reference in New Issue
Block a user