From 08822a32d8d1fb38b786f98d8e9ff44bdf573af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Mon, 2 Jun 2025 21:38:15 +0200 Subject: [PATCH] pl-api: status bite notification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- packages/pl-api/lib/client.ts | 2 +- packages/pl-api/lib/entities/notification.ts | 10 ++++++++- packages/pl-api/package.json | 2 +- packages/pl-fe/package.json | 2 +- .../notifications/components/notification.tsx | 21 ++++++++++++++++--- packages/pl-fe/src/locales/en.json | 2 +- packages/pl-fe/yarn.lock | 8 +++---- 7 files changed, 35 insertions(+), 12 deletions(-) diff --git a/packages/pl-api/lib/client.ts b/packages/pl-api/lib/client.ts index 223c13331..9097a03ce 100644 --- a/packages/pl-api/lib/client.ts +++ b/packages/pl-api/lib/client.ts @@ -481,7 +481,7 @@ class PlApiClient { return accounts; }, {})), statuses: Object.values(items.reduce>((statuses, notification) => { - if ('status' in notification) statuses[notification.status.id] = notification.status; + if ('status' in notification && notification.status) statuses[notification.status.id] = notification.status; return statuses; }, {})), notification_groups: notificationGroups, diff --git a/packages/pl-api/lib/entities/notification.ts b/packages/pl-api/lib/entities/notification.ts index e1003f773..fc6dedbe8 100644 --- a/packages/pl-api/lib/entities/notification.ts +++ b/packages/pl-api/lib/entities/notification.ts @@ -22,7 +22,7 @@ const baseNotificationSchema = v.object({ const accountNotificationSchema = v.object({ ...baseNotificationSchema.entries, - type: v.picklist(['follow', 'follow_request', 'admin.sign_up', 'bite']), + type: v.picklist(['follow', 'follow_request', 'admin.sign_up']), }); const mentionNotificationSchema = v.object({ @@ -83,6 +83,12 @@ const eventParticipationRequestNotificationSchema = v.object({ participation_message: v.fallback(v.nullable(v.string()), null), }); +const biteNotificationSchema = v.object({ + ...baseNotificationSchema.entries, + type: v.literal('bite'), + status: v.fallback(v.nullable(statusSchema), null), +}); + /** * @category Schemas * @see {@link https://docs.joinmastodon.org/entities/Notification/} @@ -108,6 +114,7 @@ const notificationSchema: v.BaseSchema> emojiReactionNotificationSchema, chatMentionNotificationSchema, eventParticipationRequestNotificationSchema, + biteNotificationSchema, ])) as any; /** @@ -124,6 +131,7 @@ type Notification = v.InferOutput< | typeof emojiReactionNotificationSchema | typeof chatMentionNotificationSchema | typeof eventParticipationRequestNotificationSchema +| typeof biteNotificationSchema >; export { notificationSchema, type Notification }; diff --git a/packages/pl-api/package.json b/packages/pl-api/package.json index 439ca96a8..9c6785fd5 100644 --- a/packages/pl-api/package.json +++ b/packages/pl-api/package.json @@ -1,6 +1,6 @@ { "name": "pl-api", - "version": "1.0.0-rc.75", + "version": "1.0.0-rc.76", "type": "module", "homepage": "https://github.com/mkljczk/pl-fe/tree/develop/packages/pl-api", "repository": { diff --git a/packages/pl-fe/package.json b/packages/pl-fe/package.json index 30efdaee4..685b537c3 100644 --- a/packages/pl-fe/package.json +++ b/packages/pl-fe/package.json @@ -105,7 +105,7 @@ "multiselect-react-dropdown": "^2.0.25", "mutative": "^1.1.0", "path-browserify": "^1.0.1", - "pl-api": "^1.0.0-rc.75", + "pl-api": "^1.0.0-rc.76", "postcss": "^8.5.3", "process": "^0.11.10", "punycode": "^2.1.1", diff --git a/packages/pl-fe/src/features/notifications/components/notification.tsx b/packages/pl-fe/src/features/notifications/components/notification.tsx index 5358efc4a..d7a6bd2e6 100644 --- a/packages/pl-fe/src/features/notifications/components/notification.tsx +++ b/packages/pl-fe/src/features/notifications/components/notification.tsx @@ -142,7 +142,7 @@ const messages: Record = defineMe }, bite: { id: 'notification.bite', - defaultMessage: '{name} has bit you', + defaultMessage: '{name} has bit {hasStatus, plural, =0 {you} other {your status}}', }, reply: { id: 'notification.reply', @@ -156,6 +156,7 @@ const buildMessage = ( accounts: Array>, targetName: string, instanceTitle: string, + hasStatus: boolean, ): React.ReactNode => { const renderedAccounts = accounts.slice(0, 2).map(account => buildLink(account)).filter(Boolean); @@ -175,6 +176,7 @@ const buildMessage = ( targetName, instance: instanceTitle, count: accounts.length, + hasStatus: +hasStatus, }); }; @@ -188,7 +190,7 @@ interface INotification { } const getNotificationStatus = (n: Pick & ({ status: StatusEntity } | { })): StatusEntity | null => { - if (['mention', 'status', 'reblog', 'favourite', 'poll', 'update', 'emoji_reaction', 'event_reminder', 'participation_accepted', 'participation_request'].includes(n.type)) + if (['mention', 'status', 'reblog', 'favourite', 'poll', 'update', 'emoji_reaction', 'event_reminder', 'participation_accepted', 'participation_request', 'bite'].includes(n.type)) // @ts-ignore return n.status; return null; @@ -338,6 +340,19 @@ const Notification: React.FC = (props) => { }; const renderContent = () => { + if (type === 'bite' && status) { + return ( + + ); + } + switch (type) { case 'follow': return ( @@ -401,7 +416,7 @@ const Notification: React.FC = (props) => { const targetName = notification.type === 'move' ? notification.target.acct : ''; const message: React.ReactNode = account && typeof account === 'object' - ? buildMessage(intl, displayedType, accounts, targetName, instance.title) + ? buildMessage(intl, displayedType, accounts, targetName, instance.title, !!status) : null; const ariaLabel = ( diff --git a/packages/pl-fe/src/locales/en.json b/packages/pl-fe/src/locales/en.json index e1256da31..d3dc8e147 100644 --- a/packages/pl-fe/src/locales/en.json +++ b/packages/pl-fe/src/locales/en.json @@ -1203,7 +1203,7 @@ "new_group_panel.title": "Create group", "notification.admin.report": "{name} reported {target}", "notification.admin.sign_up": "{name} signed up", - "notification.bite": "{name} has bit you", + "notification.bite": "{name} has bit {hasStatus, plural, =0 {you} other {your status}}", "notification.favourite": "{name} liked your post", "notification.follow": "{name} followed you", "notification.follow_request": "{name} has requested to follow you", diff --git a/packages/pl-fe/yarn.lock b/packages/pl-fe/yarn.lock index d10927adb..21a088538 100644 --- a/packages/pl-fe/yarn.lock +++ b/packages/pl-fe/yarn.lock @@ -6875,10 +6875,10 @@ pkg-dir@^4.1.0: dependencies: find-up "^4.0.0" -pl-api@^1.0.0-rc.75: - version "1.0.0-rc.75" - resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.75.tgz#ce01dfc60354d2e1dcdf8b8430c6018b9a28ee26" - integrity sha512-aiqSPsQ8HIa+SBs2gbAqNVcIhqSbz+DBlH9rfLHwzwpomEQ6BcRk10+VpdiGuQexXwcdz3rvp7BlRpugu+PIKw== +pl-api@^1.0.0-rc.76: + version "1.0.0-rc.76" + resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.76.tgz#f15622093229578ca474037591ef41e4b22c3974" + integrity sha512-Gm/H4yr4CdCUE8IIGfR6xpoWPsrN72ZQ18DmLaZQZAff9jHApGne91PFYfH4TgGzcwtAAKYDcz/78TILI0LCkw== dependencies: blurhash "^2.0.5" http-link-header "^1.1.3"