This commit is contained in:
syuilo 2023-10-06 16:28:21 +09:00
parent 87416710c3
commit 4489ca3c74

View file

@ -146,64 +146,76 @@ export class UserEntityService implements OnModuleInit {
@bindThis
public async getRelation(me: MiUser['id'], target: MiUser['id']) {
const following = await this.followingsRepository.findOneBy({
followerId: me,
followeeId: target,
});
return awaitAll({
id: target,
const [
following,
isFollowing: following != null,
isFollowed: this.followingsRepository.count({
isFollowed,
hasPendingFollowRequestFromYou,
hasPendingFollowRequestToYou,
isBlocking,
isBlocked,
isMuted,
isRenoteMuted,
] = await Promise.all([
this.followingsRepository.findOneBy({
followerId: me,
followeeId: target,
}),
this.followingsRepository.exist({
where: {
followerId: target,
followeeId: me,
},
take: 1,
}).then(n => n > 0),
hasPendingFollowRequestFromYou: this.followRequestsRepository.count({
}),
this.followRequestsRepository.exist({
where: {
followerId: me,
followeeId: target,
},
take: 1,
}).then(n => n > 0),
hasPendingFollowRequestToYou: this.followRequestsRepository.count({
}),
this.followRequestsRepository.exist({
where: {
followerId: target,
followeeId: me,
},
take: 1,
}).then(n => n > 0),
isBlocking: this.blockingsRepository.count({
}),
this.blockingsRepository.exist({
where: {
blockerId: me,
blockeeId: target,
},
take: 1,
}).then(n => n > 0),
isBlocked: this.blockingsRepository.count({
}),
this.blockingsRepository.exist({
where: {
blockerId: target,
blockeeId: me,
},
take: 1,
}).then(n => n > 0),
isMuted: this.mutingsRepository.count({
}),
this.mutingsRepository.exist({
where: {
muterId: me,
muteeId: target,
},
take: 1,
}).then(n => n > 0),
isRenoteMuted: this.renoteMutingsRepository.count({
}),
this.renoteMutingsRepository.exist({
where: {
muterId: me,
muteeId: target,
},
take: 1,
}).then(n => n > 0),
});
}),
]);
return {
id: target,
following,
isFollowing: following != null,
isFollowed,
hasPendingFollowRequestFromYou,
hasPendingFollowRequestToYou,
isBlocking,
isBlocked,
isMuted,
isRenoteMuted,
};
}
@bindThis