backend: improve mutes and blocks
Some checks failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/lint-backend Pipeline failed
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/pr/test Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/pr/lint-client Pipeline failed

Mutes and blocks now also apply recursively to replies and renotes.
Furthermore, any mentioned user being muted or blocked will also apply.
This commit is contained in:
Chloe Kudryavtsev 2022-07-26 08:12:49 -04:00
parent 63c8992cb8
commit 0f6d94f1e7

View file

@ -1,15 +1,7 @@
export function isUserRelated(note: any, userIds: Set<string>): boolean {
if (userIds.has(note.userId)) {
return true;
}
if (note.reply != null && userIds.has(note.reply.userId)) {
return true;
}
if (note.renote != null && userIds.has(note.renote.userId)) {
return true;
}
export function isUserRelated(note: any, ids: Set<string>): boolean {
if(ids.has(note.userId)) return true; // note author is muted
if(note.mentions && note.mentions.some((user: string) => ids.has(user))) return true; // any of mentioned users are muted
if(note.reply && isUserRelated(note.reply, ids)) return true; // also check reply target
if(note.renote && isUserRelated(note.renote, ids)) return true; // also check renote target
return false;
}