mirror of
https://github.com/defnull/fediwall.git
synced 2024-11-22 15:43:31 +01:00
Implemented new filter options
This commit is contained in:
parent
15883a53aa
commit
5375a2764a
46
src/App.vue
46
src/App.vue
@ -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;
|
||||||
}
|
}
|
||||||
@ -233,7 +255,7 @@ async function fetchAllPosts() {
|
|||||||
// Collect results
|
// Collect results
|
||||||
const posts: Post[] = []
|
const posts: Post[] = []
|
||||||
const addOrRepaceStatus = (status: any) => {
|
const addOrRepaceStatus = (status: any) => {
|
||||||
if(!status || !filterStatus(status)) return;
|
if (!status || !filterStatus(status)) return;
|
||||||
const post = statusToWallPost(status)
|
const post = statusToWallPost(status)
|
||||||
const i = posts.findIndex(p => p.url === post.url)
|
const i = posts.findIndex(p => p.url === post.url)
|
||||||
if (i >= 0)
|
if (i >= 0)
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user