pl-fe: allow managing mention_policy on mitra

Signed-off-by: Nicole Mikołajczyk <git@mkljczk.pl>
This commit is contained in:
Nicole Mikołajczyk
2025-04-07 15:59:47 +02:00
parent 64c9cbbde2
commit 17b907aeb3
8 changed files with 55 additions and 8 deletions

View File

@ -54,8 +54,8 @@ const preprocessAccount = v.transform((account: any) => {
...(account.role?.permissions ? {
is_admin: (account.role?.permissions & 0x1) === 0x1,
} : {}),
ap_id: account.pleroma?.ap_id ?? account.actor_id,
...(pick(account.pleroma || {}, [
'ap_id',
'background_image',
'relationship',
'is_moderator',
@ -158,6 +158,9 @@ const baseAccountSchema = v.object({
pronouns: v.fallback(v.array(v.string()), []),
mention_policy: v.fallback(v.picklist(['none', 'only_known', 'only_followers']), 'none'),
subscribers_count: v.fallback(v.number(), 0),
is_cat: v.fallback(v.boolean(), false),
speak_as_cat: v.fallback(v.boolean(), false),

View File

@ -250,6 +250,13 @@ const getFeatures = (instance: Instance) => {
v.software === WORDPRESS,
]),
/**
* @see PATCH /api/v1/accounts/update_credentials
*/
accountMentionPolicy: any([
v.software === MITRA,
]),
/**
* Move followers to a different ActivityPub account.
* @see POST /api/pleroma/move_account

View File

@ -133,6 +133,12 @@ interface UpdateCredentialsParams {
is_cat?: boolean;
/** Whether the user speaks as a cat */
speak_as_cat?: boolean;
/**
* Mention policy
* Required features{@link Features['accountMentionPolicy']}.
*/
mention_policy?: 'none' | 'only_known' | 'only_contacts';
}
/**

View File

@ -1,6 +1,6 @@
{
"name": "pl-api",
"version": "1.0.0-rc.41",
"version": "1.0.0-rc.42",
"type": "module",
"homepage": "https://github.com/mkljczk/pl-fe/tree/develop/packages/pl-api",
"repository": {

View File

@ -104,7 +104,7 @@
"multiselect-react-dropdown": "^2.0.25",
"mutative": "^1.1.0",
"path-browserify": "^1.0.1",
"pl-api": "^1.0.0-rc.40",
"pl-api": "^1.0.0-rc.42",
"postcss": "^8.4.49",
"process": "^0.11.10",
"punycode": "^2.1.1",

View File

@ -26,6 +26,8 @@ import { useOwnAccount } from 'pl-fe/hooks/use-own-account';
import toast from 'pl-fe/toast';
import { isDefaultAvatar, isDefaultHeader } from 'pl-fe/utils/accounts';
import { SelectDropdown } from '../forms';
import AvatarPicker from './components/avatar-picker';
import HeaderPicker from './components/header-picker';
@ -55,6 +57,9 @@ const messages = defineMessages({
displayNamePlaceholder: { id: 'edit_profile.fields.display_name_placeholder', defaultMessage: 'Name' },
locationPlaceholder: { id: 'edit_profile.fields.location_placeholder', defaultMessage: 'Location' },
cancel: { id: 'common.cancel', defaultMessage: 'Cancel' },
mentionPolicyNone: { id: 'edit_profile.fields.mention_policy.none', defaultMessage: 'Everybody' },
mentionPolicyOnlyKnown: { id: 'edit_profile.fields.mention_policy.only_known', defaultMessage: 'Everybody except new accounts' },
mentionPolicyOnlyContacts: { id: 'edit_profile.fields.mention_policy.only_contacts', defaultMessage: 'People I follow and my followers' },
});
/**
@ -127,6 +132,8 @@ interface AccountCredentials {
is_cat?: boolean;
/** Whether the user speaks as a cat. */
speak_as_cat?: boolean;
/** Mention policy */
mention_policy?: string;
}
/** Convert an account into an update_credentials request object. */
@ -134,7 +141,7 @@ const accountToCredentials = (account: Account): AccountCredentials => {
const hideNetwork = hidesNetwork(account);
return {
...(pick(account, ['discoverable', 'bot', 'display_name', 'locked', 'location', 'avatar_description', 'header_description', 'enable_rss', 'hide_collections', 'is_cat', 'speak_as_cat'])),
...(pick(account, ['discoverable', 'bot', 'display_name', 'locked', 'location', 'avatar_description', 'header_description', 'enable_rss', 'hide_collections', 'is_cat', 'speak_as_cat', 'mention_policy'])),
note: account.__meta.source?.note ?? '',
fields_attributes: [...account.__meta.source?.fields ?? []],
stranger_notifications: account.__meta.pleroma?.notification_settings?.block_from_strangers === true,
@ -455,6 +462,25 @@ const EditProfile: React.FC = () => {
</ListItem>
</>
)}
{features.accountMentionPolicy && (
<ListItem
label={<FormattedMessage id='preferences.fields.mention_policy_label' defaultMessage='Accept mentions from' />}
hint={<FormattedMessage id='preferences.hints.mention_policy' defaultMessage='Applies to direct messages and public posts' />}
>
<SelectDropdown
key={data.mention_policy ? 'true' : 'false'}
className='max-w-fit'
items={{
none: intl.formatMessage(messages.mentionPolicyNone),
only_known: intl.formatMessage(messages.mentionPolicyOnlyKnown),
only_contacts: intl.formatMessage(messages.mentionPolicyOnlyContacts),
}}
defaultValue={data.mention_policy}
onChange={(event: React.ChangeEvent<HTMLSelectElement>) => handleFieldChange('mention_policy')(event.target.value)}
/>
</ListItem>
)}
</List>
{features.profileFields && (

View File

@ -655,6 +655,9 @@
"edit_profile.fields.location_label": "Location",
"edit_profile.fields.location_placeholder": "Location",
"edit_profile.fields.locked_label": "Lock account",
"edit_profile.fields.mention_policy.none": "Everybody",
"edit_profile.fields.mention_policy.only_contacts": "People I follow and my followers",
"edit_profile.fields.mention_policy.only_known": "Everybody except new accounts",
"edit_profile.fields.meta_fields.content_placeholder": "Content",
"edit_profile.fields.meta_fields.label_placeholder": "Label",
"edit_profile.fields.meta_fields.label_placeholder.first": "Label (e.g. pronouns)",
@ -1274,6 +1277,7 @@
"preferences.fields.known_languages_label": "Languages you know",
"preferences.fields.language_label": "Display language",
"preferences.fields.media_display_label": "Sensitive content",
"preferences.fields.mention_policy_label": "Accept mentions from",
"preferences.fields.missing_description_modal_label": "Show confirmation dialog before sending a post without media descriptions",
"preferences.fields.preserve_spoilers_label": "Preserve content warning when replying",
"preferences.fields.privacy_label": "Default post privacy",
@ -1286,6 +1290,7 @@
"preferences.fields.unfollow_modal_label": "Show confirmation dialog before unfollowing someone",
"preferences.fields.wrench_label": "Display wrench reaction button",
"preferences.hints.demetricator": "Decrease social media anxiety by hiding all numbers from the site.",
"preferences.hints.mention_policy": "Applies to direct messages and public posts",
"preferences.notifications.advanced": "Show all notification categories",
"preferences.options.brand_color": "Base color",
"preferences.options.content_type_html": "HTML",

View File

@ -6833,10 +6833,10 @@ pkg-dir@^4.1.0:
dependencies:
find-up "^4.0.0"
pl-api@^1.0.0-rc.40:
version "1.0.0-rc.40"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.40.tgz#ae2596a15d28a8662d1a5de083b9596a8b6c00b3"
integrity sha512-4X7va+KXOcXAOD02W+4e6NHgD+pbxhIoeHxT9rcWdHDjxmWiCapBoxxxa88ASPZKZFoiXZAktsFRSEs9yM3Z6A==
pl-api@^1.0.0-rc.42:
version "1.0.0-rc.42"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.42.tgz#1353c17e703dc11a6aafefd2886f4dba690e0001"
integrity sha512-C5vy/lNJc26VoiGJh9qRoDESM4IYd04OMnrdxUP2TxXL1liCwykDV+VdDH4aN/sKPzNNo07ZerIVGaZd/Mx42g==
dependencies:
blurhash "^2.0.5"
http-link-header "^1.1.3"