fix: increase follow counts on Accept

both for inbox and outbox
This commit is contained in:
əlemi 2024-04-18 03:41:27 +02:00
parent 9cb2acdafd
commit 094a8b957c
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 18 additions and 5 deletions

View file

@ -27,10 +27,7 @@ impl Identity {
} }
pub fn is_anon(&self) -> bool { pub fn is_anon(&self) -> bool {
match self { matches!(self, Self::Anonymous)
Self::Anonymous => true,
_ => false,
}
} }
pub fn is_user(&self, uid: &str) -> bool { pub fn is_user(&self, uid: &str) -> bool {

View file

@ -96,6 +96,14 @@ impl apb::server::Inbox for Context {
model::activity::Entity::insert(activity_model.clone().into_active_model()) model::activity::Entity::insert(activity_model.clone().into_active_model())
.exec(self.db()) .exec(self.db())
.await?; .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::Entity::insert(
model::relation::ActiveModel { model::relation::ActiveModel {
follower: Set(follow_activity.actor), follower: Set(follow_activity.actor),

View file

@ -1,5 +1,5 @@
use apb::{target::Addressed, Activity, ActivityMut, BaseMut, Node, ObjectMut}; 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}; use crate::{errors::UpubError, model};
@ -148,6 +148,14 @@ impl apb::server::Outbox for Context {
match accepted_activity.activity_type { match accepted_activity.activity_type {
apb::ActivityType::Follow => { 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::Entity::insert(
model::relation::ActiveModel { model::relation::ActiveModel {
follower: Set(accepted_activity.actor), following: Set(uid.clone()), follower: Set(accepted_activity.actor), following: Set(uid.clone()),