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