1
0
Fork 0
forked from alemi/upub

feat: fill undo ids for user in outbound activities

This commit is contained in:
əlemi 2024-07-05 03:18:33 +02:00
parent c14531afc8
commit f36c249803
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 21 additions and 3 deletions

View file

@ -1,7 +1,7 @@
use sea_orm::EntityTrait;
use reqwest::Method;
use apb::{LD, Node, ActivityMut};
use apb::{LD, ActivityMut};
use upub::{Context, model, traits::Fetcher};
pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<()> {

View file

@ -1,5 +1,5 @@
use apb::{target::Addressed, Activity, ActivityMut, BaseMut, Object, ObjectMut};
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QuerySelect, SelectColumns, TransactionTrait};
use apb::{field::OptionalString, target::Addressed, Activity, ActivityMut, Base, BaseMut, Object, ObjectMut};
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QueryOrder, QuerySelect, SelectColumns, TransactionTrait};
use upub::{model, traits::{Addresser, Processor}, Context};
@ -26,6 +26,24 @@ pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<
.set_actor(apb::Node::link(job.actor.clone()))
.set_published(Some(now));
if matches!(t, apb::ObjectType::Activity(apb::ActivityType::Undo)) {
let mut undone = activity.object().extract().ok_or(crate::JobError::MissingPayload)?;
if undone.id().is_err() {
let undone_target = undone.object().id().str().ok_or(crate::JobError::MissingPayload)?;
let undone_type = undone.activity_type().map_err(|_| crate::JobError::MissingPayload)?;
let undone_model = model::activity::Entity::find()
.filter(model::activity::Column::Object.eq(&undone_target))
.filter(model::activity::Column::Actor.eq(&job.actor))
.filter(model::activity::Column::ActivityType.eq(undone_type))
.order_by_desc(model::activity::Column::Published)
.one(&tx)
.await?
.ok_or_else(|| sea_orm::DbErr::RecordNotFound(format!("actor={},type={},object={}",job.actor, undone_type, undone_target)))?;
undone = undone.set_id(Some(&undone_model.id));
}
activity = activity.set_object(apb::Node::object(undone));
}
if matches!(t, apb::ObjectType::Activity(apb::ActivityType::Create)) {
let raw_oid = Context::new_id();
let oid = ctx.oid(&raw_oid);