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: { localFollowingCount: {
type: 'integer', type: 'integer',
optional: false, nullable: false, optional: true, nullable: false,
}, },
remoteFollowingCount: { remoteFollowingCount: {
type: 'integer', type: 'integer',
optional: false, nullable: false, optional: true, nullable: false,
}, },
localFollowersCount: { localFollowersCount: {
type: 'integer', type: 'integer',
optional: false, nullable: false, optional: true, nullable: false,
}, },
remoteFollowersCount: { remoteFollowersCount: {
type: 'integer', type: 'integer',
optional: false, nullable: false, optional: true, nullable: false,
}, },
followingCount: { followingCount: {
type: 'integer', type: 'integer',
optional: false, nullable: false, optional: true, nullable: false,
}, },
followersCount: { followersCount: {
type: 'integer', type: 'integer',
optional: false, nullable: false, optional: true, nullable: false,
}, },
sentReactionsCount: { sentReactionsCount: {
type: 'integer', type: 'integer',
@ -110,7 +110,7 @@ export const paramDef = {
} as const; } as const;
// eslint-disable-next-line import/no-default-export // 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 }); const user = await Users.findOneBy({ id: ps.userId });
if (user == null) { if (user == null) {
throw new ApiError('NO_SUCH_USER'); throw new ApiError('NO_SUCH_USER');
@ -141,22 +141,6 @@ export default define(meta, paramDef, async (ps) => {
.innerJoin('vote.note', 'note') .innerJoin('vote.note', 'note')
.where('note.userId = :userId', { userId: user.id }) .where('note.userId = :userId', { userId: user.id })
.getCount(), .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') sentReactionsCount: NoteReactions.createQueryBuilder('reaction')
.where('reaction.userId = :userId', { userId: user.id }) .where('reaction.userId = :userId', { userId: user.id })
.getCount(), .getCount(),
@ -180,8 +164,32 @@ export default define(meta, paramDef, async (ps) => {
driveUsage: DriveFiles.calcDriveUsageOf(user.id), 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.followingCount = result.localFollowingCount + result.remoteFollowingCount;
result.followersCount = result.localFollowersCount + result.remoteFollowersCount; result.followersCount = result.localFollowersCount + result.remoteFollowersCount;
}
return result; return result;
}); });