From 2bbe23cd89ead5ab03148b84d7e7fd0a8f68b1a1 Mon Sep 17 00:00:00 2001 From: silverpill Date: Tue, 12 Jul 2022 19:42:30 +0000 Subject: [PATCH] Refactor "refetch-actor" command --- src/bin/mitractl.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/bin/mitractl.rs b/src/bin/mitractl.rs index 28cdc03..986a278 100644 --- a/src/bin/mitractl.rs +++ b/src/bin/mitractl.rs @@ -1,6 +1,7 @@ use anyhow::Error; use chrono::{Duration, Utc}; use clap::Parser; +use tokio_postgres::GenericClient; use uuid::Uuid; use mitra::activitypub::builders::delete_note::prepare_delete_note; @@ -81,6 +82,20 @@ struct RefetchActor { id: String, } +impl RefetchActor { + async fn execute( + &self, + config: &Config, + db_client: &impl GenericClient, + ) -> Result<(), Error> { + let profile = get_profile_by_actor_id(db_client, &self.id).await?; + let actor = fetch_actor(&config.instance(), &self.id).await?; + update_remote_profile(db_client, &config.media_dir(), profile, actor).await?; + println!("profile updated"); + Ok(()) + } +} + /// Delete profile #[derive(Parser)] struct DeleteProfile { @@ -165,13 +180,7 @@ async fn main() { println!("{}", code); }; }, - SubCommand::RefetchActor(subopts) => { - let actor_id = subopts.id; - let profile = get_profile_by_actor_id(db_client, &actor_id).await.unwrap(); - let actor = fetch_actor(&config.instance(), &actor_id).await.unwrap(); - update_remote_profile(db_client, &config.media_dir(), profile, actor).await.unwrap(); - println!("profile updated"); - }, + SubCommand::RefetchActor(cmd) => cmd.execute(&config, db_client).await.unwrap(), SubCommand::DeleteProfile(subopts) => { let profile = get_profile_by_id(db_client, &subopts.id).await.unwrap(); let mut maybe_delete_person = None;