From 58a8fff895f0d6628b544502ead91085e7941a7a Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 10 May 2020 15:20:21 +0900 Subject: [PATCH] refactor(server): Improve readability --- src/misc/check-hit-antenna.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/misc/check-hit-antenna.ts b/src/misc/check-hit-antenna.ts index 62bb9867e7..562d054563 100644 --- a/src/misc/check-hit-antenna.ts +++ b/src/misc/check-hit-antenna.ts @@ -39,11 +39,16 @@ export async function checkHitAntenna(antenna: Antenna, note: Note, noteUser: Us if (!accts.includes(getFullApAccount(noteUser.username, noteUser.host).toLowerCase())) return false; } - if (antenna.keywords.length > 0) { + const keywords = antenna.keywords + // Clean up + .map(xs => xs.filter(x => x !== '')) + .filter(xs => xs.length > 0); + + if (keywords.length > 0) { if (note.text == null) return false; - const matched = antenna.keywords.some(keywords => - keywords.filter(keyword => keyword !== '').every(keyword => + const matched = keywords.some(and => + and.every(keyword => antenna.caseSensitive ? note.text!.includes(keyword) : note.text!.toLowerCase().includes(keyword.toLowerCase()) @@ -52,11 +57,16 @@ export async function checkHitAntenna(antenna: Antenna, note: Note, noteUser: Us if (!matched) return false; } - if (antenna.excludeKeywords.length > 0) { + const excludeKeywords = antenna.excludeKeywords + // Clean up + .map(xs => xs.filter(x => x !== '')) + .filter(xs => xs.length > 0); + + if (excludeKeywords.length > 0) { if (note.text == null) return false; - const matched = antenna.excludeKeywords.some(keywords => - keywords.filter(keyword => keyword !== '').every(keyword => + const matched = excludeKeywords.some(and => + and.every(keyword => antenna.caseSensitive ? note.text!.includes(keyword) : note.text!.toLowerCase().includes(keyword.toLowerCase())