BREAKING server: respect ffVisibility on stats endpoint

This makes the returned values `localFollowingCount`,
`remoteFollowingCount`, `followingCount`, `localFollowersCount`,
`remotefollowersCount`,  `followersCount` optional on the API endpoint
`users/stats`.

Changelog: Fixed
This commit is contained in:
Johann150 2023-05-20 00:25:41 +02:00
parent ded48c96d8
commit ef4055840b
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -46,27 +46,27 @@ export const meta = {
},
localFollowingCount: {
type: 'integer',
optional: false, nullable: false,
optional: true, nullable: false,
},
remoteFollowingCount: {
type: 'integer',
optional: false, nullable: false,
optional: true, nullable: false,
},
localFollowersCount: {
type: 'integer',
optional: false, nullable: false,
optional: true, nullable: false,
},
remoteFollowersCount: {
type: 'integer',
optional: false, nullable: false,
optional: true, nullable: false,
},
followingCount: {
type: 'integer',
optional: false, nullable: false,
optional: true, nullable: false,
},
followersCount: {
type: 'integer',
optional: false, nullable: false,
optional: true, nullable: false,
},
sentReactionsCount: {
type: 'integer',
@ -110,7 +110,7 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps) => {
export default define(meta, paramDef, async (ps, me) => {
const user = await Users.findOneBy({ id: ps.userId });
if (user == null) {
throw new ApiError('NO_SUCH_USER');
@ -141,22 +141,6 @@ export default define(meta, paramDef, async (ps) => {
.innerJoin('vote.note', 'note')
.where('note.userId = :userId', { userId: user.id })
.getCount(),
localFollowingCount: Followings.createQueryBuilder('following')
.where('following.followerId = :userId', { userId: user.id })
.andWhere('following.followeeHost IS NULL')
.getCount(),
remoteFollowingCount: Followings.createQueryBuilder('following')
.where('following.followerId = :userId', { userId: user.id })
.andWhere('following.followeeHost IS NOT NULL')
.getCount(),
localFollowersCount: Followings.createQueryBuilder('following')
.where('following.followeeId = :userId', { userId: user.id })
.andWhere('following.followerHost IS NULL')
.getCount(),
remoteFollowersCount: Followings.createQueryBuilder('following')
.where('following.followeeId = :userId', { userId: user.id })
.andWhere('following.followerHost IS NOT NULL')
.getCount(),
sentReactionsCount: NoteReactions.createQueryBuilder('reaction')
.where('reaction.userId = :userId', { userId: user.id })
.getCount(),
@ -180,8 +164,32 @@ export default define(meta, paramDef, async (ps) => {
driveUsage: DriveFiles.calcDriveUsageOf(user.id),
});
const ffVisible = await Users.areFollowersVisibleTo(user, me);
if (ffVisible) {
const follows = await awaitAll({
localFollowingCount: Followings.createQueryBuilder('following')
.where('following.followerId = :userId', { userId: user.id })
.andWhere('following.followeeHost IS NULL')
.getCount(),
remoteFollowingCount: Followings.createQueryBuilder('following')
.where('following.followerId = :userId', { userId: user.id })
.andWhere('following.followeeHost IS NOT NULL')
.getCount(),
localFollowersCount: Followings.createQueryBuilder('following')
.where('following.followeeId = :userId', { userId: user.id })
.andWhere('following.followerHost IS NULL')
.getCount(),
remoteFollowersCount: Followings.createQueryBuilder('following')
.where('following.followeeId = :userId', { userId: user.id })
.andWhere('following.followerHost IS NOT NULL')
.getCount(),
});
Object.assign(result, follows);
result.followingCount = result.localFollowingCount + result.remoteFollowingCount;
result.followersCount = result.localFollowersCount + result.remoteFollowersCount;
}
return result;
});