From cd4680b422f1740ce212ff50925632b0d55db398 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 23 Mar 2021 15:12:47 +0900 Subject: [PATCH] fix --- src/server/api/endpoints/notes/mentions.ts | 2 +- src/services/note/read.ts | 23 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/server/api/endpoints/notes/mentions.ts b/src/server/api/endpoints/notes/mentions.ts index 30368ea578..32e71acc05 100644 --- a/src/server/api/endpoints/notes/mentions.ts +++ b/src/server/api/endpoints/notes/mentions.ts @@ -83,7 +83,7 @@ export default define(meta, async (ps, user) => { const mentions = await query.take(ps.limit!).getMany(); - read(user.id, mentions.map(note => note.id)); + read(user.id, mentions); return await Notes.packMany(mentions, user); }); diff --git a/src/services/note/read.ts b/src/services/note/read.ts index 91b523bd1d..4e8c76cbee 100644 --- a/src/services/note/read.ts +++ b/src/services/note/read.ts @@ -1,7 +1,7 @@ import { publishMainStream } from '../stream'; import { Note } from '../../models/entities/note'; import { User } from '../../models/entities/user'; -import { NoteUnreads, AntennaNotes, Users } from '../../models'; +import { NoteUnreads, AntennaNotes, Users, Followings, ChannelFollowings } from '../../models'; import { Not, IsNull, In } from 'typeorm'; import { Channel } from '../../models/entities/channel'; import { checkHitAntenna } from '../../misc/check-hit-antenna'; @@ -14,11 +14,24 @@ import { PackedNote } from '../../models/repositories/note'; export default async function( userId: User['id'], notes: (Note | PackedNote)[], - info: { - following: Set; + info?: { + following: Set; followingChannels: Set; } ) { + const following = info?.following ? info.following : new Set((await Followings.find({ + where: { + followerId: userId + }, + select: ['followeeId'] + })).map(x => x.followeeId)); + const followingChannels = info?.followingChannels ? info.followingChannels : new Set((await ChannelFollowings.find({ + where: { + followerId: userId + }, + select: ['followeeId'] + })).map(x => x.followeeId)); + const myAntennas = (await getAntennas()).filter(a => a.userId === userId); const readMentions: (Note | PackedNote)[] = []; const readSpecifiedNotes: (Note | PackedNote)[] = []; @@ -32,13 +45,13 @@ export default async function( readSpecifiedNotes.push(note); } - if (note.channelId && info.followingChannels.has(note.channelId)) { + if (note.channelId && followingChannels.has(note.channelId)) { readChannelNotes.push(note); } if (note.user != null) { // たぶんnullになることは無いはずだけど一応 for (const antenna of myAntennas) { - if (checkHitAntenna(antenna, note, note.user as any, undefined, Array.from(info.following))) { + if (checkHitAntenna(antenna, note, note.user as any, undefined, Array.from(following))) { readAntennaNotes.push(note); } }