diff --git a/apps/admin-x-activitypub/package.json b/apps/admin-x-activitypub/package.json index 29ce99717b..7c4026566b 100644 --- a/apps/admin-x-activitypub/package.json +++ b/apps/admin-x-activitypub/package.json @@ -1,6 +1,6 @@ { "name": "@tryghost/admin-x-activitypub", - "version": "0.3.14", + "version": "0.3.15", "license": "MIT", "repository": { "type": "git", diff --git a/apps/admin-x-activitypub/src/components/Inbox.tsx b/apps/admin-x-activitypub/src/components/Inbox.tsx index fcb6e1eb3d..73cb641b2b 100644 --- a/apps/admin-x-activitypub/src/components/Inbox.tsx +++ b/apps/admin-x-activitypub/src/components/Inbox.tsx @@ -6,6 +6,7 @@ import MainNavigation from './navigation/MainNavigation'; import NiceModal from '@ebay/nice-modal-react'; import React, {useEffect, useRef} from 'react'; import ViewProfileModal from './global/ViewProfileModal'; +import getName from '../utils/get-name'; import getUsername from '../utils/get-username'; import {Button, Heading, LoadingIndicator} from '@tryghost/admin-x-design-system'; import {handleViewContent} from '../utils/content-handlers'; @@ -123,7 +124,7 @@ const Inbox: React.FC = ({}) => {
- {actor.name || actor.preferredUsername || 'Unknown'} + {getName(actor)}
{getUsername(actor)}
diff --git a/apps/admin-x-activitypub/src/components/Profile.tsx b/apps/admin-x-activitypub/src/components/Profile.tsx index ceab6edf52..5b5608e6bb 100644 --- a/apps/admin-x-activitypub/src/components/Profile.tsx +++ b/apps/admin-x-activitypub/src/components/Profile.tsx @@ -4,6 +4,7 @@ import FeedItem from './feed/FeedItem'; import MainNavigation from './navigation/MainNavigation'; import NiceModal from '@ebay/nice-modal-react'; import React, {useEffect, useRef, useState} from 'react'; +import getName from '../utils/get-name'; import getUsername from '../utils/get-username'; import {ActorProperties} from '@tryghost/admin-x-framework/api/activitypub'; @@ -187,7 +188,7 @@ const Profile: React.FC = ({}) => {
- {item.name || item.preferredUsername || 'Unknown'} + {getName(item)}
{getUsername(item)}
@@ -235,7 +236,7 @@ const Profile: React.FC = ({}) => {
- {item.name || item.preferredUsername || 'Unknown'} + {item.name || getName(item) || 'Unknown'}
{getUsername(item)}
diff --git a/apps/admin-x-activitypub/src/components/global/ViewProfileModal.tsx b/apps/admin-x-activitypub/src/components/global/ViewProfileModal.tsx index c7b3a3de79..0b696918e7 100644 --- a/apps/admin-x-activitypub/src/components/global/ViewProfileModal.tsx +++ b/apps/admin-x-activitypub/src/components/global/ViewProfileModal.tsx @@ -13,6 +13,7 @@ import APAvatar from '../global/APAvatar'; import ActivityItem from '../activities/ActivityItem'; import FeedItem from '../feed/FeedItem'; import FollowButton from '../global/FollowButton'; +import getName from '../../utils/get-name'; import getUsername from '../../utils/get-username'; const noop = () => {}; @@ -86,7 +87,7 @@ const ActorList: React.FC = ({
- {actor.name || actor.preferredUsername || 'Unknown'} + {getName(actor)}
{getUsername(actor)}
diff --git a/apps/admin-x-activitypub/src/utils/get-name.ts b/apps/admin-x-activitypub/src/utils/get-name.ts new file mode 100644 index 0000000000..88714b83a2 --- /dev/null +++ b/apps/admin-x-activitypub/src/utils/get-name.ts @@ -0,0 +1,16 @@ +export default function getName(actor: {name: unknown, preferredUsername: unknown}): string { + if (typeof actor.name === 'string') { + return actor.name; + } + if (typeof actor.preferredUsername === 'string') { + return actor.preferredUsername; + } + if (typeof actor.preferredUsername === 'object' && actor.preferredUsername !== null) { + if ('@value' in actor.preferredUsername) { + if (typeof actor.preferredUsername['@value'] === 'string') { + return actor.preferredUsername['@value']; + } + } + } + return 'Unknown'; +}