From 24551375cf556dbf8ef86dd508413a1b449ebde9 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Mon, 19 May 2025 11:54:45 +0200 Subject: [PATCH] fix: Show Follow account modal before allowing adding to list, #34468 (#34709) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Matt Jankowski Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Actions --- .../mastodon/components/account.tsx | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/app/javascript/mastodon/components/account.tsx b/app/javascript/mastodon/components/account.tsx index f6241504f6..87e9a6eccf 100644 --- a/app/javascript/mastodon/components/account.tsx +++ b/app/javascript/mastodon/components/account.tsx @@ -11,9 +11,12 @@ import { unblockAccount, muteAccount, unmuteAccount, + followAccountSuccess, } from 'mastodon/actions/accounts'; +import { showAlertForError } from 'mastodon/actions/alerts'; import { openModal } from 'mastodon/actions/modal'; import { initMuteModal } from 'mastodon/actions/mutes'; +import { apiFollowAccount } from 'mastodon/api/accounts'; import { Avatar } from 'mastodon/components/avatar'; import { Button } from 'mastodon/components/button'; import { FollowersCounter } from 'mastodon/components/counters'; @@ -24,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 { me } from 'mastodon/initial_state'; import type { MenuItem } from 'mastodon/models/dropdown_menu'; import { useAppSelector, useAppDispatch } from 'mastodon/store'; @@ -113,14 +117,43 @@ export const Account: React.FC<{ ]; } else if (defaultAction !== 'block') { const handleAddToLists = () => { - dispatch( - openModal({ - modalType: 'LIST_ADDER', - modalProps: { - accountId: id, - }, - }), - ); + 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 = [