From 6b066eac2c6fcf7b8073d0a0d27aa6a569a68f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Fri, 23 May 2025 09:11:32 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20=E2=80=9COpen=20original=20page=E2=80=9D?= =?UTF-8?q?=20and=20=E2=80=9CAdd=20or=20Remove=20from=20lists=E2=80=9D=20b?= =?UTF-8?q?eing=20included=20in=20account=20dropdown=20even=20when=20irrel?= =?UTF-8?q?evant=20(#34767)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicole Mikołajczyk --- .../mastodon/components/account.tsx | 117 ++++++++++-------- 1 file changed, 64 insertions(+), 53 deletions(-) diff --git a/app/javascript/mastodon/components/account.tsx b/app/javascript/mastodon/components/account.tsx index 87e9a6eccf..cad7575f25 100644 --- a/app/javascript/mastodon/components/account.tsx +++ b/app/javascript/mastodon/components/account.tsx @@ -27,6 +27,7 @@ import { RelativeTimestamp } from 'mastodon/components/relative_timestamp'; import { ShortNumber } from 'mastodon/components/short_number'; import { Skeleton } from 'mastodon/components/skeleton'; import { VerifiedBadge } from 'mastodon/components/verified_badge'; +import { useIdentity } from 'mastodon/identity_context'; import { me } from 'mastodon/initial_state'; import type { MenuItem } from 'mastodon/models/dropdown_menu'; import { useAppSelector, useAppDispatch } from 'mastodon/store'; @@ -70,10 +71,12 @@ export const Account: React.FC<{ withBio?: boolean; }> = ({ id, size = 46, hidden, minimal, defaultAction, withBio }) => { const intl = useIntl(); + const { signedIn } = useIdentity(); const account = useAppSelector((state) => state.accounts.get(id)); const relationship = useAppSelector((state) => state.relationships.get(id)); const dispatch = useAppDispatch(); const accountUrl = account?.url; + const isRemote = account?.acct !== account?.username; const handleBlock = useCallback(() => { if (relationship?.blocking) { @@ -116,66 +119,74 @@ export const Account: React.FC<{ }, ]; } else if (defaultAction !== 'block') { - const handleAddToLists = () => { - const openAddToListModal = () => { - dispatch( - openModal({ - modalType: 'LIST_ADDER', - modalProps: { - accountId: id, - }, - }), - ); - }; - if (relationship?.following || relationship?.requested || id === me) { - openAddToListModal(); - } else { - dispatch( - openModal({ - modalType: 'CONFIRM_FOLLOW_TO_LIST', - modalProps: { - accountId: id, - onConfirm: () => { - apiFollowAccount(id) - .then((relationship) => { - dispatch( - followAccountSuccess({ - relationship, - alreadyFollowing: false, - }), - ); - openAddToListModal(); - }) - .catch((err: unknown) => { - dispatch(showAlertForError(err)); - }); - }, - }, - }), - ); - } - }; + arr = []; - arr = [ - { + if (isRemote && accountUrl) { + arr.push({ + text: intl.formatMessage(messages.openOriginalPage), + href: accountUrl, + }); + } + + if (signedIn) { + const handleAddToLists = () => { + const openAddToListModal = () => { + dispatch( + openModal({ + modalType: 'LIST_ADDER', + modalProps: { + accountId: id, + }, + }), + ); + }; + if (relationship?.following || relationship?.requested || id === me) { + openAddToListModal(); + } else { + dispatch( + openModal({ + modalType: 'CONFIRM_FOLLOW_TO_LIST', + modalProps: { + accountId: id, + onConfirm: () => { + apiFollowAccount(id) + .then((relationship) => { + dispatch( + followAccountSuccess({ + relationship, + alreadyFollowing: false, + }), + ); + openAddToListModal(); + }) + .catch((err: unknown) => { + dispatch(showAlertForError(err)); + }); + }, + }, + }), + ); + } + }; + + arr.push({ text: intl.formatMessage(messages.addToLists), action: handleAddToLists, - }, - ]; - - if (accountUrl) { - arr.unshift( - { - text: intl.formatMessage(messages.openOriginalPage), - href: accountUrl, - }, - null, - ); + }); } } return arr; - }, [dispatch, intl, id, accountUrl, relationship, defaultAction]); + }, [ + dispatch, + intl, + id, + accountUrl, + relationship, + defaultAction, + isRemote, + signedIn, + ]); if (hidden) { return (