Skip to content

Commit

Permalink
refactor: support actor_id->ap_id rename
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Feb 5, 2025
1 parent d889016 commit ed2d847
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/features/auth/login/join/Legal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import AppHeader from "#/features/shared/AppHeader";
import { useInterceptHrefWithInAppBrowserIfNeeded } from "#/features/shared/InAppExternalLink";
import Markdown from "#/features/shared/markdown/Markdown";
import { getApId } from "#/helpers/lemmy";
import { VOYAGER_PRIVACY, VOYAGER_TERMS } from "#/helpers/voyager";
import { useAppSelector } from "#/store";

Expand Down Expand Up @@ -91,7 +92,7 @@ export default function Legal() {
{site?.site_view.local_site.legal_information?.trim() ? (
<Markdown
className="collapse-md-margins"
id={`site-legal-${site?.site_view.site.actor_id}`}
id={`site-legal-${getApId(site?.site_view.site)}`}
>
{site.site_view.local_site.legal_information}
</Markdown>
Expand Down
3 changes: 2 additions & 1 deletion src/features/auth/login/join/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useContext, useState } from "react";
import AppHeader from "#/features/shared/AppHeader";
import { DynamicDismissableModalContext } from "#/features/shared/DynamicDismissableModal";
import Markdown from "#/features/shared/markdown/Markdown";
import { getApId } from "#/helpers/lemmy";
import { useAppSelector } from "#/store";

import Join from "./Join";
Expand Down Expand Up @@ -61,7 +62,7 @@ export default function Question() {
<IonList inset className="ion-padding">
<Markdown
className="collapse-md-margins"
id={`site-application-question-${site?.site_view.site.actor_id}`}
id={`site-application-question-${getApId(site?.site_view.site)}`}
>
{site?.site_view.local_site.application_question}
</Markdown>
Expand Down
6 changes: 3 additions & 3 deletions src/features/auth/login/pickJoinServer/PickJoinServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import AppHeader from "#/features/shared/AppHeader";
import { DynamicDismissableModalContext } from "#/features/shared/DynamicDismissableModal";
import { isIosTheme } from "#/helpers/device";
import { blurOnEnter } from "#/helpers/dom";
import { isMinimumSupportedLemmyVersion } from "#/helpers/lemmy";
import { getApId, isMinimumSupportedLemmyVersion } from "#/helpers/lemmy";
import { isValidHostname, stripProtocol } from "#/helpers/url";
import { defaultServersUntouched, getCustomServers } from "#/services/app";
import { getClient, getImageSrc } from "#/services/lemmy";
Expand Down Expand Up @@ -144,7 +144,7 @@ export default function PickJoinServer() {

// User changed search before request resolved
if (
site.site_view.site.actor_id !==
getApId(site.site_view.site) !==
`https://${searchHostname.toLowerCase()}/`
)
return;
Expand Down Expand Up @@ -364,7 +364,7 @@ function normalize(instance: GetSiteResponse | LVInstance): Instance {
}

return {
url: new URL(instance.site_view.site.actor_id).hostname,
url: new URL(getApId(instance.site_view.site)).hostname,
icon: instance.site_view.site.icon,
description: instance.site_view.site.description,
open: instance.site_view.local_site.registration_mode === "Open",
Expand Down
8 changes: 6 additions & 2 deletions src/features/community/useCommunityActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
localUserSelector,
showNsfw,
} from "#/features/auth/siteSlice";
import { checkIsMod, getHandle as useGetHandle } from "#/helpers/lemmy";
import {
checkIsMod,
getApId,
getHandle as useGetHandle,
} from "#/helpers/lemmy";
import { useBuildGeneralBrowseLink } from "#/helpers/routes";
import { shareUrl } from "#/helpers/share";
import {
Expand Down Expand Up @@ -192,7 +196,7 @@ export default function useCommunityActions(
};

const share = () => {
shareUrl(community.actor_id);
shareUrl(getApId(community));
};

return {
Expand Down
8 changes: 4 additions & 4 deletions src/features/labels/links/PersonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
preventOnClickNavigationBug,
stopIonicTapClick,
} from "#/helpers/ionic";
import { getHandle, getRemoteHandle } from "#/helpers/lemmy";
import { getApId, getHandle, getRemoteHandle } from "#/helpers/lemmy";
import { useBuildGeneralBrowseLink } from "#/helpers/routes";
import { OInstanceUrlDisplayMode } from "#/services/db";
import { useAppSelector } from "#/store";
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function PersonLink({
}: PersonLinkProps) {
const buildGeneralBrowseLink = useBuildGeneralBrowseLink();
const isAdmin = useAppSelector((state) => state.site.response?.admins)?.some(
(admin) => admin.person.actor_id === person.actor_id,
(admin) => getApId(admin.person) === getApId(person),
);
const { hideUsernames } = useContext(ShareImageContext);
const presentUserActions = usePresentUserActions();
Expand Down Expand Up @@ -89,8 +89,8 @@ export default function PersonLink({
if (isAdmin) color = "var(--ion-color-danger)";
else if (distinguished) color = "var(--ion-color-success)";
else if (
person.actor_id === "https://lemmy.world/u/aeharding" ||
person.actor_id === "https://vger.social/u/aeharding"
getApId(person) === "https://lemmy.world/u/aeharding" ||
getApId(person) === "https://vger.social/u/aeharding"
)
color = "var(--ion-color-tertiary-tint)";
else if (opId && person.id === opId) color = "var(--ion-color-primary-fixed)";
Expand Down
5 changes: 3 additions & 2 deletions src/features/resolve/resolveSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
POST_PATH,
} from "#/features/shared/useLemmyUrlHandler";
import { receivedUsers } from "#/features/user/userSlice";
import { getApId } from "#/helpers/lemmy";
import { isLemmyError } from "#/helpers/lemmyErrors";
import { getClient } from "#/services/lemmy";
import { AppDispatch, RootState } from "#/store";
Expand Down Expand Up @@ -172,7 +173,7 @@ async function findFedilink(url: string): Promise<string | undefined> {
},
);

return response.person_view.person.actor_id;
return getApId(response.person_view.person);
} else if (matchLemmyCommunity(pathname)) {
const [community, communityHostname] = matchLemmyCommunity(pathname)!;

Expand All @@ -182,7 +183,7 @@ async function findFedilink(url: string): Promise<string | undefined> {
name: community,
});

return response.community_view.community.actor_id;
return getApId(response.community_view.community);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Community } from "lemmy-js-client";

import { getRemoteHandle } from "#/helpers/lemmy";
import { getApId, getRemoteHandle } from "#/helpers/lemmy";
import useClient from "#/helpers/useClient";

import GenericAutocompleteMode, {
Expand All @@ -26,5 +26,5 @@ export default function CommunityAutocomplete(props: AutocompleteModeProps) {
}

function buildMd(item: Community) {
return `[!${getRemoteHandle(item)}](${item.actor_id})`;
return `[!${getRemoteHandle(item)}](${getApId(item)})`;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Person } from "lemmy-js-client";

import { getRemoteHandle } from "#/helpers/lemmy";
import { getApId, getRemoteHandle } from "#/helpers/lemmy";
import useClient from "#/helpers/useClient";

import GenericAutocompleteMode, {
Expand All @@ -26,5 +26,5 @@ export default function UsernameAutocompleteMode(props: AutocompleteModeProps) {
}

function buildMd(item: Person) {
return `[@${getRemoteHandle(item)}](${item.actor_id})`;
return `[@${getRemoteHandle(item)}](${getApId(item)})`;
}
5 changes: 3 additions & 2 deletions src/features/shared/useSharePostComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isNative } from "#/helpers/device";
import {
buildLemmyCommentLink,
buildLemmyPostLink,
getApId,
isPost,
} from "#/helpers/lemmy";
import { shareUrl } from "#/helpers/share";
Expand Down Expand Up @@ -137,7 +138,7 @@ export function useSharePostComment(itemView: PostView | CommentView) {
await onAsk();
break;
case OPostCommentShareType.Community: {
const instance = parseUrl(itemView.community.actor_id)?.hostname;
const instance = parseUrl(getApId(itemView.community))?.hostname;
if (instance) await shareInstance(instance);
break;
}
Expand Down Expand Up @@ -182,7 +183,7 @@ function generateInstanceCandidates(
candidates.push(connectedInstance);

const communityActorHostname = parseUrl(
postOrComment.community.actor_id,
getApId(postOrComment.community),
)?.hostname;
if (communityActorHostname) candidates.push(communityActorHostname);

Expand Down
4 changes: 2 additions & 2 deletions src/features/sidebar/internal/CommunitySidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IonRefresher, IonRefresherContent } from "@ionic/react";
import { CommunityView } from "lemmy-js-client";

import { getCommunity } from "#/features/community/communitySlice";
import { getHandle } from "#/helpers/lemmy";
import { getApId, getHandle } from "#/helpers/lemmy";
import { useAppDispatch, useAppSelector } from "#/store";

import GenericSidebar from "./GenericSidebar";
Expand Down Expand Up @@ -42,7 +42,7 @@ export default function CommunitySidebar({ community }: CommunitySidebarProps) {
counts={community.counts}
banner={community.community.banner}
name={`c/${getHandle(community.community)}`}
id={community.community.actor_id}
id={getApId(community.community)}
/>
</>
);
Expand Down
5 changes: 3 additions & 2 deletions src/features/sidebar/internal/InstanceSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IonBadge, IonRefresher, IonRefresherContent } from "@ionic/react";

import { getSite, lemmyVersionSelector } from "#/features/auth/siteSlice";
import { CenteredSpinner } from "#/features/shared/CenteredSpinner";
import { getApId } from "#/helpers/lemmy";
import { useAppDispatch, useAppSelector } from "#/store";

import GenericSidebar from "./GenericSidebar";
Expand Down Expand Up @@ -38,8 +39,8 @@ export default function InstanceSidebar() {
counts={counts}
extraBadges={<IonBadge color="dark">v{lemmyVersion}</IonBadge>}
banner={site.banner}
name={site.actor_id}
id={site.actor_id}
name={getApId(site)}
id={getApId(site)}
/>
</>
);
Expand Down
22 changes: 21 additions & 1 deletion src/helpers/lemmy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const MAX_DEFAULT_COMMENT_DEPTH = 6;
* @param item Community, Person, etc
*/
export function getItemActorName(item: Pick<Community, "actor_id">) {
return new URL(item.actor_id).hostname;
return new URL(getApId(item)).hostname;
}

export function checkIsMod(communityHandle: string, site: GetSiteResponse) {
Expand Down Expand Up @@ -360,3 +360,23 @@ export function buildLemmyPostLink(instance: string, id: number) {
export function buildLemmyCommentLink(instance: string, id: number) {
return `https://${instance}/comment/${id}`;
}

/**
* This is needed for a migration to lemmy v1
*
* After Voyager requires v1, this function can be removed
*/
export function getApId(obj: { actor_id: string }): string;
export function getApId(obj: { ap_id: string }): string;
export function getApId(
obj: { actor_id: string } | undefined,
): string | undefined;
export function getApId(obj: { ap_id: string } | undefined): string | undefined;
export function getApId(obj: undefined): undefined;
export function getApId(
obj: { ap_id?: string } | { actor_id?: string } | undefined,
): string | undefined {
if (!obj) return;
if ("ap_id" in obj) return obj.ap_id;
if ("actor_id" in obj) return obj.actor_id;
}

0 comments on commit ed2d847

Please sign in to comment.