summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/NoteCreateService.ts20
-rw-r--r--packages/backend/src/core/NoteReadService.ts14
-rw-r--r--packages/backend/src/core/SignupService.ts4
-rw-r--r--packages/backend/src/core/UserFollowingService.ts40
-rw-r--r--packages/backend/src/core/activitypub/ApInboxService.ts30
-rw-r--r--packages/backend/src/core/activitypub/ApRendererService.ts4
-rw-r--r--packages/backend/src/core/entities/ChannelEntityService.ts31
-rw-r--r--packages/backend/src/core/entities/ClipEntityService.ts2
-rw-r--r--packages/backend/src/core/entities/FlashEntityService.ts2
-rw-r--r--packages/backend/src/core/entities/GalleryPostEntityService.ts2
-rw-r--r--packages/backend/src/core/entities/NoteEntityService.ts14
-rw-r--r--packages/backend/src/core/entities/PageEntityService.ts2
-rw-r--r--packages/backend/src/core/entities/UserEntityService.ts12
13 files changed, 103 insertions, 74 deletions
diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts
index fb36ca3b6a..4f3d66dd58 100644
--- a/packages/backend/src/core/NoteCreateService.ts
+++ b/packages/backend/src/core/NoteCreateService.ts
@@ -570,12 +570,14 @@ export class NoteCreateService implements OnApplicationShutdown {
if (data.reply) {
// 通知
if (data.reply.userHost === null) {
- const threadMuted = await this.noteThreadMutingsRepository.findOneBy({
- userId: data.reply.userId,
- threadId: data.reply.threadId ?? data.reply.id,
+ const isThreadMuted = await this.noteThreadMutingsRepository.exist({
+ where: {
+ userId: data.reply.userId,
+ threadId: data.reply.threadId ?? data.reply.id,
+ }
});
- if (!threadMuted) {
+ if (!isThreadMuted) {
nm.push(data.reply.userId, 'reply');
this.globalEventService.publishMainStream(data.reply.userId, 'reply', noteObj);
@@ -712,12 +714,14 @@ export class NoteCreateService implements OnApplicationShutdown {
@bindThis
private async createMentionedEvents(mentionedUsers: MinimumUser[], note: Note, nm: NotificationManager) {
for (const u of mentionedUsers.filter(u => this.userEntityService.isLocalUser(u))) {
- const threadMuted = await this.noteThreadMutingsRepository.findOneBy({
- userId: u.id,
- threadId: note.threadId ?? note.id,
+ const isThreadMuted = await this.noteThreadMutingsRepository.exist({
+ where: {
+ userId: u.id,
+ threadId: note.threadId ?? note.id,
+ },
});
- if (threadMuted) {
+ if (isThreadMuted) {
continue;
}
diff --git a/packages/backend/src/core/NoteReadService.ts b/packages/backend/src/core/NoteReadService.ts
index b84591e26d..52e9bd369a 100644
--- a/packages/backend/src/core/NoteReadService.ts
+++ b/packages/backend/src/core/NoteReadService.ts
@@ -43,11 +43,13 @@ export class NoteReadService implements OnApplicationShutdown {
//#endregion
// スレッドミュート
- const threadMute = await this.noteThreadMutingsRepository.findOneBy({
- userId: userId,
- threadId: note.threadId ?? note.id,
+ const isThreadMuted = await this.noteThreadMutingsRepository.exist({
+ where: {
+ userId: userId,
+ threadId: note.threadId ?? note.id,
+ },
});
- if (threadMute) return;
+ if (isThreadMuted) return;
const unread = {
id: this.idService.genId(),
@@ -62,9 +64,9 @@ export class NoteReadService implements OnApplicationShutdown {
// 2秒経っても既読にならなかったら「未読の投稿がありますよ」イベントを発行する
setTimeout(2000, 'unread note', { signal: this.#shutdownController.signal }).then(async () => {
- const exist = await this.noteUnreadsRepository.findOneBy({ id: unread.id });
+ const exist = await this.noteUnreadsRepository.exist({ where: { id: unread.id } });
- if (exist == null) return;
+ if (!exist) return;
if (params.isMentioned) {
this.globalEventService.publishMainStream(userId, 'unreadMention', note.id);
diff --git a/packages/backend/src/core/SignupService.ts b/packages/backend/src/core/SignupService.ts
index e6b17a8741..1e44406c16 100644
--- a/packages/backend/src/core/SignupService.ts
+++ b/packages/backend/src/core/SignupService.ts
@@ -71,12 +71,12 @@ export class SignupService {
const secret = generateUserToken();
// Check username duplication
- if (await this.usersRepository.findOneBy({ usernameLower: username.toLowerCase(), host: IsNull() })) {
+ if (await this.usersRepository.exist({ where: { usernameLower: username.toLowerCase(), host: IsNull() } })) {
throw new Error('DUPLICATED_USERNAME');
}
// Check deleted username duplication
- if (await this.usedUsernamesRepository.findOneBy({ username: username.toLowerCase() })) {
+ if (await this.usedUsernamesRepository.exist({ where: { username: username.toLowerCase() } })) {
throw new Error('USED_USERNAME');
}
diff --git a/packages/backend/src/core/UserFollowingService.ts b/packages/backend/src/core/UserFollowingService.ts
index 7d90bc2c08..4d7bfeaf23 100644
--- a/packages/backend/src/core/UserFollowingService.ts
+++ b/packages/backend/src/core/UserFollowingService.ts
@@ -122,22 +122,26 @@ export class UserFollowingService implements OnModuleInit {
let autoAccept = false;
// 鍵アカウントであっても、既にフォローされていた場合はスルー
- const following = await this.followingsRepository.findOneBy({
- followerId: follower.id,
- followeeId: followee.id,
+ const isFollowing = await this.followingsRepository.exist({
+ where: {
+ followerId: follower.id,
+ followeeId: followee.id,
+ },
});
- if (following) {
+ if (isFollowing) {
autoAccept = true;
}
// フォローしているユーザーは自動承認オプション
if (!autoAccept && (this.userEntityService.isLocalUser(followee) && followeeProfile.autoAcceptFollowed)) {
- const followed = await this.followingsRepository.findOneBy({
- followerId: followee.id,
- followeeId: follower.id,
+ const isFollowed = await this.followingsRepository.exist({
+ where: {
+ followerId: followee.id,
+ followeeId: follower.id,
+ },
});
- if (followed) autoAccept = true;
+ if (isFollowed) autoAccept = true;
}
// Automatically accept if the follower is an account who has moved and the locked followee had accepted the old account.
@@ -206,12 +210,14 @@ export class UserFollowingService implements OnModuleInit {
this.cacheService.userFollowingsCache.refresh(follower.id);
- const req = await this.followRequestsRepository.findOneBy({
- followeeId: followee.id,
- followerId: follower.id,
+ const requestExist = await this.followRequestsRepository.exist({
+ where: {
+ followeeId: followee.id,
+ followerId: follower.id,
+ },
});
- if (req) {
+ if (requestExist) {
await this.followRequestsRepository.delete({
followeeId: followee.id,
followerId: follower.id,
@@ -505,12 +511,14 @@ export class UserFollowingService implements OnModuleInit {
}
}
- const request = await this.followRequestsRepository.findOneBy({
- followeeId: followee.id,
- followerId: follower.id,
+ const requestExist = await this.followRequestsRepository.exist({
+ where: {
+ followeeId: followee.id,
+ followerId: follower.id,
+ },
});
- if (request == null) {
+ if (!requestExist) {
throw new IdentifiableError('17447091-ce07-46dd-b331-c1fd4f15b1e7', 'request not found');
}
diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts
index efef777fb0..b0428763c9 100644
--- a/packages/backend/src/core/activitypub/ApInboxService.ts
+++ b/packages/backend/src/core/activitypub/ApInboxService.ts
@@ -618,12 +618,14 @@ export class ApInboxService {
return 'skip: follower not found';
}
- const following = await this.followingsRepository.findOneBy({
- followerId: follower.id,
- followeeId: actor.id,
+ const isFollowing = await this.followingsRepository.exist({
+ where: {
+ followerId: follower.id,
+ followeeId: actor.id,
+ },
});
- if (following) {
+ if (isFollowing) {
await this.userFollowingService.unfollow(follower, actor);
return 'ok: unfollowed';
}
@@ -673,22 +675,26 @@ export class ApInboxService {
return 'skip: フォロー解除しようとしているユーザーはローカルユーザーではありません';
}
- const req = await this.followRequestsRepository.findOneBy({
- followerId: actor.id,
- followeeId: followee.id,
+ const requestExist = await this.followRequestsRepository.exist({
+ where: {
+ followerId: actor.id,
+ followeeId: followee.id,
+ },
});
- const following = await this.followingsRepository.findOneBy({
- followerId: actor.id,
- followeeId: followee.id,
+ const isFollowing = await this.followingsRepository.exist({
+ where: {
+ followerId: actor.id,
+ followeeId: followee.id,
+ },
});
- if (req) {
+ if (requestExist) {
await this.userFollowingService.cancelFollowRequest(followee, actor);
return 'ok: follow request canceled';
}
- if (following) {
+ if (isFollowing) {
await this.userFollowingService.unfollow(actor, followee);
return 'ok: unfollowed';
}
diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts
index d8b95ca4d1..96ac5c61f1 100644
--- a/packages/backend/src/core/activitypub/ApRendererService.ts
+++ b/packages/backend/src/core/activitypub/ApRendererService.ts
@@ -323,9 +323,9 @@ export class ApRendererService {
inReplyToNote = await this.notesRepository.findOneBy({ id: note.replyId });
if (inReplyToNote != null) {
- const inReplyToUser = await this.usersRepository.findOneBy({ id: inReplyToNote.userId });
+ const inReplyToUserExist = await this.usersRepository.exist({ where: { id: inReplyToNote.userId } });
- if (inReplyToUser != null) {
+ if (inReplyToUserExist) {
if (inReplyToNote.uri) {
inReplyTo = inReplyToNote.uri;
} else {
diff --git a/packages/backend/src/core/entities/ChannelEntityService.ts b/packages/backend/src/core/entities/ChannelEntityService.ts
index 15ffd44861..d24657260f 100644
--- a/packages/backend/src/core/entities/ChannelEntityService.ts
+++ b/packages/backend/src/core/entities/ChannelEntityService.ts
@@ -47,17 +47,26 @@ export class ChannelEntityService {
const banner = channel.bannerId ? await this.driveFilesRepository.findOneBy({ id: channel.bannerId }) : null;
- const hasUnreadNote = meId ? (await this.noteUnreadsRepository.findOneBy({ noteChannelId: channel.id, userId: meId })) != null : undefined;
+ const hasUnreadNote = meId ? await this.noteUnreadsRepository.exist({
+ where: {
+ noteChannelId: channel.id,
+ userId: meId
+ },
+ }) : undefined;
- const following = meId ? await this.channelFollowingsRepository.findOneBy({
- followerId: meId,
- followeeId: channel.id,
- }) : null;
+ const isFollowing = meId ? await this.channelFollowingsRepository.exist({
+ where: {
+ followerId: meId,
+ followeeId: channel.id,
+ },
+ }) : false;
- const favorite = meId ? await this.channelFavoritesRepository.findOneBy({
- userId: meId,
- channelId: channel.id,
- }) : null;
+ const isFavorited = meId ? await this.channelFavoritesRepository.exist({
+ where: {
+ userId: meId,
+ channelId: channel.id,
+ },
+ }) : false;
const pinnedNotes = channel.pinnedNoteIds.length > 0 ? await this.notesRepository.find({
where: {
@@ -80,8 +89,8 @@ export class ChannelEntityService {
notesCount: channel.notesCount,
...(me ? {
- isFollowing: following != null,
- isFavorited: favorite != null,
+ isFollowing,
+ isFavorited,
hasUnreadNote,
} : {}),
diff --git a/packages/backend/src/core/entities/ClipEntityService.ts b/packages/backend/src/core/entities/ClipEntityService.ts
index 33d3c53806..f558cbc33d 100644
--- a/packages/backend/src/core/entities/ClipEntityService.ts
+++ b/packages/backend/src/core/entities/ClipEntityService.ts
@@ -39,7 +39,7 @@ export class ClipEntityService {
description: clip.description,
isPublic: clip.isPublic,
favoritedCount: await this.clipFavoritesRepository.countBy({ clipId: clip.id }),
- isFavorited: meId ? await this.clipFavoritesRepository.findOneBy({ clipId: clip.id, userId: meId }).then(x => x != null) : undefined,
+ isFavorited: meId ? await this.clipFavoritesRepository.exist({ where: { clipId: clip.id, userId: meId } }) : undefined,
});
}
diff --git a/packages/backend/src/core/entities/FlashEntityService.ts b/packages/backend/src/core/entities/FlashEntityService.ts
index e52a591884..92345457c9 100644
--- a/packages/backend/src/core/entities/FlashEntityService.ts
+++ b/packages/backend/src/core/entities/FlashEntityService.ts
@@ -40,7 +40,7 @@ export class FlashEntityService {
summary: flash.summary,
script: flash.script,
likedCount: flash.likedCount,
- isLiked: meId ? await this.flashLikesRepository.findOneBy({ flashId: flash.id, userId: meId }).then(x => x != null) : undefined,
+ isLiked: meId ? await this.flashLikesRepository.exist({ where: { flashId: flash.id, userId: meId } }) : undefined,
});
}
diff --git a/packages/backend/src/core/entities/GalleryPostEntityService.ts b/packages/backend/src/core/entities/GalleryPostEntityService.ts
index 632c75304f..c44a5df118 100644
--- a/packages/backend/src/core/entities/GalleryPostEntityService.ts
+++ b/packages/backend/src/core/entities/GalleryPostEntityService.ts
@@ -46,7 +46,7 @@ export class GalleryPostEntityService {
tags: post.tags.length > 0 ? post.tags : undefined,
isSensitive: post.isSensitive,
likedCount: post.likedCount,
- isLiked: meId ? await this.galleryLikesRepository.findOneBy({ postId: post.id, userId: meId }).then(x => x != null) : undefined,
+ isLiked: meId ? await this.galleryLikesRepository.exist({ where: { postId: post.id, userId: meId } }) : undefined,
});
}
diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts
index e730c0eb8f..546e5f56d2 100644
--- a/packages/backend/src/core/entities/NoteEntityService.ts
+++ b/packages/backend/src/core/entities/NoteEntityService.ts
@@ -106,16 +106,14 @@ export class NoteEntityService implements OnModuleInit {
hide = false;
} else {
// フォロワーかどうか
- const following = await this.followingsRepository.findOneBy({
- followeeId: packedNote.userId,
- followerId: meId,
+ const isFollowing = await this.followingsRepository.exist({
+ where: {
+ followeeId: packedNote.userId,
+ followerId: meId,
+ },
});
- if (following == null) {
- hide = true;
- } else {
- hide = false;
- }
+ hide = !isFollowing;
}
}
diff --git a/packages/backend/src/core/entities/PageEntityService.ts b/packages/backend/src/core/entities/PageEntityService.ts
index d6da856637..94b26a5017 100644
--- a/packages/backend/src/core/entities/PageEntityService.ts
+++ b/packages/backend/src/core/entities/PageEntityService.ts
@@ -97,7 +97,7 @@ export class PageEntityService {
eyeCatchingImage: page.eyeCatchingImageId ? await this.driveFileEntityService.pack(page.eyeCatchingImageId) : null,
attachedFiles: this.driveFileEntityService.packMany((await Promise.all(attachedFiles)).filter((x): x is DriveFile => x != null)),
likedCount: page.likedCount,
- isLiked: meId ? await this.pageLikesRepository.findOneBy({ pageId: page.id, userId: meId }).then(x => x != null) : undefined,
+ isLiked: meId ? await this.pageLikesRepository.exist({ where: { pageId: page.id, userId: meId } }) : undefined,
});
}
diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts
index 6dacaa1032..7d248f8524 100644
--- a/packages/backend/src/core/entities/UserEntityService.ts
+++ b/packages/backend/src/core/entities/UserEntityService.ts
@@ -230,12 +230,14 @@ export class UserEntityService implements OnModuleInit {
/*
const myAntennas = (await this.antennaService.getAntennas()).filter(a => a.userId === userId);
- const unread = myAntennas.length > 0 ? await this.antennaNotesRepository.findOneBy({
- antennaId: In(myAntennas.map(x => x.id)),
- read: false,
- }) : null;
+ const isUnread = (myAntennas.length > 0 ? await this.antennaNotesRepository.exist({
+ where: {
+ antennaId: In(myAntennas.map(x => x.id)),
+ read: false,
+ },
+ }) : false);
- return unread != null;
+ return isUnread;
*/
return false; // TODO
}