From a44630773c1f45e69e1bba0ebf0b1d79174a1ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 29 Nov 2026 07:57:13 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20community::gro?= =?UTF-8?q?ups=20reuses=20the=20raw=20row=20mapper=20and=20its=20Raw=20?= =?UTF-8?q?=E2=86=92=20Community=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/server/src/db/community.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/server/src/db/community.rs b/crates/server/src/db/community.rs index 1fceac3..849eb97 100644 --- a/crates/server/src/db/community.rs +++ b/crates/server/src/db/community.rs @@ -39,7 +39,10 @@ fn raw(r: &mut Reader) -> Result { } pub async fn read(id: Id, viewer: Id, db: &Connection) -> Result { - let raw = one(db, READ, (id, viewer), raw).await?; + community(one(db, READ, (id, viewer), raw).await?, db).await +} + +async fn community(raw: Raw, db: &Connection) -> Result { let kind = match raw.kind { Kind::Group => CommunityKind::Group, Kind::Direct => CommunityKind::Direct { @@ -85,21 +88,20 @@ pub async fn communities_of(user_id: Id, db: &Connection) -> Result Result, ServerError> { - all( + let raws = all( db, - "SELECT id, name, (SELECT avatar.id FROM avatar WHERE avatar.community_id = community.id), voice_enabled FROM community WHERE kind = ?1 ORDER BY name", + "SELECT id, name, kind, (SELECT avatar.id FROM avatar WHERE avatar.community_id = community.id), voice_enabled, NULL FROM community WHERE kind = ?1 ORDER BY name", (Kind::Group.as_str(),), - |r| { - Ok(Community { - id: r.get()?, - name: r.get()?, - kind: CommunityKind::Group, - avatar_id: r.get()?, - voice_enabled: r.get()?, - }) - }, + raw, ) - .await + .await?; + + let mut groups = Vec::new(); + for raw in raws { + groups.push(community(raw, db).await?); + } + + Ok(groups) } pub async fn update(