From ed41d4c22e2181da9ef0d0141de98e0ef17faa7f Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 9 Apr 2025 08:26:09 +0800 Subject: [PATCH] Initial work on 'blur' filter for posts --- src/components/status.css | 4 ++- src/components/status.jsx | 55 +++++++++++++++++++++++++++++-------- src/components/timeline.jsx | 8 ++++-- src/pages/catchup.jsx | 12 ++++---- src/pages/filters.jsx | 18 +++++++++++- src/utils/filters.js | 13 ++++++++- 6 files changed, 89 insertions(+), 21 deletions(-) diff --git a/src/components/status.css b/src/components/status.css index 26f5d834..ab195bef 100644 --- a/src/components/status.css +++ b/src/components/status.css @@ -653,6 +653,7 @@ display: flex; gap: 4px; align-items: center; + text-align: start; } .status .content-container.has-spoiler:not(.show-spoiler) .spoiler-button { ~ *:not( @@ -1374,7 +1375,8 @@ body:has(#modal-container .carousel) .status .media img:hover { width: 100%; height: 100%; min-height: var(--min-dimension); - background-image: radial-gradient( + background-image: + radial-gradient( circle at center center, transparent, var(--bg-faded-color) diff --git a/src/components/status.jsx b/src/components/status.jsx index 4938b0ab..10e1e621 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -54,6 +54,7 @@ import htmlContentLength from '../utils/html-content-length'; import isRTL from '../utils/is-rtl'; import isMastodonLinkMaybe from '../utils/isMastodonLinkMaybe'; import localeMatch from '../utils/locale-match'; +import mem from '../utils/mem'; import niceDateTime from '../utils/nice-date-time'; import openCompose from '../utils/open-compose'; import pmem from '../utils/pmem'; @@ -317,6 +318,24 @@ const checkDifferentLanguage = ( return different; }; +const getCurrentAccID = mem( + () => { + return getCurrentAccountID(); + }, + { + maxAge: 60 * 1000, // 1 minute + }, +); + +const getPrefs = mem( + () => { + return store.account.get('preferences') || {}; + }, + { + maxAge: 60 * 1000, // 1 minute + }, +); + function Status({ statusID, status, @@ -330,7 +349,7 @@ function Status({ enableTranslate, forceTranslate: _forceTranslate, previewMode, - // allowFilters, + allowFilters, onMediaClick, quoted, onStatusLinkClick = () => {}, @@ -447,16 +466,16 @@ function Status({ const hasMediaAttachments = !!mediaAttachments?.length; if (mediaFirst && hasMediaAttachments) size = 's'; - const currentAccount = useMemo(() => { - return getCurrentAccountID(); - }, []); + const currentAccount = getCurrentAccID(); const isSelf = useMemo(() => { return currentAccount && currentAccount === accountId; }, [accountId, currentAccount]); const filterContext = useContext(FilterContext); const filterInfo = - !isSelf && !readOnly && !previewMode && isFiltered(filtered, filterContext); + !isSelf && + ((!readOnly && !previewMode) || allowFilters) && + isFiltered(filtered, filterContext); if (filterInfo?.action === 'hide') { return null; @@ -472,7 +491,11 @@ function Status({ } }; - if (/*allowFilters && */ size !== 'l' && filterInfo) { + if ( + (allowFilters || size !== 'l') && + filterInfo && + filterInfo.action !== 'blur' + ) { return ( mention.id === currentAccount); const readingExpandSpoilers = useMemo(() => { - const prefs = store.account.get('preferences') || {}; + const prefs = getPrefs(); return !!prefs['reading:expand:spoilers']; }, []); const readingExpandMedia = useMemo(() => { // default | show_all | hide_all // Ignore hide_all because it means hide *ALL* media including non-sensitive ones - const prefs = store.account.get('preferences') || {}; + const prefs = getPrefs(); return prefs['reading:expand:media']?.toLowerCase() || 'default'; }, []); // FOR TESTING: @@ -2011,7 +2034,9 @@ function Status({ )}
)} {!previewMode && - sensitive && + (sensitive || filterInfo?.action === 'blur') && !!mediaAttachments.length && readingExpandMedia !== 'show_all' && ( )} {!!mediaAttachments.length && diff --git a/src/components/timeline.jsx b/src/components/timeline.jsx index bf65bc30..893fd704 100644 --- a/src/components/timeline.jsx +++ b/src/components/timeline.jsx @@ -608,8 +608,12 @@ const TimelineItem = memo( // } const aFiltered = isFiltered(a.filtered, filterContext); const bFiltered = isFiltered(b.filtered, filterContext); - if (aFiltered) filteredItemsIDs.add(a.id); - if (bFiltered) filteredItemsIDs.add(b.id); + if (aFiltered && aFiltered?.action !== 'blur') { + filteredItemsIDs.add(a.id); + } + if (bFiltered && bFiltered?.action !== 'blur') { + filteredItemsIDs.add(b.id); + } if (aFiltered && !bFiltered) { return 1; } diff --git a/src/pages/catchup.jsx b/src/pages/catchup.jsx index 83ca5d8e..04a1b6d7 100644 --- a/src/pages/catchup.jsx +++ b/src/pages/catchup.jsx @@ -309,7 +309,7 @@ function Catchup() { original = 0; const links = {}; for (const post of posts) { - if (post._filtered) { + if (post._filtered && post._filtered?.action !== 'blur') { filtered++; post.__FILTER = 'filtered'; } else if (post.group) { @@ -1711,7 +1711,7 @@ const PostLine = memo( __BOOSTERS, } = post; const isReplyTo = inReplyToId && inReplyToAccountId !== account.id; - const isFiltered = !!filterInfo; + const isFiltered = !!filterInfo && filterInfo?.action !== 'blur'; const debugHover = (e) => { if (e.shiftKey) { @@ -1853,7 +1853,9 @@ function PostPeek({ post, filterInfo }) { return !!prefs['reading:expand:spoilers']; }, []); // const readingExpandSpoilers = true; - const showMedia = readingExpandSpoilers || (!spoilerText && !sensitive); + const showMedia = + readingExpandSpoilers || + (!spoilerText && !sensitive && filterInfo?.action !== 'blur'); const postText = content ? statusPeek(post) : ''; const showPostContent = !spoilerText || readingExpandSpoilers; @@ -1866,7 +1868,7 @@ function PostPeek({ post, filterInfo }) { Thread{' '} )} - {!!filterInfo ? ( + {!!filterInfo && filterInfo?.action !== 'blur' ? ( {/* Filtered{filterInfo?.titlesStr ? `: ${filterInfo.titlesStr}` : ''} */} {filterInfo?.titlesStr @@ -1918,7 +1920,7 @@ function PostPeek({ post, filterInfo }) { )} - {!filterInfo && ( + {(!filterInfo || filterInfo?.action === 'blur') && ( {!!poll && ( diff --git a/src/pages/filters.jsx b/src/pages/filters.jsx index f9eaee98..ea8c9575 100644 --- a/src/pages/filters.jsx +++ b/src/pages/filters.jsx @@ -13,6 +13,7 @@ import NavMenu from '../components/nav-menu'; import RelativeTime from '../components/relative-time'; import { api } from '../utils/api'; import i18nDuration from '../utils/i18n-duration'; +import { getAPIVersions } from '../utils/store-utils'; import useInterval from '../utils/useInterval'; import useTitle from '../utils/useTitle'; @@ -525,12 +526,27 @@ function FiltersAddEdit({ filter, onClose }) {

Filtered post will be…
+ {getAPIVersions()?.mastodon >= 5 && ( + + )}{' '}