forked from alemi/upub
fix: dont over-decrement on follow undo
This commit is contained in:
parent
94c8900dcb
commit
3781d38f95
1 changed files with 22 additions and 10 deletions
|
@ -335,11 +335,22 @@ pub async fn undo(_ctx: &crate::Context, activity: impl apb::Activity, tx: &Data
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(ProcessorError::Incomplete)?;
|
.ok_or(ProcessorError::Incomplete)?;
|
||||||
|
|
||||||
|
// no pending relation to undo
|
||||||
|
let relation = crate::model::relation::Entity::find()
|
||||||
|
.filter(model::relation::Column::Follower.eq(internal_uid))
|
||||||
|
.filter(model::relation::Column::Following.eq(internal_uid_following))
|
||||||
|
.one(tx)
|
||||||
|
.await?
|
||||||
|
.ok_or(ProcessorError::AlreadyProcessed)?;
|
||||||
|
|
||||||
crate::model::relation::Entity::delete_many()
|
crate::model::relation::Entity::delete_many()
|
||||||
.filter(crate::model::relation::Column::Follower.eq(internal_uid))
|
.filter(crate::model::relation::Column::Follower.eq(internal_uid))
|
||||||
.filter(crate::model::relation::Column::Following.eq(internal_uid_following))
|
.filter(crate::model::relation::Column::Following.eq(internal_uid_following))
|
||||||
.exec(tx)
|
.exec(tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
if relation.accept.is_some() {
|
||||||
crate::model::actor::Entity::update_many()
|
crate::model::actor::Entity::update_many()
|
||||||
.filter(crate::model::actor::Column::Internal.eq(internal_uid))
|
.filter(crate::model::actor::Column::Internal.eq(internal_uid))
|
||||||
.col_expr(crate::model::actor::Column::FollowingCount, Expr::col(crate::model::actor::Column::FollowingCount).sub(1))
|
.col_expr(crate::model::actor::Column::FollowingCount, Expr::col(crate::model::actor::Column::FollowingCount).sub(1))
|
||||||
|
@ -350,6 +361,7 @@ pub async fn undo(_ctx: &crate::Context, activity: impl apb::Activity, tx: &Data
|
||||||
.col_expr(crate::model::actor::Column::FollowersCount, Expr::col(crate::model::actor::Column::FollowersCount).sub(1))
|
.col_expr(crate::model::actor::Column::FollowersCount, Expr::col(crate::model::actor::Column::FollowersCount).sub(1))
|
||||||
.exec(tx)
|
.exec(tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => return Err(ProcessorError::Unprocessable(activity.id()?.to_string())),
|
_ => return Err(ProcessorError::Unprocessable(activity.id()?.to_string())),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue