From b423d23cf69601a1e873d4a4f4e0905c86037e54 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 2 Jan 2023 21:07:02 +0100 Subject: [PATCH] server: fix custom lint typeorm-prefer-count --- packages/backend/src/misc/reaction-lib.ts | 2 +- .../src/remote/activitypub/kernel/undo/accept.ts | 2 +- .../src/remote/activitypub/kernel/undo/follow.ts | 8 ++++---- .../backend/src/remote/activitypub/models/note.ts | 2 +- packages/backend/src/server/api/common/signup.ts | 2 +- .../endpoints/admin/federation/update-instance.ts | 4 ++-- .../src/server/api/endpoints/blocking/delete.ts | 4 ++-- .../src/server/api/endpoints/following/delete.ts | 4 ++-- .../server/api/endpoints/following/invalidate.ts | 4 ++-- .../src/server/api/endpoints/i/read-announcement.ts | 4 ++-- .../src/server/api/endpoints/i/revoke-token.ts | 4 ++-- .../src/server/api/endpoints/messaging/messages.ts | 4 ++-- .../api/endpoints/messaging/messages/create.ts | 6 +++--- .../src/server/api/endpoints/notes/create.ts | 8 ++++---- .../src/server/api/endpoints/notes/polls/vote.ts | 6 +++--- .../src/server/api/endpoints/users/followers.ts | 4 ++-- .../src/server/api/endpoints/users/following.ts | 4 ++-- .../src/server/api/endpoints/users/groups/invite.ts | 6 +++--- .../src/server/api/endpoints/users/groups/show.ts | 4 ++-- .../server/api/endpoints/users/groups/transfer.ts | 4 ++-- .../src/server/api/endpoints/users/lists/push.ts | 6 +++--- .../src/server/api/stream/channels/messaging.ts | 4 ++-- .../src/server/api/stream/channels/user-list.ts | 4 ++-- packages/backend/src/services/create-system-user.ts | 2 +- packages/backend/src/services/following/create.ts | 8 ++++---- .../src/services/following/requests/cancel.ts | 6 +++--- packages/backend/src/services/note/create.ts | 8 ++++---- packages/backend/src/services/note/polls/vote.ts | 4 ++-- .../backend/src/services/note/reaction/create.ts | 4 ++-- packages/backend/src/services/note/unread.ts | 13 +++++++------ 30 files changed, 73 insertions(+), 72 deletions(-) diff --git a/packages/backend/src/misc/reaction-lib.ts b/packages/backend/src/misc/reaction-lib.ts index 949ca696a..51be49a67 100644 --- a/packages/backend/src/misc/reaction-lib.ts +++ b/packages/backend/src/misc/reaction-lib.ts @@ -75,7 +75,7 @@ export async function toDbReaction(reaction?: string | null, idnReacterHost?: st const custom = reaction.match(/^:([\w+-]+)(?:@\.)?:$/); if (custom) { const name = custom[1]; - const emoji = await Emojis.findOneBy({ + const emoji = await Emojis.countBy({ host: reacterHost ?? IsNull(), name, }); diff --git a/packages/backend/src/remote/activitypub/kernel/undo/accept.ts b/packages/backend/src/remote/activitypub/kernel/undo/accept.ts index b4664cb4a..9c5174ed6 100644 --- a/packages/backend/src/remote/activitypub/kernel/undo/accept.ts +++ b/packages/backend/src/remote/activitypub/kernel/undo/accept.ts @@ -12,7 +12,7 @@ export default async (actor: CacheableRemoteUser, activity: IAccept): Promise { - const exist = await transactionalEntityManager.findOneBy(User, { + const exist = await transactionalEntityManager.countBy(User, { usernameLower: username.toLowerCase(), host: IsNull(), }); diff --git a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts index a810300b5..93b311579 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts @@ -23,9 +23,9 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, me) => { - const instance = await Instances.findOneBy({ host: toPuny(ps.host) }); + const instanceExists = await Instances.countBy({ host: toPuny(ps.host) }); - if (instance == null) { + if (!instanceExists) { throw new ApiError('NO_SUCH_OBJECT'); } diff --git a/packages/backend/src/server/api/endpoints/blocking/delete.ts b/packages/backend/src/server/api/endpoints/blocking/delete.ts index 5e9ca9368..f2a206280 100644 --- a/packages/backend/src/server/api/endpoints/blocking/delete.ts +++ b/packages/backend/src/server/api/endpoints/blocking/delete.ts @@ -48,12 +48,12 @@ export default define(meta, paramDef, async (ps, user) => { }); // Check not blocking - const exist = await Blockings.findOneBy({ + const exist = await Blockings.countBy({ blockerId: blocker.id, blockeeId: blockee.id, }); - if (exist == null) throw new ApiError('NOT_BLOCKING'); + if (!exist) throw new ApiError('NOT_BLOCKING'); // Delete blocking await deleteBlocking(blocker, blockee); diff --git a/packages/backend/src/server/api/endpoints/following/delete.ts b/packages/backend/src/server/api/endpoints/following/delete.ts index 72c1ce6c6..40fe718cc 100644 --- a/packages/backend/src/server/api/endpoints/following/delete.ts +++ b/packages/backend/src/server/api/endpoints/following/delete.ts @@ -48,12 +48,12 @@ export default define(meta, paramDef, async (ps, user) => { }); // Check not following - const exist = await Followings.findOneBy({ + const exist = await Followings.countBy({ followerId: follower.id, followeeId: followee.id, }); - if (exist == null) throw new ApiError('NOT_FOLLOWING'); + if (!exist) throw new ApiError('NOT_FOLLOWING'); await deleteFollowing(follower, followee); diff --git a/packages/backend/src/server/api/endpoints/following/invalidate.ts b/packages/backend/src/server/api/endpoints/following/invalidate.ts index 437d20ae7..7bb794caa 100644 --- a/packages/backend/src/server/api/endpoints/following/invalidate.ts +++ b/packages/backend/src/server/api/endpoints/following/invalidate.ts @@ -48,12 +48,12 @@ export default define(meta, paramDef, async (ps, user) => { }); // Check not following - const exist = await Followings.findOneBy({ + const exist = await Followings.countBy({ followerId: follower.id, followeeId: followee.id, }); - if (exist == null) throw new ApiError('NOT_FOLLOWING'); + if (!exist) throw new ApiError('NOT_FOLLOWING'); await deleteFollowing(follower, followee); diff --git a/packages/backend/src/server/api/endpoints/i/read-announcement.ts b/packages/backend/src/server/api/endpoints/i/read-announcement.ts index 6d7e8954c..433cb79b5 100644 --- a/packages/backend/src/server/api/endpoints/i/read-announcement.ts +++ b/packages/backend/src/server/api/endpoints/i/read-announcement.ts @@ -25,9 +25,9 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, user) => { // Check if announcement exists - const announcement = await Announcements.findOneBy({ id: ps.announcementId }); + const exists = await Announcements.countBy({ id: ps.announcementId }); - if (announcement == null) throw new ApiError('NO_SUCH_ANNOUNCEMENT'); + if (!exists) throw new ApiError('NO_SUCH_ANNOUNCEMENT'); // Check if already read const read = await AnnouncementReads.findOneBy({ diff --git a/packages/backend/src/server/api/endpoints/i/revoke-token.ts b/packages/backend/src/server/api/endpoints/i/revoke-token.ts index 26c20cba9..ef85051f8 100644 --- a/packages/backend/src/server/api/endpoints/i/revoke-token.ts +++ b/packages/backend/src/server/api/endpoints/i/revoke-token.ts @@ -18,9 +18,9 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, user) => { - const token = await AccessTokens.findOneBy({ id: ps.tokenId }); + const exists = await AccessTokens.countBy({ id: ps.tokenId }); - if (token) { + if (exists) { await AccessTokens.delete({ id: ps.tokenId, userId: user.id, diff --git a/packages/backend/src/server/api/endpoints/messaging/messages.ts b/packages/backend/src/server/api/endpoints/messaging/messages.ts index 88e17a054..b9fea1259 100644 --- a/packages/backend/src/server/api/endpoints/messaging/messages.ts +++ b/packages/backend/src/server/api/endpoints/messaging/messages.ts @@ -95,12 +95,12 @@ export default define(meta, paramDef, async (ps, user) => { if (recipientGroup == null) throw new ApiError('NO_SUCH_GROUP'); // check joined - const joining = await UserGroupJoinings.findOneBy({ + const joined = await UserGroupJoinings.countBy({ userId: user.id, userGroupId: recipientGroup.id, }); - if (joining == null) throw new ApiError('ACCESS_DENIED', 'You have to join a group to read messages in it.'); + if (!joined) throw new ApiError('ACCESS_DENIED', 'You have to join a group to read messages in it.'); const query = makePaginationQuery(MessagingMessages.createQueryBuilder('message'), ps.sinceId, ps.untilId) .andWhere('message.groupId = :groupId', { groupId: recipientGroup.id }); diff --git a/packages/backend/src/server/api/endpoints/messaging/messages/create.ts b/packages/backend/src/server/api/endpoints/messaging/messages/create.ts index 020d596fc..cbca715c0 100644 --- a/packages/backend/src/server/api/endpoints/messaging/messages/create.ts +++ b/packages/backend/src/server/api/endpoints/messaging/messages/create.ts @@ -106,7 +106,7 @@ export default define(meta, paramDef, async (ps, user) => { }); // Check blocking - const block = await Blockings.findOneBy({ + const block = await Blockings.countBy({ blockerId: recipientUser.id, blockeeId: user.id, }); @@ -118,12 +118,12 @@ export default define(meta, paramDef, async (ps, user) => { if (recipientGroup == null) throw new ApiError('NO_SUCH_GROUP'); // check joined - const joining = await UserGroupJoinings.findOneBy({ + const joined = await UserGroupJoinings.countBy({ userId: user.id, userGroupId: recipientGroup.id, }); - if (joining == null) throw new ApiError('ACCESS_DENIED', 'You have to join a group to send a message in it.'); + if (!joined) throw new ApiError('ACCESS_DENIED', 'You have to join a group to send a message in it.'); } let file = null; diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts index 18eec6b89..1b272e9dc 100644 --- a/packages/backend/src/server/api/endpoints/notes/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/create.ts @@ -169,11 +169,11 @@ export default define(meta, paramDef, async (ps, user) => { // Check blocking if (renote.userId !== user.id) { - const block = await Blockings.findOneBy({ + const blocked = await Blockings.countBy({ blockerId: renote.userId, blockeeId: user.id, }); - if (block) throw new ApiError('BLOCKED', 'Blocked by author of note to be renoted.'); + if (blocked) throw new ApiError('BLOCKED', 'Blocked by author of note to be renoted.'); } } @@ -194,11 +194,11 @@ export default define(meta, paramDef, async (ps, user) => { // Check blocking if (reply.userId !== user.id) { - const block = await Blockings.findOneBy({ + const blocked = await Blockings.countBy({ blockerId: reply.userId, blockeeId: user.id, }); - if (block) throw new ApiError('BLOCKED', 'Blocked by author of replied to note.'); + if (blocked) throw new ApiError('BLOCKED', 'Blocked by author of replied to note.'); } } diff --git a/packages/backend/src/server/api/endpoints/notes/polls/vote.ts b/packages/backend/src/server/api/endpoints/notes/polls/vote.ts index 6648e996b..4ffdcc4c4 100644 --- a/packages/backend/src/server/api/endpoints/notes/polls/vote.ts +++ b/packages/backend/src/server/api/endpoints/notes/polls/vote.ts @@ -47,11 +47,11 @@ export default define(meta, paramDef, async (ps, user) => { // Check blocking if (note.userId !== user.id) { - const block = await Blockings.findOneBy({ + const blocked = await Blockings.countBy({ blockerId: note.userId, blockeeId: user.id, }); - if (block) throw new ApiError('BLOCKED'); + if (blocked) throw new ApiError('BLOCKED'); } const poll = await Polls.findOneByOrFail({ noteId: note.id }); @@ -99,7 +99,7 @@ export default define(meta, paramDef, async (ps, user) => { }); // check if this thread and notification type is muted - const threadMuted = await NoteThreadMutings.findOneBy({ + const threadMuted = await NoteThreadMutings.countBy({ userId: note.userId, threadId: note.threadId || note.id, mutingNotificationTypes: ArrayOverlap(['pollVote']), diff --git a/packages/backend/src/server/api/endpoints/users/followers.ts b/packages/backend/src/server/api/endpoints/users/followers.ts index e395c3f79..15ecf42fe 100644 --- a/packages/backend/src/server/api/endpoints/users/followers.ts +++ b/packages/backend/src/server/api/endpoints/users/followers.ts @@ -71,11 +71,11 @@ export default define(meta, paramDef, async (ps, me) => { if (me == null) { throw new ApiError('ACCESS_DENIED'); } else if (me.id !== user.id) { - const following = await Followings.findOneBy({ + const following = await Followings.countBy({ followeeId: user.id, followerId: me.id, }); - if (following == null) { + if (!following) { throw new ApiError('ACCESS_DENIED'); } } diff --git a/packages/backend/src/server/api/endpoints/users/following.ts b/packages/backend/src/server/api/endpoints/users/following.ts index 51ad75a77..85dccccb7 100644 --- a/packages/backend/src/server/api/endpoints/users/following.ts +++ b/packages/backend/src/server/api/endpoints/users/following.ts @@ -71,11 +71,11 @@ export default define(meta, paramDef, async (ps, me) => { if (me == null) { throw new ApiError('ACCESS_DENIED'); } else if (me.id !== user.id) { - const following = await Followings.findOneBy({ + const following = await Followings.countBy({ followeeId: user.id, followerId: me.id, }); - if (following == null) { + if (!following) { throw new ApiError('ACCESS_DENIED'); } } diff --git a/packages/backend/src/server/api/endpoints/users/groups/invite.ts b/packages/backend/src/server/api/endpoints/users/groups/invite.ts index 7a792a49b..e8214e815 100644 --- a/packages/backend/src/server/api/endpoints/users/groups/invite.ts +++ b/packages/backend/src/server/api/endpoints/users/groups/invite.ts @@ -43,14 +43,14 @@ export default define(meta, paramDef, async (ps, me) => { throw e; }); - const joining = await UserGroupJoinings.findOneBy({ + const joined = await UserGroupJoinings.countBy({ userGroupId: userGroup.id, userId: user.id, }); - if (joining) throw new ApiError('ALREADY_ADDED'); + if (joined) throw new ApiError('ALREADY_ADDED'); - const existInvitation = await UserGroupInvitations.findOneBy({ + const existInvitation = await UserGroupInvitations.countBy({ userGroupId: userGroup.id, userId: user.id, }); diff --git a/packages/backend/src/server/api/endpoints/users/groups/show.ts b/packages/backend/src/server/api/endpoints/users/groups/show.ts index eddd933c2..2aa5abb5b 100644 --- a/packages/backend/src/server/api/endpoints/users/groups/show.ts +++ b/packages/backend/src/server/api/endpoints/users/groups/show.ts @@ -37,12 +37,12 @@ export default define(meta, paramDef, async (ps, me) => { if (userGroup == null) throw new ApiError('NO_SUCH_GROUP'); - const joining = await UserGroupJoinings.findOneBy({ + const joined = await UserGroupJoinings.countBy({ userId: me.id, userGroupId: userGroup.id, }); - if (joining == null && userGroup.userId !== me.id) { + if (!joined && userGroup.userId !== me.id) { throw new ApiError('NO_SUCH_GROUP'); } diff --git a/packages/backend/src/server/api/endpoints/users/groups/transfer.ts b/packages/backend/src/server/api/endpoints/users/groups/transfer.ts index b6607e4f8..b9020fbcc 100644 --- a/packages/backend/src/server/api/endpoints/users/groups/transfer.ts +++ b/packages/backend/src/server/api/endpoints/users/groups/transfer.ts @@ -46,12 +46,12 @@ export default define(meta, paramDef, async (ps, me) => { throw e; }); - const joining = await UserGroupJoinings.findOneBy({ + const joined = await UserGroupJoinings.countBy({ userGroupId: userGroup.id, userId: user.id, }); - if (joining == null) throw new ApiError('NO_SUCH_USER', 'The user exists but is not a member of the group.'); + if (!joined) throw new ApiError('NO_SUCH_USER', 'The user exists but is not a member of the group.'); await UserGroups.update(userGroup.id, { userId: ps.userId, diff --git a/packages/backend/src/server/api/endpoints/users/lists/push.ts b/packages/backend/src/server/api/endpoints/users/lists/push.ts index 7552f3331..86f7aee9a 100644 --- a/packages/backend/src/server/api/endpoints/users/lists/push.ts +++ b/packages/backend/src/server/api/endpoints/users/lists/push.ts @@ -43,14 +43,14 @@ export default define(meta, paramDef, async (ps, me) => { // Check blocking if (user.id !== me.id) { - const block = await Blockings.findOneBy({ + const blocked = await Blockings.countBy({ blockerId: user.id, blockeeId: me.id, }); - if (block) throw new ApiError('BLOCKED'); + if (blocked) throw new ApiError('BLOCKED'); } - const exist = await UserListJoinings.findOneBy({ + const exist = await UserListJoinings.countBy({ userListId: userList.id, userId: user.id, }); diff --git a/packages/backend/src/server/api/stream/channels/messaging.ts b/packages/backend/src/server/api/stream/channels/messaging.ts index ef3ac2ab8..4f9f6a9c4 100644 --- a/packages/backend/src/server/api/stream/channels/messaging.ts +++ b/packages/backend/src/server/api/stream/channels/messaging.ts @@ -31,12 +31,12 @@ export default class extends Channel { // Check joining if (this.groupId) { - const joining = await UserGroupJoinings.findOneBy({ + const joined = await UserGroupJoinings.countBy({ userId: this.user!.id, userGroupId: this.groupId, }); - if (joining == null) { + if (!joined) { return; } } diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts index 39ee53c2b..0c1a66a5b 100644 --- a/packages/backend/src/server/api/stream/channels/user-list.ts +++ b/packages/backend/src/server/api/stream/channels/user-list.ts @@ -24,11 +24,11 @@ export default class extends Channel { this.listId = params.listId as string; // Check existence and owner - const list = await UserLists.findOneBy({ + const exists = await UserLists.countBy({ id: this.listId, userId: this.user!.id, }); - if (!list) return; + if (!exists) return; // Subscribe stream this.subscriber.on(`userListStream:${this.listId}`, this.send); diff --git a/packages/backend/src/services/create-system-user.ts b/packages/backend/src/services/create-system-user.ts index f965e82d7..8e39b00fb 100644 --- a/packages/backend/src/services/create-system-user.ts +++ b/packages/backend/src/services/create-system-user.ts @@ -22,7 +22,7 @@ export async function createSystemUser(username: string): Promise { // Start transaction await db.transaction(async transactionalEntityManager => { - const exist = await transactionalEntityManager.findOneBy(User, { + const exist = await transactionalEntityManager.countBy(User, { usernameLower: username.toLowerCase(), host: IsNull(), }); diff --git a/packages/backend/src/services/following/create.ts b/packages/backend/src/services/following/create.ts index a4f546266..f588379f8 100644 --- a/packages/backend/src/services/following/create.ts +++ b/packages/backend/src/services/following/create.ts @@ -46,12 +46,12 @@ export async function insertFollowingDoc(followee: { id: User['id']; host: User[ } }); - const req = await FollowRequests.findOneBy({ + const requested = await FollowRequests.countBy({ followeeId: followee.id, followerId: follower.id, }); - if (req) { + if (requested) { await FollowRequests.delete({ followeeId: followee.id, followerId: follower.id, @@ -167,7 +167,7 @@ export default async function(_follower: { id: User['id'] }, _followee: { id: Us let autoAccept = false; // 鍵アカウントであっても、既にフォローされていた場合はスルー - const following = await Followings.findOneBy({ + const following = await Followings.countBy({ followerId: follower.id, followeeId: followee.id, }); @@ -177,7 +177,7 @@ export default async function(_follower: { id: User['id'] }, _followee: { id: Us // フォローしているユーザーは自動承認オプション if (!autoAccept && (Users.isLocalUser(followee) && followeeProfile.autoAcceptFollowed)) { - const followed = await Followings.findOneBy({ + const followed = await Followings.countBy({ followerId: followee.id, followeeId: follower.id, }); diff --git a/packages/backend/src/services/following/requests/cancel.ts b/packages/backend/src/services/following/requests/cancel.ts index 999ebc64e..4ceac19cb 100644 --- a/packages/backend/src/services/following/requests/cancel.ts +++ b/packages/backend/src/services/following/requests/cancel.ts @@ -16,17 +16,17 @@ export async function cancelFollowRequest(followee: User, follower: User): Promi if (Users.isRemoteUser(followee)) { const content = renderActivity(renderUndo(renderFollow(follower, followee), follower)); - if (Users.isLocalUser(follower)) { // 本来このチェックは不要だけどTSに怒られるので + if (Users.isLocalUser(follower)) { deliver(follower, content, followee.inbox); } } - const request = await FollowRequests.findOneBy({ + const requested = await FollowRequests.countBy({ followeeId: followee.id, followerId: follower.id, }); - if (request == null) { + if (!requested) { throw new IdentifiableError('17447091-ce07-46dd-b331-c1fd4f15b1e7', 'request not found'); } diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 7ef25a620..aceb142b0 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -91,12 +91,12 @@ class NotificationManager { public async deliver(): Promise { for (const x of this.queue) { // check if the sender or thread are muted - const userMuted = await Mutings.findOneBy({ + const userMuted = await Mutings.countBy({ muterId: x.target, muteeId: this.notifier.id, }); - const threadMuted = await NoteThreadMutings.findOneBy({ + const threadMuted = await NoteThreadMutings.countBy({ userId: x.target, threadId: In([ // replies @@ -376,7 +376,7 @@ export default async (user: { id: User['id']; username: User['username']; host: // 通知 if (data.reply.userHost === null) { - const threadMuted = await NoteThreadMutings.findOneBy({ + const threadMuted = await NoteThreadMutings.countBy({ userId: data.reply.userId, threadId: data.reply.threadId || data.reply.id, }); @@ -623,7 +623,7 @@ async function notifyToWatchersOfReplyee(reply: Note, user: { id: User['id']; }, async function createMentionedEvents(mentionedUsers: MinimumUser[], note: Note, nm: NotificationManager): Promise { for (const u of mentionedUsers.filter(u => Users.isLocalUser(u))) { - const threadMuted = await NoteThreadMutings.findOneBy({ + const threadMuted = await NoteThreadMutings.countBy({ userId: u.id, threadId: note.threadId || note.id, }); diff --git a/packages/backend/src/services/note/polls/vote.ts b/packages/backend/src/services/note/polls/vote.ts index 6e22af41f..b86e7107d 100644 --- a/packages/backend/src/services/note/polls/vote.ts +++ b/packages/backend/src/services/note/polls/vote.ts @@ -16,7 +16,7 @@ export async function vote(user: CacheableUser, note: Note, choice: number): Pro // Check blocking if (note.userId !== user.id) { - const block = await Blockings.findOneBy({ + const block = await Blockings.countBy({ blockerId: note.userId, blockeeId: user.id, }); @@ -58,7 +58,7 @@ export async function vote(user: CacheableUser, note: Note, choice: number): Pro }); // check if this thread and notification type is muted - const muted = await NoteThreadMutings.findOneBy({ + const muted = await NoteThreadMutings.countBy({ userId: note.userId, threadId: note.threadId || note.id, mutingNotificationTypes: ArrayOverlap(['pollVote']), diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index d6e128137..d50761a29 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -18,7 +18,7 @@ import { deleteReaction } from './delete.js'; export async function createReaction(user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string): Promise { // Check blocking if (note.userId !== user.id) { - const block = await Blockings.findOneBy({ + const block = await Blockings.countBy({ blockerId: note.userId, blockeeId: user.id, }); @@ -99,7 +99,7 @@ export async function createReaction(user: { id: User['id']; host: User['host']; }); // check if this thread is muted - const threadMuted = await NoteThreadMutings.findOneBy({ + const threadMuted = await NoteThreadMutings.countBy({ userId: note.userId, threadId: note.threadId || note.id, mutingNotificationTypes: ArrayOverlap(['reaction']), diff --git a/packages/backend/src/services/note/unread.ts b/packages/backend/src/services/note/unread.ts index 829a024ee..dcd1056e3 100644 --- a/packages/backend/src/services/note/unread.ts +++ b/packages/backend/src/services/note/unread.ts @@ -11,18 +11,19 @@ export async function insertNoteUnread(userId: User['id'], note: Note, params: { }): Promise { //#region ミュートしているなら無視 // TODO: 現在の仕様ではChannelにミュートは適用されないのでよしなにケアする - const mute = await Mutings.findBy({ + const muted = await Mutings.countBy({ muterId: userId, + muteeId: note.userId, }); - if (mute.map(m => m.muteeId).includes(note.userId)) return; + if (muted) return; //#endregion + const threadMuted = await NoteThreadMutings.countBy({ // スレッドミュート - const threadMute = await NoteThreadMutings.findOneBy({ userId, threadId: note.threadId || note.id, }); - if (threadMute) return; + if (threadMuted) return; const unread = { id: genId(), @@ -38,9 +39,9 @@ export async function insertNoteUnread(userId: User['id'], note: Note, params: { // 2秒経っても既読にならなかったら「未読の投稿がありますよ」イベントを発行する setTimeout(async () => { - const exist = await NoteUnreads.findOneBy({ id: unread.id }); + const exist = await NoteUnreads.countBy({ id: unread.id }); - if (exist == null) return; + if (!exist) return; if (params.isMentioned) { publishMainStream(userId, 'unreadMention', note.id);