refactor: simplify function signatures and improve code readability
Some checks failed
lint / lint (push) Failing after 9m6s
test / unit (push) Has been cancelled

This commit is contained in:
2026-05-29 03:47:29 +02:00
parent ecb61f9b8f
commit bd370776fe
4 changed files with 59 additions and 67 deletions

View File

@@ -97,9 +97,7 @@ fn build_note_json(
note
}
fn thought_to_ap_visibility(
v: &domain::models::thought::Visibility,
) -> k_ap::ApVisibility {
fn thought_to_ap_visibility(v: &domain::models::thought::Visibility) -> k_ap::ApVisibility {
match v {
domain::models::thought::Visibility::Public => k_ap::ApVisibility::Public,
domain::models::thought::Visibility::Unlisted => k_ap::ApVisibility::Public,

View File

@@ -5,7 +5,7 @@ use sqlx::PgPool;
use k_ap::{
ActivityRepository, ActorRepository, ApActorType, ApUser, ApUserRepository, BlockedDomain,
BlocklistRepository, Follower, FollowerStatus, FollowingStatus, FollowRepository, RemoteActor,
BlocklistRepository, FollowRepository, Follower, FollowerStatus, FollowingStatus, RemoteActor,
};
// ── PostgresFederationRepository ─────────────────────────────────────────────
@@ -518,9 +518,8 @@ impl FollowRepository for PostgresFederationRepository {
}
async fn count_following(&self, local_user_id: uuid::Uuid) -> Result<usize> {
let n: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM federation_following WHERE local_user_id=$1",
)
let n: i64 =
sqlx::query_scalar("SELECT COUNT(*) FROM federation_following WHERE local_user_id=$1")
.bind(local_user_id)
.fetch_one(&self.pool)
.await
@@ -616,9 +615,7 @@ impl ActorRepository for PostgresFederationRepository {
public_key: String,
private_key: String,
) -> Result<()> {
sqlx::query(
"UPDATE users SET public_key=$2, private_key=$3, updated_at=NOW() WHERE id=$1",
)
sqlx::query("UPDATE users SET public_key=$2, private_key=$3, updated_at=NOW() WHERE id=$1")
.bind(user_id)
.bind(&public_key)
.bind(&private_key)
@@ -704,9 +701,7 @@ impl ActorRepository for PostgresFederationRepository {
}
async fn remove_announce(&self, activity_id: &str, actor_url: &str) -> Result<()> {
sqlx::query(
"DELETE FROM federation_announces WHERE activity_id=$1 AND actor_url=$2",
)
sqlx::query("DELETE FROM federation_announces WHERE activity_id=$1 AND actor_url=$2")
.bind(activity_id)
.bind(actor_url)
.execute(&self.pool)
@@ -716,9 +711,8 @@ impl ActorRepository for PostgresFederationRepository {
}
async fn count_announces(&self, object_url: &str) -> Result<usize> {
let n: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM federation_announces WHERE object_url=$1",
)
let n: i64 =
sqlx::query_scalar("SELECT COUNT(*) FROM federation_announces WHERE object_url=$1")
.bind(object_url)
.fetch_one(&self.pool)
.await
@@ -777,9 +771,8 @@ impl BlocklistRepository for PostgresFederationRepository {
}
async fn is_domain_blocked(&self, domain: &str) -> Result<bool> {
let n: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM federation_blocked_domains WHERE domain=$1",
)
let n: i64 =
sqlx::query_scalar("SELECT COUNT(*) FROM federation_blocked_domains WHERE domain=$1")
.bind(domain)
.fetch_one(&self.pool)
.await
@@ -799,14 +792,8 @@ impl BlocklistRepository for PostgresFederationRepository {
.map(|_| ())
}
async fn remove_blocked_actor(
&self,
local_user_id: uuid::Uuid,
actor_url: &str,
) -> Result<()> {
sqlx::query(
"DELETE FROM federation_blocked_actors WHERE local_user_id=$1 AND actor_url=$2",
)
async fn remove_blocked_actor(&self, local_user_id: uuid::Uuid, actor_url: &str) -> Result<()> {
sqlx::query("DELETE FROM federation_blocked_actors WHERE local_user_id=$1 AND actor_url=$2")
.bind(local_user_id)
.bind(actor_url)
.execute(&self.pool)
@@ -860,8 +847,7 @@ impl PostgresApUserRepository {
header_url: Option<String>,
also_known_as: Option<String>,
) -> ApUser {
let profile_url =
url::Url::parse(&format!("{}/users/{}", self.base_url, username)).ok();
let profile_url = url::Url::parse(&format!("{}/users/{}", self.base_url, username)).ok();
let avatar_url = avatar_url.and_then(|u| url::Url::parse(&u).ok());
let banner_url = header_url.and_then(|u| url::Url::parse(&u).ok());
ApUser {

View File

@@ -48,7 +48,11 @@ struct KapPublisher(NatsTransport);
impl k_ap::data::EventPublisher for KapPublisher {
async fn publish(&self, event: FederationEvent) -> anyhow::Result<()> {
let (subject, payload) = match event {
FederationEvent::DeliveryRequested { inbox, activity, signing_actor_id } => (
FederationEvent::DeliveryRequested {
inbox,
activity,
signing_actor_id,
} => (
"federation.delivery.requested",
serde_json::to_vec(&event_payload::EventPayload::FederationDeliveryRequested {
inbox: inbox.to_string(),
@@ -56,7 +60,10 @@ impl k_ap::data::EventPublisher for KapPublisher {
signing_actor_id: signing_actor_id.to_string(),
})?,
),
FederationEvent::BackfillRequested { owner_user_id, follower_inbox_url } => (
FederationEvent::BackfillRequested {
owner_user_id,
follower_inbox_url,
} => (
"federation.backfill.requested",
serde_json::to_vec(&event_payload::EventPayload::FederationBackfillRequested {
owner_user_id: owner_user_id.to_string(),
@@ -107,7 +114,9 @@ pub async fn build(cfg: &Config) -> Infrastructure {
}
};
let event_publisher: Arc<dyn EventPublisher> = match &nats_client {
Some(client) => Arc::new(EventPublisherAdapter::new(NatsTransport::new(client.clone()))),
Some(client) => Arc::new(EventPublisherAdapter::new(NatsTransport::new(
client.clone(),
))),
None => Arc::new(NoOpEventPublisher),
};
let kap_publisher: Option<Arc<dyn k_ap::data::EventPublisher>> = nats_client

View File

@@ -133,9 +133,8 @@ async fn main() {
Err(e) => {
if raw.delivery_count >= CONSUMER_MAX_DELIVER as u64 {
// Rebuild payload from raw bytes for DLQ storage.
let payload_val = serde_json::from_slice::<serde_json::Value>(
&raw.payload,
)
let payload_val =
serde_json::from_slice::<serde_json::Value>(&raw.payload)
.unwrap_or(serde_json::Value::Null);
if let Err(dlq_err) = infra
.dlq_store