egirlskey/src/client/app/common/scripts/should-mute-note.ts

20 lines
905 B
TypeScript
Raw Normal View History

export default function(me, settings, note) {
2019-02-28 05:13:18 +00:00
const isMyNote = me && (note.userId == me.id);
const isPureRenote = note.renoteId != null && note.text == null && note.fileIds.length == 0 && note.poll == null;
2018-12-28 20:51:17 +00:00
const includesMutedWords = (text: string) =>
text
? settings.mutedWords.some(q => q.length > 0 && !q.some(word =>
word.startsWith('/') && word.endsWith('/') ? !(new RegExp(word.substr(1, word.length - 2)).test(text)) : !text.includes(word)))
2018-12-28 20:51:17 +00:00
: false;
return (
(!isMyNote && note.reply && includesMutedWords(note.reply.text)) ||
(!isMyNote && note.renote && includesMutedWords(note.renote.text)) ||
(!settings.showMyRenotes && isMyNote && isPureRenote) ||
(!settings.showRenotedMyNotes && isPureRenote && note.renote.userId == me.id) ||
(!settings.showLocalRenotes && isPureRenote && note.renote.user.host == null) ||
2018-12-28 20:51:17 +00:00
(!isMyNote && includesMutedWords(note.text))
);
}