Add listing group chats
This commit is contained in:
parent
9a52c072d3
commit
5cc22bae82
@ -382,6 +382,14 @@ pub struct Chat {
|
||||
users: Vec<ID>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, GraphQLObject, Type)]
|
||||
pub struct GroupChat {
|
||||
id: ID,
|
||||
title: String,
|
||||
description: Option<String>,
|
||||
users: Vec<ID>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Query;
|
||||
|
||||
@ -485,6 +493,26 @@ impl Query {
|
||||
|
||||
Ok(chats)
|
||||
}
|
||||
|
||||
async fn group_chats(context: &Context, user: ID, password_hash: String) -> FieldResult<Vec<GroupChat>> {
|
||||
let user = id_to_uuid(&user)?.to_simple();
|
||||
user_authentication(&context.db, &user, &password_hash).await?;
|
||||
|
||||
let mut chats = Vec::new();
|
||||
for chat in sqlx::query(format!(
|
||||
r#"SELECT id, title, description, users FROM chat_index WHERE is_group_chat = 1 AND users LIKE "%{}%""#,
|
||||
user,
|
||||
).as_str()).fetch_all(&context.db).await? {
|
||||
chats.push(GroupChat {
|
||||
id: ID::from(chat.try_get::<String, _>("id")?),
|
||||
title: chat.try_get("title")?,
|
||||
description: chat.try_get("description")?,
|
||||
users: from_sql_formatted_array(chat.try_get("users")?, "users")?.map(|u: String| u.into()).collect(),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(chats)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user