From 1cd8bfadeddaa409f169f320a04065e4705a1152 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 5 Sep 2021 16:25:30 +0900 Subject: [PATCH] =?UTF-8?q?fix(server):=20=E3=83=8E=E3=83=BC=E3=83=88?= =?UTF-8?q?=E7=BF=BB=E8=A8=B3=E6=99=82=E3=81=AB=E5=85=AC=E9=96=8B=E7=AF=84?= =?UTF-8?q?=E5=9B=B2=E3=81=8C=E8=80=83=E6=85=AE=E3=81=95=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 +++ src/models/repositories/note.ts | 50 +++++++++++++++++++++ src/server/api/endpoints/notes/translate.ts | 5 +++ 3 files changed, 61 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2454a3b609..c14fb48177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ --> +## 12.x.x (unreleased) + +### Bugfixes +- Dockerfileを修正 +- ノート翻訳時に公開範囲が考慮されていない問題を修正 + ## 12.90.0 (2021/09/04) ### Improvements diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index a8e356abf2..9e0f5e55f0 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -18,7 +18,57 @@ export class NoteRepository extends Repository { return x.trim().length <= 100; } + public async isVisibleForMe(note: Note, meId: User['id'] | null): Promise { + // visibility が specified かつ自分が指定されていなかったら非表示 + if (note.visibility === 'specified') { + if (meId == null) { + return false; + } else if (meId === note.userId) { + return true; + } else { + // 指定されているかどうか + const specified = note.visibleUserIds.some((id: any) => meId === id); + + if (specified) { + return true; + } else { + return false; + } + } + } + + // visibility が followers かつ自分が投稿者のフォロワーでなかったら非表示 + if (note.visibility === 'followers') { + if (meId == null) { + return false; + } else if (meId === note.userId) { + return true; + } else if (note.reply && (meId === note.reply.userId)) { + // 自分の投稿に対するリプライ + return true; + } else if (note.mentions && note.mentions.some(id => meId === id)) { + // 自分へのメンション + return true; + } else { + // フォロワーかどうか + const following = await Followings.findOne({ + followeeId: note.userId, + followerId: meId + }); + + if (following == null) { + return false; + } else { + return true; + } + } + } + + return true; + } + private async hideNote(packedNote: PackedNote, meId: User['id'] | null) { + // TODO: isVisibleForMe を使うようにしても良さそう(型違うけど) let hide = false; // visibility が specified かつ自分が指定されていなかったら非表示 diff --git a/src/server/api/endpoints/notes/translate.ts b/src/server/api/endpoints/notes/translate.ts index e4bc6bb060..b56b1debdd 100644 --- a/src/server/api/endpoints/notes/translate.ts +++ b/src/server/api/endpoints/notes/translate.ts @@ -8,6 +8,7 @@ import config from '@/config/index'; import { getAgentByUrl } from '@/misc/fetch'; import { URLSearchParams } from 'url'; import { fetchMeta } from '@/misc/fetch-meta'; +import { Notes } from '@/models'; export const meta = { tags: ['notes'], @@ -43,6 +44,10 @@ export default define(meta, async (ps, user) => { throw e; }); + if (!(await Notes.isVisibleForMe(note, user ? user.id : null))) { + return 204; // TODO: 良い感じのエラー返す + } + if (note.text == null) { return 204; }