Support Mitra notification subtype
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
6b7082f8fe
commit
6b6b9cc40a
6 changed files with 26 additions and 12 deletions
|
@ -24,8 +24,14 @@ const accountNotificationSchema = baseNotificationSchema.extend({
|
||||||
type: z.enum(['follow', 'follow_request', 'admin.sign_up', 'bite']),
|
type: z.enum(['follow', 'follow_request', 'admin.sign_up', 'bite']),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mentionNotificationSchema = baseNotificationSchema.extend({
|
||||||
|
type: z.literal('mention'),
|
||||||
|
subtype: z.enum(['reply']).nullable().catch(null),
|
||||||
|
status: statusSchema,
|
||||||
|
});
|
||||||
|
|
||||||
const statusNotificationSchema = baseNotificationSchema.extend({
|
const statusNotificationSchema = baseNotificationSchema.extend({
|
||||||
type: z.enum(['mention', 'status', 'reblog', 'favourite', 'poll', 'update', 'event_reminder']),
|
type: z.enum(['status', 'reblog', 'favourite', 'poll', 'update', 'event_reminder']),
|
||||||
status: statusSchema,
|
status: statusSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -77,6 +83,7 @@ const notificationSchema: z.ZodType<Notification> = z.preprocess((notification:
|
||||||
: notification.type?.replace(/^pleroma:/, ''),
|
: notification.type?.replace(/^pleroma:/, ''),
|
||||||
}), z.discriminatedUnion('type', [
|
}), z.discriminatedUnion('type', [
|
||||||
accountNotificationSchema,
|
accountNotificationSchema,
|
||||||
|
mentionNotificationSchema,
|
||||||
statusNotificationSchema,
|
statusNotificationSchema,
|
||||||
reportNotificationSchema,
|
reportNotificationSchema,
|
||||||
severedRelationshipNotificationSchema,
|
severedRelationshipNotificationSchema,
|
||||||
|
@ -89,6 +96,7 @@ const notificationSchema: z.ZodType<Notification> = z.preprocess((notification:
|
||||||
|
|
||||||
type Notification = z.infer<
|
type Notification = z.infer<
|
||||||
| typeof accountNotificationSchema
|
| typeof accountNotificationSchema
|
||||||
|
| typeof mentionNotificationSchema
|
||||||
| typeof statusNotificationSchema
|
| typeof statusNotificationSchema
|
||||||
| typeof reportNotificationSchema
|
| typeof reportNotificationSchema
|
||||||
| typeof severedRelationshipNotificationSchema
|
| typeof severedRelationshipNotificationSchema
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "pl-api",
|
"name": "pl-api",
|
||||||
"version": "0.0.31",
|
"version": "0.0.32",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"homepage": "https://github.com/mkljczk/pl-fe/tree/fork/packages/pl-api",
|
"homepage": "https://github.com/mkljczk/pl-fe/tree/fork/packages/pl-api",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -134,7 +134,7 @@
|
||||||
"multiselect-react-dropdown": "^2.0.25",
|
"multiselect-react-dropdown": "^2.0.25",
|
||||||
"object-to-formdata": "^4.5.1",
|
"object-to-formdata": "^4.5.1",
|
||||||
"path-browserify": "^1.0.1",
|
"path-browserify": "^1.0.1",
|
||||||
"pl-api": "^0.0.31",
|
"pl-api": "^0.0.32",
|
||||||
"postcss": "^8.4.29",
|
"postcss": "^8.4.29",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"punycode": "^2.1.1",
|
"punycode": "^2.1.1",
|
||||||
|
|
|
@ -40,7 +40,7 @@ const buildLink = (account: Pick<Account, 'acct' | 'display_name_html'>): JSX.El
|
||||||
</bdi>
|
</bdi>
|
||||||
);
|
);
|
||||||
|
|
||||||
const icons: Partial<Record<NotificationType, string>> = {
|
const icons: Partial<Record<NotificationType | 'reply', string>> = {
|
||||||
follow: require('@tabler/icons/outline/user-plus.svg'),
|
follow: require('@tabler/icons/outline/user-plus.svg'),
|
||||||
follow_request: require('@tabler/icons/outline/user-plus.svg'),
|
follow_request: require('@tabler/icons/outline/user-plus.svg'),
|
||||||
mention: require('@tabler/icons/outline/at.svg'),
|
mention: require('@tabler/icons/outline/at.svg'),
|
||||||
|
@ -56,9 +56,10 @@ const icons: Partial<Record<NotificationType, string>> = {
|
||||||
participation_request: require('@tabler/icons/outline/calendar-event.svg'),
|
participation_request: require('@tabler/icons/outline/calendar-event.svg'),
|
||||||
participation_accepted: require('@tabler/icons/outline/calendar-event.svg'),
|
participation_accepted: require('@tabler/icons/outline/calendar-event.svg'),
|
||||||
bite: require('@tabler/icons/outline/pacman.svg'),
|
bite: require('@tabler/icons/outline/pacman.svg'),
|
||||||
|
reply: require('@tabler/icons/outline/corner-up-left.svg'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const messages: Record<NotificationType, MessageDescriptor> = defineMessages({
|
const messages: Record<NotificationType | 'reply', MessageDescriptor> = defineMessages({
|
||||||
follow: {
|
follow: {
|
||||||
id: 'notification.follow',
|
id: 'notification.follow',
|
||||||
defaultMessage: '{name} followed you',
|
defaultMessage: '{name} followed you',
|
||||||
|
@ -135,11 +136,15 @@ const messages: Record<NotificationType, MessageDescriptor> = defineMessages({
|
||||||
id: 'notification.bite',
|
id: 'notification.bite',
|
||||||
defaultMessage: '{name} has bit you',
|
defaultMessage: '{name} has bit you',
|
||||||
},
|
},
|
||||||
|
reply: {
|
||||||
|
id: 'notification.reply',
|
||||||
|
defaultMessage: '{name} replied to your post',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const buildMessage = (
|
const buildMessage = (
|
||||||
intl: IntlShape,
|
intl: IntlShape,
|
||||||
type: NotificationType,
|
type: NotificationType | 'reply',
|
||||||
accounts: Array<Pick<Account, 'acct' | 'display_name_html'>>,
|
accounts: Array<Pick<Account, 'acct' | 'display_name_html'>>,
|
||||||
targetName: string,
|
targetName: string,
|
||||||
instanceTitle: string,
|
instanceTitle: string,
|
||||||
|
@ -292,7 +297,7 @@ const Notification: React.FC<INotification> = (props) => {
|
||||||
} else if (icons[type]) {
|
} else if (icons[type]) {
|
||||||
return (
|
return (
|
||||||
<Icon
|
<Icon
|
||||||
src={icons[type]!}
|
src={icons[type === 'mention' ? notification.subtype || type : type]!}
|
||||||
className='flex-none text-primary-600 dark:text-primary-400'
|
className='flex-none text-primary-600 dark:text-primary-400'
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -362,7 +367,7 @@ const Notification: React.FC<INotification> = (props) => {
|
||||||
const targetName = notification.type === 'move' ? notification.target.acct : '';
|
const targetName = notification.type === 'move' ? notification.target.acct : '';
|
||||||
|
|
||||||
const message: React.ReactNode = account && typeof account === 'object'
|
const message: React.ReactNode = account && typeof account === 'object'
|
||||||
? buildMessage(intl, type, accounts, targetName, instance.title)
|
? buildMessage(intl, type === 'mention' ? notification.subtype || type : type, accounts, targetName, instance.title)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const ariaLabel = (
|
const ariaLabel = (
|
||||||
|
|
|
@ -1124,6 +1124,7 @@
|
||||||
"notification.pleroma:participation_request": "{name} wants to join your event",
|
"notification.pleroma:participation_request": "{name} wants to join your event",
|
||||||
"notification.poll": "A poll you have voted in has ended",
|
"notification.poll": "A poll you have voted in has ended",
|
||||||
"notification.reblog": "{name} reposted your post",
|
"notification.reblog": "{name} reposted your post",
|
||||||
|
"notification.reply": "{name} replied to your post",
|
||||||
"notification.severed_relationships": "Lost connections with {name}",
|
"notification.severed_relationships": "Lost connections with {name}",
|
||||||
"notification.status": "{name} just posted",
|
"notification.status": "{name} just posted",
|
||||||
"notification.update": "{name} edited a post you interacted with",
|
"notification.update": "{name} edited a post you interacted with",
|
||||||
|
|
|
@ -8240,10 +8240,10 @@ pkg-types@^1.0.3:
|
||||||
mlly "^1.2.0"
|
mlly "^1.2.0"
|
||||||
pathe "^1.1.0"
|
pathe "^1.1.0"
|
||||||
|
|
||||||
pl-api@^0.0.31:
|
pl-api@^0.0.32:
|
||||||
version "0.0.31"
|
version "0.0.32"
|
||||||
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.31.tgz#63720a2620c304e461cf758f566809b78d4ce080"
|
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-0.0.32.tgz#d6d86342c99c740bdb4e99a67ef249caede7390a"
|
||||||
integrity sha512-L0d7LveBpas9Et9tRePuCfcSb3nzEgbNTyVXbivV7Je+jwGCXnhXo7O7VMl+EnjjJKW+wlqfSer7Y+Db9UCXAw==
|
integrity sha512-uIh98+/5Z9CVoP5b77+tH2ETsSeLKmSXR0vmH7vkxQdjssrv139puy7jv7aYKnbOj2uqm3IDTCyYzI4q0KNFBQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
blurhash "^2.0.5"
|
blurhash "^2.0.5"
|
||||||
http-link-header "^1.1.3"
|
http-link-header "^1.1.3"
|
||||||
|
|
Loading…
Reference in a new issue