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>
This commit is contained in:
Tess K 2024-05-04 18:51:36 +00:00
commit 83df1c0128
1 changed files with 26 additions and 2 deletions

View File

@ -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();
}