[mastodon-client] Fix user profile aggregate when only target is self

This commit is contained in:
Laura Hausmann 2023-11-25 02:08:48 +01:00
parent f350755721
commit 5490137f44
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -126,17 +126,21 @@ export class UserConverter {
const userProfileAggregate = new Map<User["id"], UserProfile | null>(); const userProfileAggregate = new Map<User["id"], UserProfile | null>();
if (user) { if (user) {
const followings = await Followings.createQueryBuilder('following') const targetsWithoutSelf = targets.filter(u => u !== user.id);
.select('following.followeeId')
.where('following.followerId = :meId', { meId: user.id }) if (targetsWithoutSelf.length > 0) {
.andWhere('following.followeeId IN (:...targets)', { targets: targets.filter(u => u !== user.id) }) const followings = await Followings.createQueryBuilder('following')
.getMany(); .select('following.followeeId')
.where('following.followerId = :meId', { meId: user.id })
.andWhere('following.followeeId IN (:...targets)', { targets: targetsWithoutSelf })
.getMany();
for (const userId of targetsWithoutSelf) {
followedOrSelfAggregate.set(userId, !!followings.find(f => f.followerId === userId));
}
}
followedOrSelfAggregate.set(user.id, true); followedOrSelfAggregate.set(user.id, true);
for (const userId of targets.filter(u => u !== user.id)) {
followedOrSelfAggregate.set(userId, !!followings.find(f => f.followerId === userId));
}
} }
const profiles = await UserProfiles.findBy({ const profiles = await UserProfiles.findBy({