diff --git a/app/(home-pages)/p/[didOrHandle]/layout.tsx b/app/(home-pages)/p/[didOrHandle]/layout.tsx index 2f19e187..effa6e60 100644 --- a/app/(home-pages)/p/[didOrHandle]/layout.tsx +++ b/app/(home-pages)/p/[didOrHandle]/layout.tsx @@ -7,6 +7,7 @@ import { ProfileTabs } from "./ProfileTabs"; import { DashboardLayout } from "components/PageLayouts/DashboardLayout"; import { ProfileLayout } from "./ProfileLayout"; import { Agent } from "@atproto/api"; +import { get_profile_data } from "app/api/rpc/[command]/get_profile_data"; export default async function ProfilePageLayout(props: { params: Promise<{ didOrHandle: string }>; @@ -33,21 +34,11 @@ export default async function ProfilePageLayout(props: { } did = resolved; } - - let agent = new Agent({ - service: "https://public.api.bsky.app", - }); - let profileReq = agent.app.bsky.actor.getProfile({ actor: did }); - - let publicationsReq = supabaseServerClient - .from("publications") - .select("*") - .eq("identity_did", did); - - let [{ data: profile }, { data: publications }] = await Promise.all([ - profileReq, - publicationsReq, - ]); + let profileData = await get_profile_data.handler( + { didOrHandle: did }, + { supabase: supabaseServerClient }, + ); + let { publications, profile } = profileData.result; if (!profile) return null; diff --git a/app/api/rpc/[command]/get_profile_data.ts b/app/api/rpc/[command]/get_profile_data.ts index 8a74bdde..2c0e4f8e 100644 --- a/app/api/rpc/[command]/get_profile_data.ts +++ b/app/api/rpc/[command]/get_profile_data.ts @@ -4,6 +4,8 @@ import type { Env } from "./route"; import { idResolver } from "app/(home-pages)/reader/idResolver"; import { supabaseServerClient } from "supabase/serverClient"; import { Agent } from "@atproto/api"; +import { getIdentityData } from "actions/getIdentityData"; +import { createOauthClient } from "src/atproto-oauth"; export type GetProfileDataReturnType = Awaited< ReturnType<(typeof get_profile_data)["handler"]> @@ -25,13 +27,29 @@ export const get_profile_data = makeRoute({ } did = resolved; } + let agent; + let authed_identity = await getIdentityData(); + if (authed_identity?.atp_did) { + try { + const oauthClient = await createOauthClient(); + let credentialSession = await oauthClient.restore( + authed_identity.atp_did, + ); + agent = new Agent(credentialSession); + } catch (e) { + agent = new Agent({ + service: "https://public.api.bsky.app", + }); + } + } else { + agent = new Agent({ + service: "https://public.api.bsky.app", + }); + } - let agent = new Agent({ - service: "https://public.api.bsky.app", - }); let profileReq = agent.app.bsky.actor.getProfile({ actor: did }); - let publicationsReq = supabaseServerClient + let publicationsReq = supabase .from("publications") .select("*") .eq("identity_did", did); diff --git a/components/ProfilePopover.tsx b/components/ProfilePopover.tsx index f584b832..97774e1e 100644 --- a/components/ProfilePopover.tsx +++ b/components/ProfilePopover.tsx @@ -6,6 +6,7 @@ import { useRef, useState } from "react"; import { ProfileHeader } from "app/(home-pages)/p/[didOrHandle]/ProfileHeader"; import { SpeedyLink } from "./SpeedyLink"; import { Tooltip } from "./Tooltip"; +import { ProfileViewDetailed } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; export const ProfilePopover = (props: { trigger: React.ReactNode; @@ -64,11 +65,7 @@ export const ProfilePopover = (props: { publications={data.publications} popover /> -
-
- Followed by{" "} - -
+ ) : (
Profile not found
@@ -76,3 +73,18 @@ export const ProfilePopover = (props: { ); }; + +let KnownFollowers = (props: { viewer: ProfileViewDetailed["viewer"] }) => { + if (!props.viewer?.knownFollowers) return null; + let count = props.viewer.knownFollowers.count; + return ( + <> +
+ Followed by{" "} + + + ); +};