From 43eb8bd99b09532b76de30b257bf02f47525fe69 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 28 May 2018 21:59:57 +0900 Subject: [PATCH] =?UTF-8?q?notes/local-timeline=20=E3=81=A8=20notes/global?= =?UTF-8?q?-timeline=20=E3=81=AE=E3=82=B5=E3=82=A4=E3=83=B3=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=92=E4=B8=8D=E8=A6=81=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/endpoints.ts | 2 -- .../api/endpoints/notes/global-timeline.ts | 32 +++++++++++-------- .../api/endpoints/notes/local-timeline.ts | 31 ++++++++++-------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts index 908d9574a..c1ac4777b 100644 --- a/src/server/api/endpoints.ts +++ b/src/server/api/endpoints.ts @@ -515,7 +515,6 @@ const endpoints: Endpoint[] = [ }, { name: 'notes/local-timeline', - withCredential: true, limit: { duration: ms('10minutes'), max: 100 @@ -523,7 +522,6 @@ const endpoints: Endpoint[] = [ }, { name: 'notes/global-timeline', - withCredential: true, limit: { duration: ms('10minutes'), max: 100 diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts index d22a1763d..7cf06c3af 100644 --- a/src/server/api/endpoints/notes/global-timeline.ts +++ b/src/server/api/endpoints/notes/global-timeline.ts @@ -9,7 +9,7 @@ import { pack } from '../../../../models/note'; /** * Get timeline of global */ -module.exports = async (params, user, app) => { +module.exports = async (params, user) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; @@ -36,9 +36,9 @@ module.exports = async (params, user, app) => { } // ミュートしているユーザーを取得 - const mutedUserIds = (await Mute.find({ + const mutedUserIds = user ? (await Mute.find({ muterId: user._id - })).map(m => m.muteeId); + })).map(m => m.muteeId) : null; //#region Construct query const sort = { @@ -46,18 +46,24 @@ module.exports = async (params, user, app) => { }; const query = { - // mute - userId: { - $nin: mutedUserIds - }, - '_reply.userId': { - $nin: mutedUserIds - }, - '_renote.userId': { - $nin: mutedUserIds - } + // public only + visibility: 'public' } as any; + if (mutedUserIds && mutedUserIds.length > 0) { + query.userId = { + $nin: mutedUserIds + }; + + query['_reply.userId'] = { + $nin: mutedUserIds + }; + + query['_renote.userId'] = { + $nin: mutedUserIds + }; + } + if (sinceId) { sort._id = 1; query._id = { diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts index 64118e1f1..7d01de3d4 100644 --- a/src/server/api/endpoints/notes/local-timeline.ts +++ b/src/server/api/endpoints/notes/local-timeline.ts @@ -9,7 +9,7 @@ import { pack } from '../../../../models/note'; /** * Get timeline of local */ -module.exports = async (params, user, app) => { +module.exports = async (params, user) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; @@ -36,9 +36,9 @@ module.exports = async (params, user, app) => { } // ミュートしているユーザーを取得 - const mutedUserIds = (await Mute.find({ + const mutedUserIds = user ? (await Mute.find({ muterId: user._id - })).map(m => m.muteeId); + })).map(m => m.muteeId) : null; //#region Construct query const sort = { @@ -46,17 +46,6 @@ module.exports = async (params, user, app) => { }; const query = { - // mute - userId: { - $nin: mutedUserIds - }, - '_reply.userId': { - $nin: mutedUserIds - }, - '_renote.userId': { - $nin: mutedUserIds - }, - // public only visibility: 'public', @@ -64,6 +53,20 @@ module.exports = async (params, user, app) => { '_user.host': null } as any; + if (mutedUserIds && mutedUserIds.length > 0) { + query.userId = { + $nin: mutedUserIds + }; + + query['_reply.userId'] = { + $nin: mutedUserIds + }; + + query['_renote.userId'] = { + $nin: mutedUserIds + }; + } + if (sinceId) { sort._id = 1; query._id = {