diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-09-05 16:25:30 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-09-05 16:25:30 +0900 |
| commit | 1cd8bfadeddaa409f169f320a04065e4705a1152 (patch) | |
| tree | 83530a441394e702f247620200ddf4a81a2db91b /src/models | |
| parent | fix Dockerfile (#7763) (diff) | |
| download | sharkey-1cd8bfadeddaa409f169f320a04065e4705a1152.tar.gz sharkey-1cd8bfadeddaa409f169f320a04065e4705a1152.tar.bz2 sharkey-1cd8bfadeddaa409f169f320a04065e4705a1152.zip | |
fix(server): ノート翻訳時に公開範囲が考慮されていない問題を修正
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/repositories/note.ts | 50 |
1 files changed, 50 insertions, 0 deletions
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<Note> { return x.trim().length <= 100; } + public async isVisibleForMe(note: Note, meId: User['id'] | null): Promise<boolean> { + // 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 かつ自分が指定されていなかったら非表示 |