From b2904bb1bacff80a82ced138e710719f555c9377 Mon Sep 17 00:00:00 2001 From: asonix Date: Wed, 10 Feb 2021 00:44:48 -0600 Subject: [PATCH] Don't add inbox as connection --- src/data/actor.rs | 8 ++++---- src/db.rs | 4 ++-- src/jobs/apub/follow.rs | 14 +++----------- src/jobs/apub/reject.rs | 2 +- src/jobs/apub/undo.rs | 2 +- src/routes/inbox.rs | 5 ++--- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/data/actor.rs b/src/data/actor.rs index 54c24b8..31cb927 100644 --- a/src/data/actor.rs +++ b/src/data/actor.rs @@ -56,13 +56,13 @@ impl ActorCache { .map(MaybeCached::Fetched) } - pub(crate) async fn follower(&self, actor: Actor) -> Result<(), MyError> { - self.db.add_listener(actor.id.clone()).await?; + pub(crate) async fn add_connection(&self, actor: Actor) -> Result<(), MyError> { + self.db.add_connection(actor.id.clone()).await?; self.db.save_actor(actor).await } - pub(crate) async fn unfollower(&self, actor: &Actor) -> Result<(), MyError> { - self.db.remove_listener(actor.id.clone()).await + pub(crate) async fn remove_connection(&self, actor: &Actor) -> Result<(), MyError> { + self.db.remove_connection(actor.id.clone()).await } pub(crate) async fn get_no_cache( diff --git a/src/db.rs b/src/db.rs index 2b94976..8955405 100644 --- a/src/db.rs +++ b/src/db.rs @@ -474,7 +474,7 @@ impl Db { .await } - pub(crate) async fn remove_listener(&self, actor_id: Url) -> Result<(), MyError> { + pub(crate) async fn remove_connection(&self, actor_id: Url) -> Result<(), MyError> { self.unblock(move |inner| { inner .connected_actor_ids @@ -485,7 +485,7 @@ impl Db { .await } - pub(crate) async fn add_listener(&self, actor_id: Url) -> Result<(), MyError> { + pub(crate) async fn add_connection(&self, actor_id: Url) -> Result<(), MyError> { self.unblock(move |inner| { inner .connected_actor_ids diff --git a/src/jobs/apub/follow.rs b/src/jobs/apub/follow.rs index 8c31e47..a691a50 100644 --- a/src/jobs/apub/follow.rs +++ b/src/jobs/apub/follow.rs @@ -15,24 +15,16 @@ use std::{future::Future, pin::Pin}; #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] pub(crate) struct Follow { - is_listener: bool, input: AcceptedActivities, actor: Actor, } impl Follow { - pub fn new(is_listener: bool, input: AcceptedActivities, actor: Actor) -> Self { - Follow { - is_listener, - input, - actor, - } + pub fn new(input: AcceptedActivities, actor: Actor) -> Self { + Follow { input, actor } } async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { - if !self.is_listener { - state.db.add_listener(self.actor.inbox.clone()).await?; - } let my_id = state.config.generate_url(UrlKind::Actor); // if following relay directly, not just following 'public', followback @@ -45,7 +37,7 @@ impl Follow { .queue(Deliver::new(self.actor.inbox.clone(), follow)?)?; } - state.actors.follower(self.actor.clone()).await?; + state.actors.add_connection(self.actor.clone()).await?; let accept = generate_accept_follow( &state.config, diff --git a/src/jobs/apub/reject.rs b/src/jobs/apub/reject.rs index 3e9e1fa..070ce11 100644 --- a/src/jobs/apub/reject.rs +++ b/src/jobs/apub/reject.rs @@ -11,7 +11,7 @@ pub(crate) struct Reject(pub(crate) Actor); impl Reject { async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { - state.actors.unfollower(&self.0).await?; + state.actors.remove_connection(&self.0).await?; let my_id = state.config.generate_url(UrlKind::Actor); let undo = generate_undo_follow(&state.config, &self.0.id, &my_id)?; diff --git a/src/jobs/apub/undo.rs b/src/jobs/apub/undo.rs index cd62f61..c965837 100644 --- a/src/jobs/apub/undo.rs +++ b/src/jobs/apub/undo.rs @@ -21,7 +21,7 @@ impl Undo { async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { let was_following = state.state.db.is_connected(self.actor.id.clone()).await?; - state.actors.unfollower(&self.actor).await?; + state.actors.remove_connection(&self.actor).await?; if was_following { let my_id = state.config.generate_url(UrlKind::Actor); diff --git a/src/routes/inbox.rs b/src/routes/inbox.rs index 87a3b5c..9082008 100644 --- a/src/routes/inbox.rs +++ b/src/routes/inbox.rs @@ -66,7 +66,7 @@ pub(crate) async fn route( ValidTypes::Announce | ValidTypes::Create => { handle_announce(&state, &jobs, input, actor).await? } - ValidTypes::Follow => handle_follow(&config, &jobs, input, actor, is_connected).await?, + ValidTypes::Follow => handle_follow(&config, &jobs, input, actor).await?, ValidTypes::Delete | ValidTypes::Update => handle_forward(&jobs, input, actor).await?, ValidTypes::Undo => handle_undo(&config, &jobs, input, actor, is_connected).await?, }; @@ -207,7 +207,6 @@ async fn handle_follow( jobs: &JobServer, input: AcceptedActivities, actor: Actor, - is_listener: bool, ) -> Result<(), MyError> { let my_id: Url = config.generate_url(UrlKind::Actor); @@ -217,7 +216,7 @@ async fn handle_follow( )?)); } - jobs.queue(Follow::new(is_listener, input, actor))?; + jobs.queue(Follow::new(input, actor))?; Ok(()) }