From a8adc46f3ba42e86c64a64f2633f5796aeca01f4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 28 Jul 2020 09:36:43 +0900 Subject: refactor: Rename function --- src/misc/is-muted-user-related.ts | 15 +++++++++++++++ src/misc/should-mute-this-note.ts | 15 --------------- src/server/api/stream/channels/antenna.ts | 4 ++-- src/server/api/stream/channels/global-timeline.ts | 4 ++-- src/server/api/stream/channels/hashtag.ts | 4 ++-- src/server/api/stream/channels/home-timeline.ts | 4 ++-- src/server/api/stream/channels/hybrid-timeline.ts | 4 ++-- src/server/api/stream/channels/local-timeline.ts | 4 ++-- src/server/api/stream/channels/user-list.ts | 4 ++-- src/services/add-note-to-antenna.ts | 4 ++-- 10 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 src/misc/is-muted-user-related.ts delete mode 100644 src/misc/should-mute-this-note.ts diff --git a/src/misc/is-muted-user-related.ts b/src/misc/is-muted-user-related.ts new file mode 100644 index 0000000000..6f074bcb90 --- /dev/null +++ b/src/misc/is-muted-user-related.ts @@ -0,0 +1,15 @@ +export function isMutedUserRelated(note: any, mutedUserIds: string[]): boolean { + if (mutedUserIds.includes(note.userId)) { + return true; + } + + if (note.reply != null && mutedUserIds.includes(note.reply.userId)) { + return true; + } + + if (note.renote != null && mutedUserIds.includes(note.renote.userId)) { + return true; + } + + return false; +} diff --git a/src/misc/should-mute-this-note.ts b/src/misc/should-mute-this-note.ts deleted file mode 100644 index 8f606a2943..0000000000 --- a/src/misc/should-mute-this-note.ts +++ /dev/null @@ -1,15 +0,0 @@ -export default function(note: any, mutedUserIds: string[]): boolean { - if (mutedUserIds.includes(note.userId)) { - return true; - } - - if (note.reply != null && mutedUserIds.includes(note.reply.userId)) { - return true; - } - - if (note.renote != null && mutedUserIds.includes(note.renote.userId)) { - return true; - } - - return false; -} diff --git a/src/server/api/stream/channels/antenna.ts b/src/server/api/stream/channels/antenna.ts index 714edb502d..b5a792f814 100644 --- a/src/server/api/stream/channels/antenna.ts +++ b/src/server/api/stream/channels/antenna.ts @@ -1,7 +1,7 @@ import autobind from 'autobind-decorator'; import Channel from '../channel'; import { Notes } from '../../../../models'; -import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; export default class extends Channel { public readonly chName = 'antenna'; @@ -25,7 +25,7 @@ export default class extends Channel { const note = await Notes.pack(body.id, this.user, { detail: true }); // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する - if (shouldMuteThisNote(note, this.muting)) return; + if (isMutedUserRelated(note, this.muting)) return; this.send('note', note); } else { diff --git a/src/server/api/stream/channels/global-timeline.ts b/src/server/api/stream/channels/global-timeline.ts index 39800fa775..d530907d8d 100644 --- a/src/server/api/stream/channels/global-timeline.ts +++ b/src/server/api/stream/channels/global-timeline.ts @@ -1,5 +1,5 @@ import autobind from 'autobind-decorator'; -import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; import Channel from '../channel'; import { fetchMeta } from '../../../../misc/fetch-meta'; import { Notes } from '../../../../models'; @@ -46,7 +46,7 @@ export default class extends Channel { } // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する - if (shouldMuteThisNote(note, this.muting)) return; + if (isMutedUserRelated(note, this.muting)) return; // 流れてきたNoteがミュートすべきNoteだったら無視する // TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある) diff --git a/src/server/api/stream/channels/hashtag.ts b/src/server/api/stream/channels/hashtag.ts index e55a508328..32d8111f72 100644 --- a/src/server/api/stream/channels/hashtag.ts +++ b/src/server/api/stream/channels/hashtag.ts @@ -1,5 +1,5 @@ import autobind from 'autobind-decorator'; -import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; import Channel from '../channel'; import { Notes } from '../../../../models'; import { PackedNote } from '../../../../models/repositories/note'; @@ -34,7 +34,7 @@ export default class extends Channel { } // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する - if (shouldMuteThisNote(note, this.muting)) return; + if (isMutedUserRelated(note, this.muting)) return; this.send('note', note); } diff --git a/src/server/api/stream/channels/home-timeline.ts b/src/server/api/stream/channels/home-timeline.ts index 8504d4547b..caf4ccf5e9 100644 --- a/src/server/api/stream/channels/home-timeline.ts +++ b/src/server/api/stream/channels/home-timeline.ts @@ -1,5 +1,5 @@ import autobind from 'autobind-decorator'; -import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; import Channel from '../channel'; import { Notes } from '../../../../models'; import { PackedNote } from '../../../../models/repositories/note'; @@ -51,7 +51,7 @@ export default class extends Channel { } // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する - if (shouldMuteThisNote(note, this.muting)) return; + if (isMutedUserRelated(note, this.muting)) return; // 流れてきたNoteがミュートすべきNoteだったら無視する // TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある) diff --git a/src/server/api/stream/channels/hybrid-timeline.ts b/src/server/api/stream/channels/hybrid-timeline.ts index bc491934ea..1aec98aa72 100644 --- a/src/server/api/stream/channels/hybrid-timeline.ts +++ b/src/server/api/stream/channels/hybrid-timeline.ts @@ -1,5 +1,5 @@ import autobind from 'autobind-decorator'; -import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; import Channel from '../channel'; import { fetchMeta } from '../../../../misc/fetch-meta'; import { Notes } from '../../../../models'; @@ -60,7 +60,7 @@ export default class extends Channel { } // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する - if (shouldMuteThisNote(note, this.muting)) return; + if (isMutedUserRelated(note, this.muting)) return; // 流れてきたNoteがミュートすべきNoteだったら無視する // TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある) diff --git a/src/server/api/stream/channels/local-timeline.ts b/src/server/api/stream/channels/local-timeline.ts index 3279912f87..6426ccc23f 100644 --- a/src/server/api/stream/channels/local-timeline.ts +++ b/src/server/api/stream/channels/local-timeline.ts @@ -1,5 +1,5 @@ import autobind from 'autobind-decorator'; -import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; import Channel from '../channel'; import { fetchMeta } from '../../../../misc/fetch-meta'; import { Notes } from '../../../../models'; @@ -48,7 +48,7 @@ export default class extends Channel { } // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する - if (shouldMuteThisNote(note, this.muting)) return; + if (isMutedUserRelated(note, this.muting)) return; // 流れてきたNoteがミュートすべきNoteだったら無視する // TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある) diff --git a/src/server/api/stream/channels/user-list.ts b/src/server/api/stream/channels/user-list.ts index e1b7a88830..4191a0de54 100644 --- a/src/server/api/stream/channels/user-list.ts +++ b/src/server/api/stream/channels/user-list.ts @@ -1,7 +1,7 @@ import autobind from 'autobind-decorator'; import Channel from '../channel'; import { Notes, UserListJoinings, UserLists } from '../../../../models'; -import shouldMuteThisNote from '../../../../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../../../../misc/is-muted-user-related'; import { User } from '../../../../models/entities/user'; import { PackedNote } from '../../../../models/repositories/note'; @@ -73,7 +73,7 @@ export default class extends Channel { } // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する - if (shouldMuteThisNote(note, this.muting)) return; + if (isMutedUserRelated(note, this.muting)) return; this.send('note', note); } diff --git a/src/services/add-note-to-antenna.ts b/src/services/add-note-to-antenna.ts index 88a6613c60..57a0df2752 100644 --- a/src/services/add-note-to-antenna.ts +++ b/src/services/add-note-to-antenna.ts @@ -2,7 +2,7 @@ import { Antenna } from '../models/entities/antenna'; import { Note } from '../models/entities/note'; import { AntennaNotes, Mutings, Notes } from '../models'; import { genId } from '../misc/gen-id'; -import shouldMuteThisNote from '../misc/should-mute-this-note'; +import { isMutedUserRelated } from '../misc/is-muted-user-related'; import { ensure } from '../prelude/ensure'; import { publishAntennaStream, publishMainStream } from './stream'; import { User } from '../models/entities/user'; @@ -39,7 +39,7 @@ export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: U _note.renote = await Notes.findOne(note.renoteId).then(ensure); } - if (shouldMuteThisNote(_note, mutings.map(x => x.muteeId))) { + if (isMutedUserRelated(_note, mutings.map(x => x.muteeId))) { return; } -- cgit v1.2.3-freya