Don't add inbox as connection

This commit is contained in:
asonix 2021-02-10 00:44:48 -06:00
parent a4d70d7e3a
commit b2904bb1ba
6 changed files with 13 additions and 22 deletions

View file

@ -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(

View file

@ -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

View file

@ -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,

View file

@ -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)?;

View file

@ -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);

View file

@ -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(())
}