Implemented new filter options

This commit is contained in:
Marcel Hellkamp 2023-07-24 14:51:11 +02:00
parent 15883a53aa
commit 5375a2764a
2 changed files with 38 additions and 12 deletions

View File

@ -6,6 +6,7 @@ import ConfigModal from './components/ConfigModal.vue';
import { loadConfig, type Config } from './config'; import { loadConfig, type Config } from './config';
import InfoBar from './components/InfoBar.vue'; import InfoBar from './components/InfoBar.vue';
import { gitVersion } from '@/defaults' import { gitVersion } from '@/defaults'
import { regexEscape } from '@/utils'
const config = ref<Config>(); const config = ref<Config>();
@ -117,20 +118,41 @@ async function getLocalUser(user: string, domain: string): Promise<any> {
* Check if a mastodon status document should be accepted * Check if a mastodon status document should be accepted
*/ */
const filterStatus = (status: any) => { const filterStatus = (status: any) => {
const cfg = config.value
if (!cfg) return false;
// Filter reblogs?
if (cfg.hideBoosts && status.reblog) return false;
// Unwrap boosts here so the other filters are checked against the status that
// is going to be displayed, not just the boost-status.
if (status.reblog) if (status.reblog)
status = status.reblog status = status.reblog
// Filter sensitive posts (TODO: Allow if configured) // Filter by language
if (status?.sensitive) return false; if (cfg.languages.length > 0
// Filter replies (TODO: Allow if configured) && !cfg.languages.includes(status.language || "en")) return false;
if (status?.in_reply_to_id) return false; // Filter sensitive content?
// Filter non-public posts if (cfg.hideSensitive && status.sensitive) return false;
if (status?.visibility !== "public") return false; // Filter replies?
// Filter bad actors if (cfg.hideReplies && status.in_reply_to_id) return false;
if (status?.account?.suspended) return false; // Filter bots?
if (status?.account?.limted) return false; if (cfg.hideBots && status.account?.bot) return false;
// TODO: Filter bots? // Filter bad hashtags or words
//if(post?.account?.bot) return false; if (cfg.badWords.length) {
const pattern = new RegExp(`\\b(${cfg.badWords.map(regexEscape).join("|")})\\b`, 'i');
if (status.tags?.find((tag: any) => cfg.badWords.includes(tag.name)))
return false;
if (status.content.match(pattern))
return false;
}
// Filter non-public content
if (status.visibility !== "public") return false;
// Filter limited or suspended accounts
if (status.account?.suspended) return false;
if (status.account?.limted) return false;
// Accept anything else // Accept anything else
return true; return true;
} }

View File

@ -13,6 +13,10 @@ export function arrayUnique<T>(array: T[]) {
return array.filter((v,i,a) => a.indexOf(v) === i) return array.filter((v,i,a) => a.indexOf(v) === i)
} }
export function regexEscape(str: string) {
return str.toString().replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
}
export function deepClone(obj: any) { export function deepClone(obj: any) {
if(window.structuredClone) if(window.structuredClone)
return window.structuredClone(obj) return window.structuredClone(obj)