summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-10-06 16:28:21 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-10-06 16:28:21 +0900
commit4489ca3c74d3e5ee85b2ce0cf2721c49b6edf7ea (patch)
treed0fb5f26b410d5a3f8d1cab56f51ce951fadc956 /packages/backend/src
parentenhance(backend): some tweaks (diff)
downloadsharkey-4489ca3c74d3e5ee85b2ce0cf2721c49b6edf7ea.tar.gz
sharkey-4489ca3c74d3e5ee85b2ce0cf2721c49b6edf7ea.tar.bz2
sharkey-4489ca3c74d3e5ee85b2ce0cf2721c49b6edf7ea.zip
refactor
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/entities/UserEntityService.ts70
1 files changed, 41 insertions, 29 deletions
diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts
index 6ae16613c0..ee67634da5 100644
--- a/packages/backend/src/core/entities/UserEntityService.ts
+++ b/packages/backend/src/core/entities/UserEntityService.ts
@@ -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