1
0
Fork 0
forked from alemi/upub

feat: accept also bare note to publish

This commit is contained in:
əlemi 2024-03-28 05:24:38 +01:00
parent 0ec839f42f
commit b5867b90ac
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -78,8 +78,40 @@ pub async fn post(
None => Err(StatusCode::BAD_REQUEST.into()), None => Err(StatusCode::BAD_REQUEST.into()),
Some(BaseType::Link(_)) => Err(StatusCode::UNPROCESSABLE_ENTITY.into()), Some(BaseType::Link(_)) => Err(StatusCode::UNPROCESSABLE_ENTITY.into()),
// Some(BaseType::Object(ObjectType::Note)) => { Some(BaseType::Object(ObjectType::Note)) => {
// }, let oid = ctx.oid(uuid::Uuid::new_v4().to_string());
let aid = ctx.aid(uuid::Uuid::new_v4().to_string());
let activity_targets = activity.addressed();
let object_model = model::object::Model::new(
&activity
.set_id(Some(&oid))
.set_attributed_to(Node::link(uid.clone()))
.set_published(Some(chrono::Utc::now()))
)?;
let activity_model = model::activity::Model {
id: aid.clone(),
activity_type: ActivityType::Create,
actor: uid.clone(),
object: Some(oid.clone()),
target: None,
cc: object_model.cc.clone(),
bcc: object_model.bcc.clone(),
to: object_model.to.clone(),
bto: object_model.bto.clone(),
published: object_model.published,
};
model::object::Entity::insert(object_model.into_active_model())
.exec(ctx.db()).await?;
model::activity::Entity::insert(activity_model.into_active_model())
.exec(ctx.db()).await?;
let addressed = ctx.expand_addressing(&uid, activity_targets).await?;
ctx.address_to(&aid, Some(&oid), &addressed).await?;
ctx.deliver_to(&aid, &uid, &addressed).await?;
Ok(CreationResult(aid))
},
Some(BaseType::Object(ObjectType::Activity(ActivityType::Create))) => { Some(BaseType::Object(ObjectType::Activity(ActivityType::Create))) => {
let Some(object) = activity.object().get().map(|x| x.underlying_json_object()) else { let Some(object) = activity.object().get().map(|x| x.underlying_json_object()) else {