diff --git a/components/timeline/TimelineHomeFilter.vue b/components/timeline/TimelineHomeFilter.vue index 0edfbe79..0d957b6f 100644 --- a/components/timeline/TimelineHomeFilter.vue +++ b/components/timeline/TimelineHomeFilter.vue @@ -1,11 +1,5 @@ diff --git a/composables/settings/definition.ts b/composables/settings/definition.ts index 269df245..73dafeb0 100644 --- a/composables/settings/definition.ts +++ b/composables/settings/definition.ts @@ -35,6 +35,14 @@ export interface UserSettings { themeColors?: ThemeColors } +export interface UserHomeFilter { + bot: boolean + sensitive: boolean + repost: boolean + mutual: boolean + tag: boolean +} + export interface ThemeColors { '--theme-color-name': string diff --git a/composables/settings/storage.ts b/composables/settings/storage.ts index a1a543d7..b5c01ebd 100644 --- a/composables/settings/storage.ts +++ b/composables/settings/storage.ts @@ -1,8 +1,8 @@ import type { Ref } from 'vue' import type { VueI18n } from 'vue-i18n' import type { LocaleObject } from 'vue-i18n-routing' -import type { FontSize, OldFontSize, PreferencesSettings, UserSettings } from './definition' -import { STORAGE_KEY_SETTINGS } from '~/constants' +import type { FontSize, OldFontSize, PreferencesSettings, UserHomeFilter, UserSettings } from './definition' +import { STORAGE_KEY_HOME_FILTER, STORAGE_KEY_SETTINGS } from '~/constants' import { oldFontSizeMap } from '~~/constants/options' export function useUserSettings() { @@ -45,3 +45,13 @@ export function togglePreferences(key: keyof PreferencesSettings) { const flag = usePreferences(key) flag.value = !flag.value } + +export function useHomeFilter() { + return useUserSessionStorage(STORAGE_KEY_HOME_FILTER, () => ({ + bot: true, + sensitive: true, + repost: true, + mutual: true, + tag: true, + })) +} diff --git a/composables/timeline.ts b/composables/timeline.ts index 51988216..c6e42e54 100644 --- a/composables/timeline.ts +++ b/composables/timeline.ts @@ -14,7 +14,20 @@ function removeFilteredItems(items: mastodon.v1.Status[], context: mastodon.v1.F const isFiltered = (item: mastodon.v1.Status) => (item.account.id === currentUser.value?.account.id) || !item.filtered?.find(isStrict) const isReblogFiltered = (item: mastodon.v1.Status) => !item.reblog?.filtered?.find(isStrict) - return [...items].filter(isFiltered).filter(isReblogFiltered) + const homeFilter = useHomeFilter() + const { bot, mutual, repost, sensitive, tag } = homeFilter.value + + const isClientSideHomeFiltered = (item: mastodon.v1.Status) => { + if (bot && mutual && repost && sensitive && tag) + return true + + if (item.account.bot && !bot) + return false + + return true + } + + return [...items].filter(isFiltered).filter(isReblogFiltered).filter(isClientSideHomeFiltered) } export function reorderedTimeline(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext = 'public') { diff --git a/composables/users.ts b/composables/users.ts index feea3d64..9cb19166 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -330,3 +330,17 @@ export function clearUserLocalStorage(account?: mastodon.v1.Account) { delete value.value[id] }) } + +export function useUserSessionStorage(key: string, initial: () => T): Ref { + if (process.server || process.test) + return shallowRef(initial()) + + const all = useSessionStorage>(key, {}, { deep: true }) + return computed(() => { + const id = currentUser.value?.account.id + ? currentUser.value.account.acct + : '[anonymous]' + all.value[id] = Object.assign(initial(), all.value[id] || {}) + return all.value[id] + }) +} diff --git a/constants/index.ts b/constants/index.ts index c7d28132..c3cff03e 100644 --- a/constants/index.ts +++ b/constants/index.ts @@ -13,6 +13,7 @@ export const STORAGE_KEY_CURRENT_USER_HANDLE = 'elk-current-user-handle' export const STORAGE_KEY_NOTIFY_TAB = 'elk-notify-tab' export const STORAGE_KEY_FIRST_VISIT = 'elk-first-visit' export const STORAGE_KEY_SETTINGS = 'elk-settings' +export const STORAGE_KEY_HOME_FILTER = 'elk-home-filter' export const STORAGE_KEY_CUSTOM_EMOJIS = 'elk-custom-emojis' export const STORAGE_KEY_HIDE_EXPLORE_POSTS_TIPS = 'elk-hide-explore-posts-tips' export const STORAGE_KEY_HIDE_EXPLORE_NEWS_TIPS = 'elk-hide-explore-news-tips'