Skip to content

Commit 894fd82

Browse files
committed
Do not display nonsense items in account dropdowns
Signed-off-by: Nicole Mikołajczyk <[email protected]>
1 parent ef1bf8e commit 894fd82

File tree

1 file changed

+56
-50
lines changed

1 file changed

+56
-50
lines changed

app/javascript/mastodon/components/account.tsx

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { RelativeTimestamp } from 'mastodon/components/relative_timestamp';
2727
import { ShortNumber } from 'mastodon/components/short_number';
2828
import { Skeleton } from 'mastodon/components/skeleton';
2929
import { VerifiedBadge } from 'mastodon/components/verified_badge';
30+
import { useIdentity } from 'mastodon/identity_context';
3031
import { me } from 'mastodon/initial_state';
3132
import type { MenuItem } from 'mastodon/models/dropdown_menu';
3233
import { useAppSelector, useAppDispatch } from 'mastodon/store';
@@ -70,10 +71,12 @@ export const Account: React.FC<{
7071
withBio?: boolean;
7172
}> = ({ id, size = 46, hidden, minimal, defaultAction, withBio }) => {
7273
const intl = useIntl();
74+
const { signedIn } = useIdentity();
7375
const account = useAppSelector((state) => state.accounts.get(id));
7476
const relationship = useAppSelector((state) => state.relationships.get(id));
7577
const dispatch = useAppDispatch();
7678
const accountUrl = account?.url;
79+
const isRemote = account?.acct !== account?.username;
7780

7881
const handleBlock = useCallback(() => {
7982
if (relationship?.blocking) {
@@ -116,66 +119,69 @@ export const Account: React.FC<{
116119
},
117120
];
118121
} else if (defaultAction !== 'block') {
119-
const handleAddToLists = () => {
120-
const openAddToListModal = () => {
121-
dispatch(
122-
openModal({
123-
modalType: 'LIST_ADDER',
124-
modalProps: {
125-
accountId: id,
126-
},
127-
}),
128-
);
129-
};
130-
if (relationship?.following || relationship?.requested || id === me) {
131-
openAddToListModal();
132-
} else {
133-
dispatch(
134-
openModal({
135-
modalType: 'CONFIRM_FOLLOW_TO_LIST',
136-
modalProps: {
137-
accountId: id,
138-
onConfirm: () => {
139-
apiFollowAccount(id)
140-
.then((relationship) => {
141-
dispatch(
142-
followAccountSuccess({
143-
relationship,
144-
alreadyFollowing: false,
145-
}),
146-
);
147-
openAddToListModal();
148-
})
149-
.catch((err: unknown) => {
150-
dispatch(showAlertForError(err));
151-
});
152-
},
153-
},
154-
}),
155-
);
156-
}
157-
};
122+
arr = [];
158123

159-
arr = [
160-
{
161-
text: intl.formatMessage(messages.addToLists),
162-
action: handleAddToLists,
163-
},
164-
];
165-
166-
if (accountUrl) {
167-
arr.unshift(
124+
if (isRemote && accountUrl) {
125+
arr.push(
168126
{
169127
text: intl.formatMessage(messages.openOriginalPage),
170128
href: accountUrl,
171129
},
172-
null,
130+
);
131+
}
132+
133+
if (signedIn) {
134+
const handleAddToLists = () => {
135+
const openAddToListModal = () => {
136+
dispatch(
137+
openModal({
138+
modalType: 'LIST_ADDER',
139+
modalProps: {
140+
accountId: id,
141+
},
142+
}),
143+
);
144+
};
145+
if (relationship?.following || relationship?.requested || id === me) {
146+
openAddToListModal();
147+
} else {
148+
dispatch(
149+
openModal({
150+
modalType: 'CONFIRM_FOLLOW_TO_LIST',
151+
modalProps: {
152+
accountId: id,
153+
onConfirm: () => {
154+
apiFollowAccount(id)
155+
.then((relationship) => {
156+
dispatch(
157+
followAccountSuccess({
158+
relationship,
159+
alreadyFollowing: false,
160+
}),
161+
);
162+
openAddToListModal();
163+
})
164+
.catch((err: unknown) => {
165+
dispatch(showAlertForError(err));
166+
});
167+
},
168+
},
169+
}),
170+
);
171+
}
172+
};
173+
174+
arr.push(
175+
{
176+
text: intl.formatMessage(messages.addToLists),
177+
action: handleAddToLists,
178+
},
173179
);
174180
}
175181
}
176182

177183
return arr;
178-
}, [dispatch, intl, id, accountUrl, relationship, defaultAction]);
184+
}, [dispatch, intl, id, accountUrl, relationship, defaultAction, isRemote, signedIn]);
179185

180186
if (hidden) {
181187
return (

0 commit comments

Comments
 (0)