diff options
| author | Tess K <me@thvxl.se> | 2024-05-04 18:51:36 +0000 |
|---|---|---|
| committer | Tess K <me@thvxl.se> | 2024-05-04 18:51:36 +0000 |
| commit | 83df1c012874204fb83a5e2d4671767de4f599f8 (patch) | |
| tree | 10f354f5e9b77cdd6298e4cd506f3c6524bf56cc /packages/frontend/src/scripts | |
| parent | merge: Compact LD-signed activities against well-known context (!503) (diff) | |
| parent | revert refactor and cleanup (diff) | |
| download | sharkey-83df1c012874204fb83a5e2d4671767de4f599f8.tar.gz sharkey-83df1c012874204fb83a5e2d4671767de4f599f8.tar.bz2 sharkey-83df1c012874204fb83a5e2d4671767de4f599f8.zip | |
merge: feat: check polls and media for muted keywords (!507)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/507
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Tess K <me@thvxl.se>
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/check-word-mute.ts | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/packages/frontend/src/scripts/check-word-mute.ts b/packages/frontend/src/scripts/check-word-mute.ts index 67e896b4b9..8d3e96cea5 100644 --- a/packages/frontend/src/scripts/check-word-mute.ts +++ b/packages/frontend/src/scripts/check-word-mute.ts @@ -3,12 +3,14 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -export function checkWordMute(note: Record<string, any>, me: Record<string, any> | null | undefined, mutedWords: Array<string | string[]>): boolean { +import type { Note, MeDetailed } from "misskey-js/entities.js"; + +export function checkWordMute(note: Note, me: MeDetailed | null | undefined, mutedWords: Array<string | string[]>): boolean { // 自分自身 if (me && (note.userId === me.id)) return false; if (mutedWords.length > 0) { - const text = ((note.cw ?? '') + '\n' + (note.text ?? '')).trim(); + const text = getNoteText(note); if (text === '') return false; @@ -40,3 +42,25 @@ export function checkWordMute(note: Record<string, any>, me: Record<string, any> return false; } + +function getNoteText(note: Note): string { + const textParts: string[] = []; + + if (note.cw) + textParts.push(note.cw); + + if (note.text) + textParts.push(note.text); + + if (note.files) + for (const file of note.files) + if (file.comment) + textParts.push(file.comment); + + if (note.poll) + for (const choice of note.poll.choices) + if (choice.text) + textParts.push(choice.text); + + return textParts.join('\n').trim(); +} |