diff --git a/src/server/auth.rs b/src/server/auth.rs index afbfe465..89adc186 100644 --- a/src/server/auth.rs +++ b/src/server/auth.rs @@ -27,10 +27,7 @@ impl Identity { } pub fn is_anon(&self) -> bool { - match self { - Self::Anonymous => true, - _ => false, - } + matches!(self, Self::Anonymous) } pub fn is_user(&self, uid: &str) -> bool { diff --git a/src/server/inbox.rs b/src/server/inbox.rs index 96718172..7c1fddf3 100644 --- a/src/server/inbox.rs +++ b/src/server/inbox.rs @@ -96,6 +96,14 @@ impl apb::server::Inbox for Context { model::activity::Entity::insert(activity_model.clone().into_active_model()) .exec(self.db()) .await?; + model::user::Entity::update_many() + .col_expr( + model::user::Column::FollowingCount, + Expr::col(model::user::Column::FollowingCount).add(1) + ) + .filter(model::user::Column::Id.eq(&follow_activity.actor)) + .exec(self.db()) + .await?; model::relation::Entity::insert( model::relation::ActiveModel { follower: Set(follow_activity.actor), diff --git a/src/server/outbox.rs b/src/server/outbox.rs index a91510ec..f827ff70 100644 --- a/src/server/outbox.rs +++ b/src/server/outbox.rs @@ -1,5 +1,5 @@ use apb::{target::Addressed, Activity, ActivityMut, BaseMut, Node, ObjectMut}; -use sea_orm::{EntityTrait, IntoActiveModel, Set}; +use sea_orm::{sea_query::Expr, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter, Set}; use crate::{errors::UpubError, model}; @@ -148,6 +148,14 @@ impl apb::server::Outbox for Context { match accepted_activity.activity_type { apb::ActivityType::Follow => { + model::user::Entity::update_many() + .col_expr( + model::user::Column::FollowersCount, + Expr::col(model::user::Column::FollowersCount).add(1) + ) + .filter(model::user::Column::Id.eq(&uid)) + .exec(self.db()) + .await?; model::relation::Entity::insert( model::relation::ActiveModel { follower: Set(accepted_activity.actor), following: Set(uid.clone()),