bro we are sledding
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
config::{Config, UrlKind},
|
||||
data::Actor,
|
||||
db::Actor,
|
||||
error::MyError,
|
||||
jobs::{
|
||||
apub::{get_inboxes, prepare_activity},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
apub::AcceptedActivities,
|
||||
config::{Config, UrlKind},
|
||||
data::Actor,
|
||||
db::Actor,
|
||||
error::MyError,
|
||||
jobs::{apub::prepare_activity, Deliver, JobState},
|
||||
};
|
||||
@@ -36,14 +36,16 @@ impl Follow {
|
||||
let my_id = state.config.generate_url(UrlKind::Actor);
|
||||
|
||||
// if following relay directly, not just following 'public', followback
|
||||
if self.input.object_is(&my_id) && !state.actors.is_following(&self.actor.id).await {
|
||||
if self.input.object_is(&my_id)
|
||||
&& !state.state.db.is_connected(self.actor.id.clone()).await?
|
||||
{
|
||||
let follow = generate_follow(&state.config, &self.actor.id, &my_id)?;
|
||||
state
|
||||
.job_server
|
||||
.queue(Deliver::new(self.actor.inbox.clone(), follow)?)?;
|
||||
}
|
||||
|
||||
state.actors.follower(&self.actor).await?;
|
||||
state.actors.follower(self.actor.clone()).await?;
|
||||
|
||||
let accept = generate_accept_follow(
|
||||
&state.config,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
apub::AcceptedActivities,
|
||||
data::Actor,
|
||||
db::Actor,
|
||||
error::MyError,
|
||||
jobs::{apub::get_inboxes, DeliverMany, JobState},
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
config::{Config, UrlKind},
|
||||
data::{Actor, State},
|
||||
data::State,
|
||||
db::Actor,
|
||||
error::MyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
@@ -23,7 +24,7 @@ pub use self::{announce::Announce, follow::Follow, forward::Forward, reject::Rej
|
||||
async fn get_inboxes(state: &State, actor: &Actor, object_id: &Url) -> Result<Vec<Url>, MyError> {
|
||||
let domain = object_id.host().ok_or(MyError::Domain)?.to_string();
|
||||
|
||||
Ok(state.listeners_without(&actor.inbox, &domain).await)
|
||||
state.inboxes_without(&actor.inbox, &domain).await
|
||||
}
|
||||
|
||||
fn prepare_activity<T, U, V, Kind>(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
config::UrlKind,
|
||||
data::Actor,
|
||||
db::Actor,
|
||||
jobs::{apub::generate_undo_follow, Deliver, JobState},
|
||||
};
|
||||
use background_jobs::ActixJob;
|
||||
@@ -11,9 +11,7 @@ pub struct Reject(pub Actor);
|
||||
|
||||
impl Reject {
|
||||
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
|
||||
if state.actors.unfollower(&self.0).await?.is_some() {
|
||||
state.db.remove_listener(self.0.inbox.clone()).await?;
|
||||
}
|
||||
state.actors.unfollower(&self.0).await?;
|
||||
|
||||
let my_id = state.config.generate_url(UrlKind::Actor);
|
||||
let undo = generate_undo_follow(&state.config, &self.0.id, &my_id)?;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
apub::AcceptedActivities,
|
||||
config::UrlKind,
|
||||
data::Actor,
|
||||
db::Actor,
|
||||
jobs::{apub::generate_undo_follow, Deliver, JobState},
|
||||
};
|
||||
use background_jobs::ActixJob;
|
||||
@@ -19,11 +19,9 @@ impl Undo {
|
||||
}
|
||||
|
||||
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
|
||||
let was_following = state.actors.is_following(&self.actor.id).await;
|
||||
let was_following = state.state.db.is_connected(self.actor.id.clone()).await?;
|
||||
|
||||
if state.actors.unfollower(&self.actor).await?.is_some() {
|
||||
state.db.remove_listener(self.actor.inbox.clone()).await?;
|
||||
}
|
||||
state.actors.unfollower(&self.actor).await?;
|
||||
|
||||
if was_following {
|
||||
let my_id = state.config.generate_url(UrlKind::Actor);
|
||||
|
||||
@@ -15,7 +15,7 @@ impl CacheMedia {
|
||||
}
|
||||
|
||||
async fn perform(self, state: JobState) -> Result<(), Error> {
|
||||
if state.media.get_bytes(self.uuid).await.is_some() {
|
||||
if !state.media.is_outdated(self.uuid).await? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ impl CacheMedia {
|
||||
state
|
||||
.media
|
||||
.store_bytes(self.uuid, content_type, bytes)
|
||||
.await;
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
+17
-14
@@ -5,32 +5,35 @@ use crate::{
|
||||
use activitystreams::url::Url;
|
||||
use anyhow::Error;
|
||||
use background_jobs::ActixJob;
|
||||
use futures::join;
|
||||
use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct QueryInstance {
|
||||
listener: Url,
|
||||
actor_id: Url,
|
||||
}
|
||||
|
||||
impl QueryInstance {
|
||||
pub fn new(listener: Url) -> Self {
|
||||
pub fn new(actor_id: Url) -> Self {
|
||||
QueryInstance {
|
||||
listener: listener.into(),
|
||||
actor_id: actor_id.into(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn perform(self, state: JobState) -> Result<(), Error> {
|
||||
let (o1, o2) = join!(
|
||||
state.node_cache.is_contact_outdated(&self.listener),
|
||||
state.node_cache.is_instance_outdated(&self.listener),
|
||||
);
|
||||
let contact_outdated = state
|
||||
.node_cache
|
||||
.is_contact_outdated(self.actor_id.clone())
|
||||
.await;
|
||||
let instance_outdated = state
|
||||
.node_cache
|
||||
.is_instance_outdated(self.actor_id.clone())
|
||||
.await;
|
||||
|
||||
if !(o1 || o2) {
|
||||
if !(contact_outdated || instance_outdated) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut instance_uri = self.listener.clone();
|
||||
let mut instance_uri = self.actor_id.clone();
|
||||
instance_uri.set_fragment(None);
|
||||
instance_uri.set_query(None);
|
||||
instance_uri.set_path("api/v1/instance");
|
||||
@@ -47,11 +50,11 @@ impl QueryInstance {
|
||||
};
|
||||
|
||||
if let Some(mut contact) = instance.contact {
|
||||
let uuid = if let Some(uuid) = state.media.get_uuid(&contact.avatar).await? {
|
||||
let uuid = if let Some(uuid) = state.media.get_uuid(contact.avatar.clone()).await? {
|
||||
contact.avatar = state.config.generate_url(UrlKind::Media(uuid)).into();
|
||||
uuid
|
||||
} else {
|
||||
let uuid = state.media.store_url(&contact.avatar).await?;
|
||||
let uuid = state.media.store_url(contact.avatar.clone()).await?;
|
||||
contact.avatar = state.config.generate_url(UrlKind::Media(uuid)).into();
|
||||
uuid
|
||||
};
|
||||
@@ -61,7 +64,7 @@ impl QueryInstance {
|
||||
state
|
||||
.node_cache
|
||||
.set_contact(
|
||||
&self.listener,
|
||||
self.actor_id.clone(),
|
||||
contact.username,
|
||||
contact.display_name,
|
||||
contact.url,
|
||||
@@ -75,7 +78,7 @@ impl QueryInstance {
|
||||
state
|
||||
.node_cache
|
||||
.set_instance(
|
||||
&self.listener,
|
||||
self.actor_id.clone(),
|
||||
instance.title,
|
||||
description,
|
||||
instance.version,
|
||||
|
||||
+4
-4
@@ -13,7 +13,7 @@ pub use self::{
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
data::{ActorCache, Media, NodeCache, State},
|
||||
data::{ActorCache, MediaCache, NodeCache, State},
|
||||
db::Db,
|
||||
error::MyError,
|
||||
jobs::process_listeners::Listeners,
|
||||
@@ -35,7 +35,7 @@ pub fn create_workers(
|
||||
state: State,
|
||||
actors: ActorCache,
|
||||
job_server: JobServer,
|
||||
media: Media,
|
||||
media: MediaCache,
|
||||
config: Config,
|
||||
) {
|
||||
let remote_handle = job_server.remote.clone();
|
||||
@@ -72,7 +72,7 @@ pub struct JobState {
|
||||
state: State,
|
||||
actors: ActorCache,
|
||||
config: Config,
|
||||
media: Media,
|
||||
media: MediaCache,
|
||||
node_cache: NodeCache,
|
||||
job_server: JobServer,
|
||||
}
|
||||
@@ -88,7 +88,7 @@ impl JobState {
|
||||
state: State,
|
||||
actors: ActorCache,
|
||||
job_server: JobServer,
|
||||
media: Media,
|
||||
media: MediaCache,
|
||||
config: Config,
|
||||
) -> Self {
|
||||
JobState {
|
||||
|
||||
+10
-6
@@ -6,20 +6,24 @@ use std::{future::Future, pin::Pin};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct QueryNodeinfo {
|
||||
listener: Url,
|
||||
actor_id: Url,
|
||||
}
|
||||
|
||||
impl QueryNodeinfo {
|
||||
pub fn new(listener: Url) -> Self {
|
||||
QueryNodeinfo { listener }
|
||||
pub fn new(actor_id: Url) -> Self {
|
||||
QueryNodeinfo { actor_id }
|
||||
}
|
||||
|
||||
async fn perform(self, state: JobState) -> Result<(), Error> {
|
||||
if !state.node_cache.is_nodeinfo_outdated(&self.listener).await {
|
||||
if !state
|
||||
.node_cache
|
||||
.is_nodeinfo_outdated(self.actor_id.clone())
|
||||
.await
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut well_known_uri = self.listener.clone();
|
||||
let mut well_known_uri = self.actor_id.clone();
|
||||
well_known_uri.set_fragment(None);
|
||||
well_known_uri.set_query(None);
|
||||
well_known_uri.set_path(".well-known/nodeinfo");
|
||||
@@ -40,7 +44,7 @@ impl QueryNodeinfo {
|
||||
state
|
||||
.node_cache
|
||||
.set_info(
|
||||
&self.listener,
|
||||
self.actor_id.clone(),
|
||||
nodeinfo.software.name,
|
||||
nodeinfo.software.version,
|
||||
nodeinfo.open_registrations,
|
||||
|
||||
@@ -8,11 +8,11 @@ pub struct Listeners;
|
||||
|
||||
impl Listeners {
|
||||
async fn perform(self, state: JobState) -> Result<(), Error> {
|
||||
for listener in state.state.listeners().await {
|
||||
for actor_id in state.state.db.connected_ids().await? {
|
||||
state
|
||||
.job_server
|
||||
.queue(QueryInstance::new(listener.clone()))?;
|
||||
state.job_server.queue(QueryNodeinfo::new(listener))?;
|
||||
.queue(QueryInstance::new(actor_id.clone()))?;
|
||||
state.job_server.queue(QueryNodeinfo::new(actor_id))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user