feat: add fetch_outbox on folreq and outbox?fetch
This commit is contained in:
parent
9b6f438a98
commit
815fdcd883
3 changed files with 28 additions and 2 deletions
|
@ -101,6 +101,7 @@ pub trait Fetcher {
|
|||
async fn resolve_object(&self, object: serde_json::Value, tx: &impl ConnectionTrait) -> Result<crate::model::object::Model, RequestError>;
|
||||
|
||||
async fn fetch_thread(&self, id: &str, tx: &impl ConnectionTrait) -> Result<(), RequestError>;
|
||||
async fn fetch_outbox(&self, id: &str, tx: &impl ConnectionTrait) -> Result<(), RequestError>;
|
||||
|
||||
fn client(domain: &str) -> reqwest::Client {
|
||||
reqwest::Client::builder()
|
||||
|
@ -447,6 +448,8 @@ impl Fetcher for crate::Context {
|
|||
page = page.first().into_inner()?;
|
||||
}
|
||||
|
||||
// TODO parallelize these
|
||||
|
||||
for obj in page.items().flat() {
|
||||
if let Err(e) = self.fetch_object(&obj.id()?, tx).await {
|
||||
tracing::warn!("error fetching reply: {e}");
|
||||
|
@ -466,6 +469,21 @@ impl Fetcher for crate::Context {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn fetch_outbox(&self, id: &str, tx: &impl ConnectionTrait) -> Result<(), RequestError> {
|
||||
let actor = self.pull(id).await?.actor()?;
|
||||
let outbox = actor
|
||||
.outbox().resolve(self).await?
|
||||
.first().resolve(self).await?;
|
||||
|
||||
// TODO parallelize these
|
||||
|
||||
for item in outbox.ordered_items().all_ids() {
|
||||
self.fetch_object(&item, tx).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn fetch_object(&self, id: &str, tx: &impl ConnectionTrait) -> Result<crate::model::object::Model, RequestError> {
|
||||
fetch_object_r(self, id, 0, tx).await
|
||||
}
|
||||
|
|
|
@ -203,6 +203,7 @@ pub async fn follow(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
|
|||
ctx.address(Some(&activity_model), None, tx).await?;
|
||||
|
||||
if ctx.is_local(&target_actor.id) {
|
||||
ctx.fetch_outbox(&target_actor.id, tx).await?;
|
||||
crate::Query::notify(activity_model.internal, target_actor.internal)
|
||||
.exec(tx)
|
||||
.await?;
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
use axum::{extract::{Path, Query, State}, http::StatusCode, Json};
|
||||
use sea_orm::{ActiveValue::{NotSet, Set}, ColumnTrait, Condition, EntityTrait, QueryFilter, QueryOrder, QuerySelect};
|
||||
|
||||
use upub::{model, selector::{RichActivity, RichFillable}, Context};
|
||||
use upub::{model, selector::{RichActivity, RichFillable}, traits::Fetcher, Context};
|
||||
|
||||
use crate::{activitypub::{CreationResult, Pagination}, builders::JsonLD, AuthIdentity, Identity};
|
||||
use crate::{activitypub::{CreationResult, Pagination, TryFetch}, builders::JsonLD, AuthIdentity, Identity};
|
||||
|
||||
pub async fn get(
|
||||
State(ctx): State<Context>,
|
||||
AuthIdentity(auth): AuthIdentity,
|
||||
Path(id): Path<String>,
|
||||
Query(query): Query<TryFetch>,
|
||||
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
|
||||
let uid = ctx.uid(&id);
|
||||
if auth.is_local() && query.fetch && !ctx.is_local(&uid) {
|
||||
ctx.fetch_outbox(&uid, ctx.db()).await?;
|
||||
}
|
||||
|
||||
crate::builders::collection(upub::url!(ctx, "/actors/{id}/outbox"), None)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue