diff --git a/apps/admin-x-activitypub/src/components/ListIndex.tsx b/apps/admin-x-activitypub/src/components/ListIndex.tsx index 76c2b3e401..996533aa3c 100644 --- a/apps/admin-x-activitypub/src/components/ListIndex.tsx +++ b/apps/admin-x-activitypub/src/components/ListIndex.tsx @@ -16,7 +16,7 @@ const ActivityPubComponent: React.FC = () => { const {updateRoute} = useRouting(); // TODO: Replace with actual user ID - const {data: {orderedItems: activities = []} = {}} = useBrowseInboxForUser('index'); + const {data: {items: activities = []} = {}} = useBrowseInboxForUser('index'); const {data: {totalItems: followingCount = 0} = {}} = useBrowseFollowingForUser('index'); const {data: {totalItems: followersCount = 0} = {}} = useBrowseFollowersForUser('index'); diff --git a/apps/admin-x-activitypub/src/components/ViewFollowers.tsx b/apps/admin-x-activitypub/src/components/ViewFollowers.tsx index b1a92fda9a..bff12ef78c 100644 --- a/apps/admin-x-activitypub/src/components/ViewFollowers.tsx +++ b/apps/admin-x-activitypub/src/components/ViewFollowers.tsx @@ -1,8 +1,8 @@ import {} from '@tryghost/admin-x-framework/api/activitypub'; import NiceModal from '@ebay/nice-modal-react'; -import getUsernameFromFollowing from '../utils/get-username-from-following'; +import getUsername from '../utils/get-username'; import {Avatar, Button, List, ListItem, Modal} from '@tryghost/admin-x-design-system'; -import {FollowingResponseData, useBrowseFollowersForUser, useUnfollow} from '@tryghost/admin-x-framework/api/activitypub'; +import {FollowingResponseData, useBrowseFollowersForUser, useFollow} from '@tryghost/admin-x-framework/api/activitypub'; import {RoutingModalProps, useRouting} from '@tryghost/admin-x-framework/routing'; interface ViewFollowersModalProps { @@ -13,10 +13,11 @@ interface ViewFollowersModalProps { const ViewFollowersModal: React.FC = ({}) => { const {updateRoute} = useRouting(); // const modal = NiceModal.useModal(); - const mutation = useUnfollow(); + const mutation = useFollow(); - const {data: {orderedItems: followers = []} = {}} = useBrowseFollowersForUser('inbox'); + const {data: {items = []} = {}} = useBrowseFollowersForUser('inbox'); + const followers = Array.isArray(items) ? items : [items]; return ( { @@ -33,7 +34,7 @@ const ViewFollowersModal: React.FC
{followers.map(item => ( - mutation.mutate({username: item.username})} />} avatar={} detail={getUsernameFromFollowing(item)} id='list-item' title={item.name}> + mutation.mutate({username: getUsername(item)})} />} avatar={} detail={getUsername(item)} id='list-item' title={item.name}> ))}
diff --git a/apps/admin-x-activitypub/src/components/ViewFollowing.tsx b/apps/admin-x-activitypub/src/components/ViewFollowing.tsx index dc5dc2021c..4a5bc82cd6 100644 --- a/apps/admin-x-activitypub/src/components/ViewFollowing.tsx +++ b/apps/admin-x-activitypub/src/components/ViewFollowing.tsx @@ -1,6 +1,6 @@ import {} from '@tryghost/admin-x-framework/api/activitypub'; import NiceModal from '@ebay/nice-modal-react'; -import getUsernameFromFollowing from '../utils/get-username-from-following'; +import getUsername from '../utils/get-username'; import {Avatar, Button, List, ListItem, Modal} from '@tryghost/admin-x-design-system'; import {FollowingResponseData, useBrowseFollowingForUser, useUnfollow} from '@tryghost/admin-x-framework/api/activitypub'; import {RoutingModalProps, useRouting} from '@tryghost/admin-x-framework/routing'; @@ -14,8 +14,9 @@ const ViewFollowingModal: React.FC const {updateRoute} = useRouting(); const mutation = useUnfollow(); - const {data: {orderedItems: following = []} = {}} = useBrowseFollowingForUser('inbox'); + const {data: {items = []} = {}} = useBrowseFollowingForUser('inbox'); + const following = Array.isArray(items) ? items : [items]; return ( { @@ -32,7 +33,7 @@ const ViewFollowingModal: React.FC
{following.map(item => ( - mutation.mutate({username: getUsernameFromFollowing(item)})} />} avatar={} detail={getUsernameFromFollowing(item)} id='list-item' title={item.name}> + mutation.mutate({username: getUsername(item)})} />} avatar={} detail={getUsername(item)} id='list-item' title={item.name}> ))} {/* diff --git a/apps/admin-x-activitypub/src/utils/get-username-from-following.ts b/apps/admin-x-activitypub/src/utils/get-username-from-following.ts deleted file mode 100644 index 598caa5f6e..0000000000 --- a/apps/admin-x-activitypub/src/utils/get-username-from-following.ts +++ /dev/null @@ -1,12 +0,0 @@ -function getUsernameFromFollowing(followItem: {username: string; id: string|null;}) { - if (!followItem.username || !followItem.id) { - return '@unknown@unknown'; - } - try { - return `@${followItem.username}@${(new URL(followItem.id)).hostname}`; - } catch (err) { - return '@unknown@unknown'; - } -} - -export default getUsernameFromFollowing; diff --git a/apps/admin-x-framework/src/api/activitypub.ts b/apps/admin-x-framework/src/api/activitypub.ts index 83ecfdd95c..246292d556 100644 --- a/apps/admin-x-framework/src/api/activitypub.ts +++ b/apps/admin-x-framework/src/api/activitypub.ts @@ -2,7 +2,7 @@ import {createMutation, createQueryWithId} from '../utils/api/hooks'; export type FollowItem = { id: string; - username: string, + preferredUsername: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any [x: string]: any }; @@ -63,7 +63,7 @@ export type InboxResponseData = { summary: string; type: 'OrderedCollection'; totalItems: number; - orderedItems: Activity[]; + items: Activity[]; } export type FollowingResponseData = { @@ -72,7 +72,7 @@ export type FollowingResponseData = { summary: string; type: string; totalItems: number; - orderedItems: FollowItem[]; + items: FollowItem[]; } type FollowRequestProps = { @@ -82,19 +82,22 @@ type FollowRequestProps = { export const useFollow = createMutation({ method: 'POST', useActivityPub: true, - path: data => `/follow/${data.username}` + path: data => `/actions/follow/${data.username}` }); export const useUnfollow = createMutation({ method: 'POST', useActivityPub: true, - path: data => `/unfollow/${data.username}` + path: data => `/actions/unfollow/${data.username}` }); // This is a frontend root, not using the Ghost admin API export const useBrowseInboxForUser = createQueryWithId({ dataType: 'InboxResponseData', useActivityPub: true, + headers: { + Accept: 'application/activity+json' + }, path: id => `/inbox/${id}` }); @@ -102,6 +105,9 @@ export const useBrowseInboxForUser = createQueryWithId({ export const useBrowseFollowingForUser = createQueryWithId({ dataType: 'FollowingResponseData', useActivityPub: true, + headers: { + Accept: 'application/activity+json' + }, path: id => `/following/${id}` }); @@ -109,5 +115,8 @@ export const useBrowseFollowingForUser = createQueryWithId({ dataType: 'FollowingResponseData', useActivityPub: true, + headers: { + Accept: 'application/activity+json' + }, path: id => `/followers/${id}` });