[backend/database] Update follower/following counts on follow/unfollow/accept (ISH-17)
This commit is contained in:
parent
02e003afa3
commit
78b69c180c
2 changed files with 28 additions and 2 deletions
|
@ -106,6 +106,12 @@ public class AccountController(
|
||||||
await db.AddAsync(following);
|
await db.AddAsync(following);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If user is local, we need to increment following/follower counts here, otherwise we'll do it when receiving the Accept activity
|
||||||
|
if (followee.Host == null) {
|
||||||
|
followee.FollowersCount++;
|
||||||
|
user.FollowingCount++;
|
||||||
|
}
|
||||||
|
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
if (followee.IsLocked)
|
if (followee.IsLocked)
|
||||||
|
@ -158,7 +164,12 @@ public class AccountController(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (followee.PrecomputedIsFollowedBy ?? false) {
|
if (followee.PrecomputedIsFollowedBy ?? false) {
|
||||||
await db.Followings.Where(p => p.Follower == user && p.Followee == followee).ExecuteDeleteAsync();
|
var followings = await db.Followings.Where(p => p.Follower == user && p.Followee == followee).ToListAsync();
|
||||||
|
user.FollowingCount -= followings.Count;
|
||||||
|
followee.FollowersCount -= followings.Count;
|
||||||
|
db.RemoveRange(followings);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
followee.PrecomputedIsFollowedBy = false;
|
followee.PrecomputedIsFollowedBy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,9 @@ public class ActivityHandlerService(
|
||||||
FollowerSharedInbox = follower.SharedInbox
|
FollowerSharedInbox = follower.SharedInbox
|
||||||
};
|
};
|
||||||
|
|
||||||
|
follower.FollowingCount++;
|
||||||
|
followee.FollowersCount++;
|
||||||
|
|
||||||
await db.AddAsync(following);
|
await db.AddAsync(following);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
@ -166,7 +169,15 @@ public class ActivityHandlerService(
|
||||||
var followee = await userResolver.ResolveAsync(followeeActor.Id);
|
var followee = await userResolver.ResolveAsync(followeeActor.Id);
|
||||||
|
|
||||||
await db.FollowRequests.Where(p => p.Follower == follower && p.Followee == followee).ExecuteDeleteAsync();
|
await db.FollowRequests.Where(p => p.Follower == follower && p.Followee == followee).ExecuteDeleteAsync();
|
||||||
await db.Followings.Where(p => p.Follower == follower && p.Followee == followee).ExecuteDeleteAsync();
|
|
||||||
|
// We don't want to use ExecuteDelete for this one to ensure consistency with following counters
|
||||||
|
var followings = await db.Followings.Where(p => p.Follower == follower && p.Followee == followee).ToListAsync();
|
||||||
|
if (followings.Count > 0) {
|
||||||
|
followee.FollowersCount -= followings.Count;
|
||||||
|
follower.FollowingCount -= followings.Count;
|
||||||
|
db.RemoveRange(followings);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AcceptAsync(ASObject obj, ASObject actor) {
|
private async Task AcceptAsync(ASObject obj, ASObject actor) {
|
||||||
|
@ -200,6 +211,10 @@ public class ActivityHandlerService(
|
||||||
FollowerSharedInbox = request.FollowerSharedInbox,
|
FollowerSharedInbox = request.FollowerSharedInbox,
|
||||||
FolloweeSharedInbox = request.FolloweeSharedInbox
|
FolloweeSharedInbox = request.FolloweeSharedInbox
|
||||||
};
|
};
|
||||||
|
|
||||||
|
resolvedActor.FollowersCount++;
|
||||||
|
request.Follower.FollowingCount++;
|
||||||
|
|
||||||
db.Remove(request);
|
db.Remove(request);
|
||||||
await db.AddAsync(following);
|
await db.AddAsync(following);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
Loading…
Add table
Reference in a new issue