Only suggest discoverable accounts in collection account editor (#37920)
This commit is contained in:
@@ -12,6 +12,26 @@ export interface ApiAccountRoleJSON {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApiFeaturePolicy =
|
||||||
|
| 'public'
|
||||||
|
| 'followers'
|
||||||
|
| 'following'
|
||||||
|
| 'disabled'
|
||||||
|
| 'unsupported_policy';
|
||||||
|
|
||||||
|
type ApiUserFeaturePolicy =
|
||||||
|
| 'automatic'
|
||||||
|
| 'manual'
|
||||||
|
| 'denied'
|
||||||
|
| 'missing'
|
||||||
|
| 'unknown';
|
||||||
|
|
||||||
|
interface ApiFeaturePolicyJSON {
|
||||||
|
automatic: ApiFeaturePolicy[];
|
||||||
|
manual: ApiFeaturePolicy[];
|
||||||
|
current_user: ApiUserFeaturePolicy;
|
||||||
|
}
|
||||||
|
|
||||||
// See app/serializers/rest/account_serializer.rb
|
// See app/serializers/rest/account_serializer.rb
|
||||||
export interface BaseApiAccountJSON {
|
export interface BaseApiAccountJSON {
|
||||||
acct: string;
|
acct: string;
|
||||||
@@ -23,6 +43,7 @@ export interface BaseApiAccountJSON {
|
|||||||
indexable: boolean;
|
indexable: boolean;
|
||||||
display_name: string;
|
display_name: string;
|
||||||
emojis: ApiCustomEmojiJSON[];
|
emojis: ApiCustomEmojiJSON[];
|
||||||
|
feature_approval: ApiFeaturePolicyJSON;
|
||||||
fields: ApiAccountFieldJSON[];
|
fields: ApiAccountFieldJSON[];
|
||||||
followers_count: number;
|
followers_count: number;
|
||||||
following_count: number;
|
following_count: number;
|
||||||
|
|||||||
@@ -129,7 +129,11 @@ export const CollectionAccounts: React.FC<{
|
|||||||
accountIds: suggestedAccountIds,
|
accountIds: suggestedAccountIds,
|
||||||
isLoading: isLoadingSuggestions,
|
isLoading: isLoadingSuggestions,
|
||||||
searchAccounts,
|
searchAccounts,
|
||||||
} = useSearchAccounts();
|
} = useSearchAccounts({
|
||||||
|
filterResults: (account) =>
|
||||||
|
// Only suggest accounts who allow being featured/recommended
|
||||||
|
account.feature_approval.current_user === 'automatic',
|
||||||
|
});
|
||||||
|
|
||||||
const suggestedItems = suggestedAccountIds.map((id) => ({
|
const suggestedItems = suggestedAccountIds.map((id) => ({
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import { useAppDispatch } from 'mastodon/store';
|
|||||||
export function useSearchAccounts({
|
export function useSearchAccounts({
|
||||||
resetOnInputClear = true,
|
resetOnInputClear = true,
|
||||||
onSettled,
|
onSettled,
|
||||||
|
filterResults,
|
||||||
}: {
|
}: {
|
||||||
onSettled?: (value: string) => void;
|
onSettled?: (value: string) => void;
|
||||||
|
filterResults?: (account: ApiAccountJSON) => boolean;
|
||||||
resetOnInputClear?: boolean;
|
resetOnInputClear?: boolean;
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
@@ -49,8 +51,9 @@ export function useSearchAccounts({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
dispatch(importFetchedAccounts(data));
|
const accounts = filterResults ? data.filter(filterResults) : data;
|
||||||
setAccountIds(data.map((a) => a.id));
|
dispatch(importFetchedAccounts(accounts));
|
||||||
|
setAccountIds(accounts.map((a) => a.id));
|
||||||
setLoadingState('idle');
|
setLoadingState('idle');
|
||||||
onSettled?.(value);
|
onSettled?.(value);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ export const accountDefaultValues: AccountShape = {
|
|||||||
display_name: '',
|
display_name: '',
|
||||||
display_name_html: '',
|
display_name_html: '',
|
||||||
emojis: ImmutableList<CustomEmoji>(),
|
emojis: ImmutableList<CustomEmoji>(),
|
||||||
|
feature_approval: {
|
||||||
|
automatic: [],
|
||||||
|
manual: [],
|
||||||
|
current_user: 'missing',
|
||||||
|
},
|
||||||
fields: ImmutableList<AccountField>(),
|
fields: ImmutableList<AccountField>(),
|
||||||
group: false,
|
group: false,
|
||||||
header: '',
|
header: '',
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ export const accountFactory: FactoryFunction<ApiAccountJSON> = ({
|
|||||||
created_at: '2023-01-01T00:00:00.000Z',
|
created_at: '2023-01-01T00:00:00.000Z',
|
||||||
discoverable: true,
|
discoverable: true,
|
||||||
emojis: [],
|
emojis: [],
|
||||||
|
feature_approval: {
|
||||||
|
automatic: [],
|
||||||
|
manual: [],
|
||||||
|
current_user: 'missing',
|
||||||
|
},
|
||||||
fields: [],
|
fields: [],
|
||||||
followers_count: 0,
|
followers_count: 0,
|
||||||
following_count: 0,
|
following_count: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user