summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-09-17 23:07:15 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-09-17 23:07:15 +0900
commit44f6fe6f1fa3873d6b6950dc5746725f014a1bb1 (patch)
tree6e3593d17111e620312642dee58cb89db99e0040 /src
parentNo lint when test (diff)
downloadsharkey-44f6fe6f1fa3873d6b6950dc5746725f014a1bb1.tar.gz
sharkey-44f6fe6f1fa3873d6b6950dc5746725f014a1bb1.tar.bz2
sharkey-44f6fe6f1fa3873d6b6950dc5746725f014a1bb1.zip
Refactor: Extract shouldMuteThisNote function
Diffstat (limited to 'src')
-rw-r--r--src/misc/should-mute-this-note.ts15
-rw-r--r--src/server/api/stream/global-timeline.ts14
-rw-r--r--src/server/api/stream/hashtag.ts14
-rw-r--r--src/server/api/stream/home.ts11
-rw-r--r--src/server/api/stream/hybrid-timeline.ts14
-rw-r--r--src/server/api/stream/local-timeline.ts14
6 files changed, 29 insertions, 53 deletions
diff --git a/src/misc/should-mute-this-note.ts b/src/misc/should-mute-this-note.ts
new file mode 100644
index 0000000000..c818115a3c
--- /dev/null
+++ b/src/misc/should-mute-this-note.ts
@@ -0,0 +1,15 @@
+export default function(note: any, mutedUserIds: string[]): boolean {
+ if (mutedUserIds.indexOf(note.userId) != -1) {
+ return true;
+ }
+
+ if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
+ return true;
+ }
+
+ if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
+ return true;
+ }
+
+ return false;
+}
diff --git a/src/server/api/stream/global-timeline.ts b/src/server/api/stream/global-timeline.ts
index 4786450cbb..03852fb181 100644
--- a/src/server/api/stream/global-timeline.ts
+++ b/src/server/api/stream/global-timeline.ts
@@ -3,6 +3,7 @@ import Xev from 'xev';
import { IUser } from '../../../models/user';
import Mute from '../../../models/mute';
+import shouldMuteThisNote from '../../../misc/should-mute-this-note';
export default async function(
request: websocket.request,
@@ -15,17 +16,8 @@ export default async function(
// Subscribe stream
subscriber.on('global-timeline', async note => {
- //#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
- if (mutedUserIds.indexOf(note.userId) != -1) {
- return;
- }
- if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
- return;
- }
- if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
- return;
- }
- //#endregion
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, mutedUserIds)) return;
connection.send(JSON.stringify({
type: 'note',
diff --git a/src/server/api/stream/hashtag.ts b/src/server/api/stream/hashtag.ts
index db2806e796..54da4f9ad9 100644
--- a/src/server/api/stream/hashtag.ts
+++ b/src/server/api/stream/hashtag.ts
@@ -4,6 +4,7 @@ import Xev from 'xev';
import { IUser } from '../../../models/user';
import Mute from '../../../models/mute';
import { pack } from '../../../models/note';
+import shouldMuteThisNote from '../../../misc/should-mute-this-note';
export default async function(
request: websocket.request,
@@ -28,17 +29,8 @@ export default async function(
});
}
- //#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
- if (mutedUserIds.indexOf(note.userId) != -1) {
- return;
- }
- if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
- return;
- }
- if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
- return;
- }
- //#endregion
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, mutedUserIds)) return;
connection.send(JSON.stringify({
type: 'note',
diff --git a/src/server/api/stream/home.ts b/src/server/api/stream/home.ts
index 5f3b6744b2..f1fced42d7 100644
--- a/src/server/api/stream/home.ts
+++ b/src/server/api/stream/home.ts
@@ -8,6 +8,7 @@ import { pack as packNote, pack } from '../../../models/note';
import readNotification from '../common/read-notification';
import call from '../call';
import { IApp } from '../../../models/app';
+import shouldMuteThisNote from '../../../misc/should-mute-this-note';
const log = debug('misskey');
@@ -45,15 +46,7 @@ export default async function(
//#region 流れてきたメッセージがミュートしているユーザーが関わるものだったら無視する
if (x.type == 'note') {
- if (mutedUserIds.includes(x.body.userId)) {
- return;
- }
- if (x.body.reply != null && mutedUserIds.includes(x.body.reply.userId)) {
- return;
- }
- if (x.body.renote != null && mutedUserIds.includes(x.body.renote.userId)) {
- return;
- }
+ if (shouldMuteThisNote(x.body, mutedUserIds)) return;
} else if (x.type == 'notification') {
if (mutedUserIds.includes(x.body.userId)) {
return;
diff --git a/src/server/api/stream/hybrid-timeline.ts b/src/server/api/stream/hybrid-timeline.ts
index d0dae9b0dd..045b822783 100644
--- a/src/server/api/stream/hybrid-timeline.ts
+++ b/src/server/api/stream/hybrid-timeline.ts
@@ -4,6 +4,7 @@ import Xev from 'xev';
import { IUser } from '../../../models/user';
import Mute from '../../../models/mute';
import { pack } from '../../../models/note';
+import shouldMuteThisNote from '../../../misc/should-mute-this-note';
export default async function(
request: websocket.request,
@@ -26,17 +27,8 @@ export default async function(
});
}
- //#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
- if (mutedUserIds.indexOf(note.userId) != -1) {
- return;
- }
- if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
- return;
- }
- if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
- return;
- }
- //#endregion
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, mutedUserIds)) return;
connection.send(JSON.stringify({
type: 'note',
diff --git a/src/server/api/stream/local-timeline.ts b/src/server/api/stream/local-timeline.ts
index e21c071bab..ae054a5f9f 100644
--- a/src/server/api/stream/local-timeline.ts
+++ b/src/server/api/stream/local-timeline.ts
@@ -4,6 +4,7 @@ import Xev from 'xev';
import { IUser } from '../../../models/user';
import Mute from '../../../models/mute';
import { pack } from '../../../models/note';
+import shouldMuteThisNote from '../../../misc/should-mute-this-note';
export default async function(
request: websocket.request,
@@ -23,17 +24,8 @@ export default async function(
});
}
- //#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
- if (mutedUserIds.indexOf(note.userId) != -1) {
- return;
- }
- if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
- return;
- }
- if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
- return;
- }
- //#endregion
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, mutedUserIds)) return;
connection.send(JSON.stringify({
type: 'note',