Code cleanup

This commit is contained in:
Marcel Hellkamp 2023-07-28 19:36:57 +02:00
parent b9d0c9f677
commit 9f8057e4d5

View File

@ -166,24 +166,24 @@ async function fetchJson(domain: string, path: string, query?: Record<string, an
* Check if a mastodon status document should be accepted * Check if a mastodon status document should be accepted
*/ */
const filterStatus = (cfg: Config, status: MastodonStatus) => { const filterStatus = (cfg: Config, status: MastodonStatus) => {
// Filter reblogs? // Boosts are unwrapped so other filters check the actual status that is
if (cfg.hideBoosts && status.reblog) return false; // going to be displayed, not the (mostly empty) boost-status.
if (status.reblog) {
// Unwrap boosts here so the other filters are checked against the status that if(cfg.hideBoosts) return false;
// is going to be displayed, not just the boost-status.
if (status.reblog)
status = status.reblog status = status.reblog
}
// Filter by language // These filters are always active
if (status.visibility !== "public") return false;
if (status.account?.suspended) return false;
if (status.account?.limited) return false;
// Optional filters
if (cfg.languages.length > 0 if (cfg.languages.length > 0
&& !cfg.languages.includes(status.language || "en")) return false; && !cfg.languages.includes(status.language || "en")) return false;
// Filter sensitive content?
if (cfg.hideSensitive && status.sensitive) return false; if (cfg.hideSensitive && status.sensitive) return false;
// Filter replies?
if (cfg.hideReplies && status.in_reply_to_id) return false; if (cfg.hideReplies && status.in_reply_to_id) return false;
// Filter bots?
if (cfg.hideBots && status.account?.bot) return false; if (cfg.hideBots && status.account?.bot) return false;
// Filter bad hashtags or words
if (cfg.badWords.length) { if (cfg.badWords.length) {
const pattern = new RegExp(`\\b(${cfg.badWords.map(regexEscape).join("|")})\\b`, 'i'); const pattern = new RegExp(`\\b(${cfg.badWords.map(regexEscape).join("|")})\\b`, 'i');
if (status.tags?.find((tag: any) => cfg.badWords.includes(tag.name))) if (status.tags?.find((tag: any) => cfg.badWords.includes(tag.name)))
@ -192,13 +192,7 @@ const filterStatus = (cfg: Config, status: MastodonStatus) => {
return false; return false;
} }
// Filter non-public content // Skip posts that would show up empty
if (status.visibility !== "public") return false;
// Filter limited or suspended accounts
if (status.account?.suspended) return false;
if (status.account?.limited) return false;
// Filter posts that would show up empty
if(!cfg.showText && ! status.media_attachments?.length) return false; if(!cfg.showText && ! status.media_attachments?.length) return false;
if(!cfg.showMedia && ! status.content.trim()) return false; if(!cfg.showMedia && ! status.content.trim()) return false;