From e7fcca0e064e04a6a403453666f0eefcdb3c2125 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 9 Sep 2019 22:28:41 +0900 Subject: [PATCH] Fix #5403 --- src/models/repositories/user.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/models/repositories/user.ts b/src/models/repositories/user.ts index a5fad9647..5c8cbb3d1 100644 --- a/src/models/repositories/user.ts +++ b/src/models/repositories/user.ts @@ -1,5 +1,5 @@ import $ from 'cafy'; -import { EntityRepository, Repository, In } from 'typeorm'; +import { EntityRepository, Repository, In, Not } from 'typeorm'; import { User, ILocalUser, IRemoteUser } from '../entities/user'; import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages } from '..'; import { ensure } from '../../prelude/ensure'; @@ -56,6 +56,10 @@ export class UserRepository extends Repository { } public async getHasUnreadMessagingMessage(userId: User['id']): Promise { + const mute = await Mutings.find({ + muterId: userId + }); + const joinings = await UserGroupJoinings.find({ userId: userId }); const groupQs = Promise.all(joinings.map(j => MessagingMessages.createQueryBuilder('message') @@ -66,11 +70,11 @@ export class UserRepository extends Repository { .getOne().then(x => x != null))); const [withUser, withGroups] = await Promise.all([ - // TODO: ミュートを考慮 MessagingMessages.count({ where: { recipientId: userId, - isRead: false + isRead: false, + ...(mute.length > 0 ? { userId: Not(In(mute.map(x => x.muteeId))) } : {}), }, take: 1 }).then(count => count > 0),