From ab6a84cd45a266e97feee6a268495db8c161ce88 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 27 Aug 2019 03:24:35 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E5=AE=9F=E8=A3=85=E3=81=AETL=E3=81=AE?= =?UTF-8?q?Renote=E3=82=AF=E3=82=A8=E3=83=AA=E3=82=92=E5=AE=9F=E8=A3=85=20?= =?UTF-8?q?(#5343)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * users/notes includeMyRenotes * other renotes * fix target user in users/notes * users/notesからv10から未実装でありえないオプションを削除 * users/notesのincludeMyRenotesの説明を修正 * remove needless anonymous checks --- .../api/endpoints/notes/hybrid-timeline.ts | 66 ++++++------------ src/server/api/endpoints/notes/timeline.ts | 67 ++++++------------ .../api/endpoints/notes/user-list-timeline.ts | 68 +++++++------------ src/server/api/endpoints/users/notes.ts | 40 +++-------- 4 files changed, 74 insertions(+), 167 deletions(-) diff --git a/src/server/api/endpoints/notes/hybrid-timeline.ts b/src/server/api/endpoints/notes/hybrid-timeline.ts index 8c4c7a60b..4d0ac2fed 100644 --- a/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -130,59 +130,35 @@ export default define(meta, async (ps, user) => { generateVisibilityQuery(query, user); generateMuteQuery(query, user); - /* TODO - // MongoDBではトップレベルで否定ができないため、De Morganの法則を利用してクエリします。 - // つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。 - // for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws - if (ps.includeMyRenotes === false) { - query.$and.push({ - $or: [{ - userId: { $ne: user.id } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.userId != :meId', { meId: user.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } if (ps.includeRenotedMyNotes === false) { - query.$and.push({ - $or: [{ - '_renote.userId': { $ne: user.id } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserId != :meId', { meId: user.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } if (ps.includeLocalRenotes === false) { - query.$and.push({ - $or: [{ - '_renote.user.host': { $ne: null } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserHost IS NOT NULL'); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } - */ if (ps.withFiles) { query.andWhere('note.fileIds != \'{}\''); diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts index 25876f655..b2fb250c5 100644 --- a/src/server/api/endpoints/notes/timeline.ts +++ b/src/server/api/endpoints/notes/timeline.ts @@ -116,58 +116,35 @@ export default define(meta, async (ps, user) => { generateVisibilityQuery(query, user); generateMuteQuery(query, user); - /* v11 TODO - // MongoDBではトップレベルで否定ができないため、De Morganの法則を利用してクエリします。 - // つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。 - // for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws - if (ps.includeMyRenotes === false) { - query.$and.push({ - $or: [{ - userId: { $ne: user.id } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.userId != :meId', { meId: user.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } if (ps.includeRenotedMyNotes === false) { - query.$and.push({ - $or: [{ - '_renote.userId': { $ne: user.id } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserId != :meId', { meId: user.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } if (ps.includeLocalRenotes === false) { - query.$and.push({ - $or: [{ - '_renote.user.host': { $ne: null } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); - }*/ + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserHost IS NOT NULL'); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); + } if (ps.withFiles) { query.andWhere('note.fileIds != \'{}\''); diff --git a/src/server/api/endpoints/notes/user-list-timeline.ts b/src/server/api/endpoints/notes/user-list-timeline.ts index f66221537..1e669b9d8 100644 --- a/src/server/api/endpoints/notes/user-list-timeline.ts +++ b/src/server/api/endpoints/notes/user-list-timeline.ts @@ -6,6 +6,7 @@ import { UserLists, UserListJoinings, Notes } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; import { generateVisibilityQuery } from '../../common/generate-visibility-query'; import { activeUsersChart } from '../../../../services/chart'; +import { Brackets } from 'typeorm'; export const meta = { desc: { @@ -134,58 +135,35 @@ export default define(meta, async (ps, user) => { generateVisibilityQuery(query, user); - /* TODO - // MongoDBではトップレベルで否定ができないため、De Morganの法則を利用してクエリします。 - // つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。 - // for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws - if (ps.includeMyRenotes === false) { - query.$and.push({ - $or: [{ - userId: { $ne: user.id } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.userId != :meId', { meId: user.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } if (ps.includeRenotedMyNotes === false) { - query.$and.push({ - $or: [{ - '_renote.userId': { $ne: user.id } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserId != :meId', { meId: user.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } if (ps.includeLocalRenotes === false) { - query.$and.push({ - $or: [{ - '_renote.user.host': { $ne: null } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); - }*/ + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserHost IS NOT NULL'); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); + } if (ps.withFiles) { query.andWhere('note.fileIds != \'{}\''); diff --git a/src/server/api/endpoints/users/notes.ts b/src/server/api/endpoints/users/notes.ts index ef564b3c3..c8be19ff1 100644 --- a/src/server/api/endpoints/users/notes.ts +++ b/src/server/api/endpoints/users/notes.ts @@ -74,23 +74,7 @@ export const meta = { validator: $.optional.bool, default: true, desc: { - 'ja-JP': '自分の行ったRenoteを含めるかどうか' - } - }, - - includeRenotedMyNotes: { - validator: $.optional.bool, - default: true, - desc: { - 'ja-JP': 'Renoteされた自分の投稿を含めるかどうか' - } - }, - - includeLocalRenotes: { - validator: $.optional.bool, - default: true, - desc: { - 'ja-JP': 'Renoteされたローカルの投稿を含めるかどうか' + 'ja-JP': 'Renoteを含めるかどうか' } }, @@ -177,23 +161,15 @@ export default define(meta, async (ps, me) => { query.andWhere('note.replyId IS NULL'); } - /* TODO if (ps.includeMyRenotes === false) { - query.$and.push({ - $or: [{ - userId: { $ne: user.id } - }, { - renoteId: null - }, { - text: { $ne: null } - }, { - fileIds: { $ne: [] } - }, { - poll: { $ne: null } - }] - }); + query.andWhere(new Brackets(qb => { + qb.orWhere('note.userId != :userId', { userId: user.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } - */ //#endregion