forked from alemi/upub
feat: increment statuses count
be it when posting, receiving a Create or fetching an object, increment relevant user statuses count
This commit is contained in:
parent
a966f7fcb5
commit
a6c3ef9a3e
3 changed files with 24 additions and 0 deletions
|
@ -166,6 +166,11 @@ async fn fetch_object_inner(ctx: &Context, id: &str, depth: usize) -> crate::Res
|
||||||
if let Err(e) = ctx.fetch_user(&attributed_to).await {
|
if let Err(e) = ctx.fetch_user(&attributed_to).await {
|
||||||
tracing::warn!("could not get actor of fetched object: {e}");
|
tracing::warn!("could not get actor of fetched object: {e}");
|
||||||
}
|
}
|
||||||
|
model::user::Entity::update_many()
|
||||||
|
.col_expr(model::user::Column::StatusesCount, Expr::col(model::user::Column::StatusesCount).add(1))
|
||||||
|
.filter(model::user::Column::Id.eq(&attributed_to))
|
||||||
|
.exec(ctx.db())
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let addressed = object.addressed();
|
let addressed = object.addressed();
|
||||||
|
|
|
@ -22,6 +22,7 @@ impl apb::server::Inbox for Context {
|
||||||
};
|
};
|
||||||
let mut object_model = model::object::Model::new(&object_node)?;
|
let mut object_model = model::object::Model::new(&object_node)?;
|
||||||
let oid = object_model.id.clone();
|
let oid = object_model.id.clone();
|
||||||
|
let uid = object_model.attributed_to.clone();
|
||||||
// make sure we're allowed to edit this object
|
// make sure we're allowed to edit this object
|
||||||
if let Some(object_author) = &object_model.attributed_to {
|
if let Some(object_author) = &object_model.attributed_to {
|
||||||
if server != Context::server(object_author) {
|
if server != Context::server(object_author) {
|
||||||
|
@ -58,6 +59,14 @@ impl apb::server::Inbox for Context {
|
||||||
.exec(self.db())
|
.exec(self.db())
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
// TODO can we even receive anonymous objects?
|
||||||
|
if let Some(object_author) = uid {
|
||||||
|
model::user::Entity::update_many()
|
||||||
|
.col_expr(model::user::Column::StatusesCount, Expr::col(model::user::Column::StatusesCount).add(1))
|
||||||
|
.filter(model::user::Column::Id.eq(&object_author))
|
||||||
|
.exec(self.db())
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
let expanded_addressing = self.expand_addressing(activity.addressed()).await?;
|
let expanded_addressing = self.expand_addressing(activity.addressed()).await?;
|
||||||
self.address_to(Some(&aid), Some(&oid), &expanded_addressing).await?;
|
self.address_to(Some(&aid), Some(&oid), &expanded_addressing).await?;
|
||||||
tracing::info!("{} posted {}", aid, oid);
|
tracing::info!("{} posted {}", aid, oid);
|
||||||
|
|
|
@ -47,6 +47,11 @@ impl apb::server::Outbox for Context {
|
||||||
.exec(self.db()).await?;
|
.exec(self.db()).await?;
|
||||||
model::activity::Entity::insert(activity_model.into_active_model())
|
model::activity::Entity::insert(activity_model.into_active_model())
|
||||||
.exec(self.db()).await?;
|
.exec(self.db()).await?;
|
||||||
|
model::user::Entity::update_many()
|
||||||
|
.col_expr(model::user::Column::StatusesCount, Expr::col(model::user::Column::StatusesCount).add(1))
|
||||||
|
.filter(model::user::Column::Id.eq(&uid))
|
||||||
|
.exec(self.db())
|
||||||
|
.await?;
|
||||||
|
|
||||||
self.dispatch(&uid, activity_targets, &aid, Some(&oid)).await?;
|
self.dispatch(&uid, activity_targets, &aid, Some(&oid)).await?;
|
||||||
|
|
||||||
|
@ -90,6 +95,11 @@ impl apb::server::Outbox for Context {
|
||||||
.exec(self.db()).await?;
|
.exec(self.db()).await?;
|
||||||
model::activity::Entity::insert(activity_model.into_active_model())
|
model::activity::Entity::insert(activity_model.into_active_model())
|
||||||
.exec(self.db()).await?;
|
.exec(self.db()).await?;
|
||||||
|
model::user::Entity::update_many()
|
||||||
|
.col_expr(model::user::Column::StatusesCount, Expr::col(model::user::Column::StatusesCount).add(1))
|
||||||
|
.filter(model::user::Column::Id.eq(&uid))
|
||||||
|
.exec(self.db())
|
||||||
|
.await?;
|
||||||
|
|
||||||
self.dispatch(&uid, activity_targets, &aid, Some(&oid)).await?;
|
self.dispatch(&uid, activity_targets, &aid, Some(&oid)).await?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue