Support ditto:name_grant notification type

environments/review-main-yi2y9f/deployments/4692^2
Alex Gleason 2024-06-09 17:00:41 -05:00
rodzic 0e846784df
commit def7cc4d14
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
5 zmienionych plików z 48 dodań i 17 usunięć

Wyświetl plik

@ -129,8 +129,8 @@ interface AccountCredentials {
birthday?: string; birthday?: string;
/** Nostr NIP-05 identifier. */ /** Nostr NIP-05 identifier. */
nip05?: string; nip05?: string;
/** /**
* Lightning address. * Lightning address.
* https://github.com/lnurl/luds/blob/luds/16.md * https://github.com/lnurl/luds/blob/luds/16.md
*/ */
lud16?: string; lud16?: string;

Wyświetl plik

@ -1,19 +1,21 @@
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';
import { defineMessages, useIntl, FormattedMessage, IntlShape, MessageDescriptor, defineMessage } from 'react-intl'; import { defineMessages, useIntl, IntlShape, MessageDescriptor, defineMessage, FormattedMessage } from 'react-intl';
import { Link, useHistory } from 'react-router-dom'; import { Link, useHistory } from 'react-router-dom';
import { mentionCompose } from 'soapbox/actions/compose'; import { mentionCompose } from 'soapbox/actions/compose';
import { reblog, favourite, unreblog, unfavourite } from 'soapbox/actions/interactions'; import { reblog, favourite, unreblog, unfavourite } from 'soapbox/actions/interactions';
import { patchMe } from 'soapbox/actions/me';
import { openModal } from 'soapbox/actions/modals'; import { openModal } from 'soapbox/actions/modals';
import { getSettings } from 'soapbox/actions/settings'; import { getSettings } from 'soapbox/actions/settings';
import { hideStatus, revealStatus } from 'soapbox/actions/statuses'; import { hideStatus, revealStatus } from 'soapbox/actions/statuses';
import Icon from 'soapbox/components/icon'; import Icon from 'soapbox/components/icon';
import { HStack, Text, Emoji } from 'soapbox/components/ui'; import { HStack, Text, Emoji, Button, Stack } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account-container'; import AccountContainer from 'soapbox/containers/account-container';
import StatusContainer from 'soapbox/containers/status-container'; import StatusContainer from 'soapbox/containers/status-container';
import { HotKeys } from 'soapbox/features/ui/components/hotkeys'; import { HotKeys } from 'soapbox/features/ui/components/hotkeys';
import { useAppDispatch, useAppSelector, useInstance } from 'soapbox/hooks'; import { useAppDispatch, useAppSelector, useInstance } from 'soapbox/hooks';
import { makeGetNotification } from 'soapbox/selectors'; import { makeGetNotification } from 'soapbox/selectors';
import toast from 'soapbox/toast';
import { NotificationType, validType } from 'soapbox/utils/notification'; import { NotificationType, validType } from 'soapbox/utils/notification';
import type { ScrollPosition } from 'soapbox/components/status'; import type { ScrollPosition } from 'soapbox/components/status';
@ -56,6 +58,7 @@ const icons: Record<NotificationType, string> = {
'pleroma:event_reminder': require('@tabler/icons/outline/calendar-time.svg'), 'pleroma:event_reminder': require('@tabler/icons/outline/calendar-time.svg'),
'pleroma:participation_request': require('@tabler/icons/outline/calendar-event.svg'), 'pleroma:participation_request': require('@tabler/icons/outline/calendar-event.svg'),
'pleroma:participation_accepted': require('@tabler/icons/outline/calendar-event.svg'), 'pleroma:participation_accepted': require('@tabler/icons/outline/calendar-event.svg'),
'ditto:name_grant': require('@tabler/icons/outline/user-check.svg'),
}; };
const nameMessage = defineMessage({ const nameMessage = defineMessage({
@ -63,7 +66,7 @@ const nameMessage = defineMessage({
defaultMessage: '{link}{others}', defaultMessage: '{link}{others}',
}); });
const messages: Record<NotificationType, MessageDescriptor> = defineMessages({ const notificationMessages: Record<NotificationType, MessageDescriptor> = defineMessages({
follow: { follow: {
id: 'notification.follow', id: 'notification.follow',
defaultMessage: '{name} followed you', defaultMessage: '{name} followed you',
@ -132,29 +135,32 @@ const messages: Record<NotificationType, MessageDescriptor> = defineMessages({
id: 'notification.pleroma:participation_accepted', id: 'notification.pleroma:participation_accepted',
defaultMessage: 'You were accepted to join the event', defaultMessage: 'You were accepted to join the event',
}, },
'ditto:name_grant': {
id: 'notification.ditto:name_grant',
defaultMessage: 'You were granted the name {acct}',
},
});
const messages = defineMessages({
updateNameSuccess: { id: 'notification.update_name_success', defaultMessage: 'Name updated successfully' },
}); });
const buildMessage = ( const buildMessage = (
intl: IntlShape, intl: IntlShape,
type: NotificationType, type: NotificationType,
account: AccountEntity, account: AccountEntity,
totalCount: number | null, acct: string | undefined,
targetName: string, targetName: string,
instanceTitle: string, instanceTitle: string,
): React.ReactNode => { ): React.ReactNode => {
const link = buildLink(account); const link = buildLink(account);
const name = intl.formatMessage(nameMessage, { const name = intl.formatMessage(nameMessage, {
link, link,
others: totalCount && totalCount > 0 ? ( others: '',
<FormattedMessage
id='notification.others'
defaultMessage='+ {count, plural, one {# other} other {# others}}'
values={{ count: totalCount - 1 }}
/>
) : '',
}); });
return intl.formatMessage(messages[type], { return intl.formatMessage(notificationMessages[type], {
acct,
name, name,
targetName, targetName,
instance: instanceTitle, instance: instanceTitle,
@ -274,6 +280,11 @@ const Notification: React.FC<INotification> = (props) => {
} }
}; };
const updateName = async (name: string) => {
await dispatch(patchMe({ nip05: name }));
toast.success(messages.updateNameSuccess);
};
const renderIcon = (): React.ReactNode => { const renderIcon = (): React.ReactNode => {
if (type === 'pleroma:emoji_reaction' && notification.emoji) { if (type === 'pleroma:emoji_reaction' && notification.emoji) {
return ( return (
@ -349,19 +360,32 @@ const Notification: React.FC<INotification> = (props) => {
showGroup={false} showGroup={false}
/> />
) : null; ) : null;
case 'ditto:name_grant':
return (
<Stack className='p-4'>
<Button onClick={() => updateName(notification.name)}>
<FormattedMessage
id='notification.set_name' defaultMessage='Set name to {name}'
values={{ name: notification.name }}
/>
</Button>
</Stack>
);
default: default:
return null; return null;
} }
}; };
const acct = notification.name;
const targetName = notification.target && typeof notification.target === 'object' ? notification.target.acct : ''; const targetName = notification.target && typeof notification.target === 'object' ? notification.target.acct : '';
const message: React.ReactNode = validType(type) && account && typeof account === 'object' ? buildMessage(intl, type, account, notification.total_count, targetName, instance.title) : null; const message: React.ReactNode = validType(type) && account && typeof account === 'object' ? buildMessage(intl, type, account, acct, targetName, instance.title) : null;
const ariaLabel = validType(type) ? ( const ariaLabel = validType(type) ? (
notificationForScreenReader( notificationForScreenReader(
intl, intl,
intl.formatMessage(messages[type], { intl.formatMessage(notificationMessages[type], {
acct,
name: account && typeof account === 'object' ? account.acct : '', name: account && typeof account === 'object' ? account.acct : '',
targetName, targetName,
}), }),

Wyświetl plik

@ -19,6 +19,7 @@ export const NotificationRecord = ImmutableRecord({
emoji: null as string | null, // pleroma:emoji_reaction emoji: null as string | null, // pleroma:emoji_reaction
emoji_url: null as string | null, // pleroma:emoji_reaction emoji_url: null as string | null, // pleroma:emoji_reaction
id: '', id: '',
name: '', // ditto:name_grant
status: null as EmbeddedEntity<Status>, status: null as EmbeddedEntity<Status>,
target: null as EmbeddedEntity<Account>, // move target: null as EmbeddedEntity<Account>, // move
type: '', type: '',

Wyświetl plik

@ -10,7 +10,6 @@ const baseNotificationSchema = z.object({
created_at: z.string().datetime().catch(new Date().toUTCString()), created_at: z.string().datetime().catch(new Date().toUTCString()),
id: z.string(), id: z.string(),
type: z.string(), type: z.string(),
total_count: z.number().optional().catch(undefined), // TruthSocial
}); });
const mentionNotificationSchema = baseNotificationSchema.extend({ const mentionNotificationSchema = baseNotificationSchema.extend({
@ -82,6 +81,11 @@ const participationAcceptedNotificationSchema = baseNotificationSchema.extend({
status: statusSchema, status: statusSchema,
}); });
const nameGrantNotificationSchema = baseNotificationSchema.extend({
type: z.literal('ditto:name_grant'),
name: z.string(),
});
const notificationSchema = z.discriminatedUnion('type', [ const notificationSchema = z.discriminatedUnion('type', [
mentionNotificationSchema, mentionNotificationSchema,
statusNotificationSchema, statusNotificationSchema,
@ -97,6 +101,7 @@ const notificationSchema = z.discriminatedUnion('type', [
eventReminderNotificationSchema, eventReminderNotificationSchema,
participationRequestNotificationSchema, participationRequestNotificationSchema,
participationAcceptedNotificationSchema, participationAcceptedNotificationSchema,
nameGrantNotificationSchema,
]); ]);
type Notification = z.infer<typeof notificationSchema>; type Notification = z.infer<typeof notificationSchema>;

Wyświetl plik

@ -17,6 +17,7 @@ const NOTIFICATION_TYPES = [
'pleroma:event_reminder', 'pleroma:event_reminder',
'pleroma:participation_request', 'pleroma:participation_request',
'pleroma:participation_accepted', 'pleroma:participation_accepted',
'ditto:name_grant',
] as const; ] as const;
/** Notification types to exclude from the "All" filter by default. */ /** Notification types to exclude from the "All" filter by default. */