diff --git a/src/components/FeedPost.tsx b/src/components/FeedPost.tsx index b4f84e5..cef5adb 100644 --- a/src/components/FeedPost.tsx +++ b/src/components/FeedPost.tsx @@ -6,7 +6,6 @@ import { Post, ThreadPost } from "../lib/post"; import { Profile } from "../lib/profile"; import { PostInteractionButtons, PostNotesIndicator } from "./PostInteraction"; import { Text } from "./primitive/Text"; -import Ionicons from "@expo/vector-icons/Ionicons"; import Fontawesome from "@expo/vector-icons/FontAwesome"; const styles = StyleSheet.create({ @@ -58,7 +57,6 @@ function PostHeader({ post, reblogParentProfile }: { post: Post, reblogParentPro const router = useRouter(); const [hovered, setHovered] = useState(false); - const reblogged = !!post.reblog const profile = post.author const onPress = () => { @@ -77,10 +75,10 @@ function PostHeader({ post, reblogParentProfile }: { post: Post, reblogParentPro style={{ width: 25, height: 25 }} source={require("@/assets/images/avatar-default.svg")} /> - {reblogged && ( + {reblogParentProfile && ( )} - {reblogged ? ( + {reblogParentProfile ? ( {profile.handle} reblogged {reblogParentProfile!.handle} ) : ( {profile.handle} diff --git a/src/lib/query/feed.ts b/src/lib/query/feed.ts index 18ecb9d..357c9d8 100644 --- a/src/lib/query/feed.ts +++ b/src/lib/query/feed.ts @@ -9,6 +9,8 @@ import { AtUri } from "@atproto/api"; import { getOrInsertAsync } from "@/src/util/asynchelper"; import { strongRef } from "@/src/lexicons/com/atproto/repo"; +const postCache: Map = new Map(); + function parsePost( author: Profile, record: dev.maelstrom.bramblr.post.Main, @@ -31,6 +33,32 @@ function parsePost( }; } +export async function fetchPost(uri: AtUriString) { + if (postCache.has(uri)) { + return postCache.get(uri)!; + } + + console.log("Fetching post for real"); + const atUri = new AtUri(uri); + const record = await Slingshot.call(com.atproto.repo.getRecord, { + repo: atUri.did, + collection: atUri.collection as any, + rkey: atUri.rkey, + }); + + const authorProfile = await resolveProfile(atUri.did); + + const post = parsePost( + authorProfile, + record.value as dev.maelstrom.bramblr.post.Main, + record.uri as AtUriString, // Maybe do some verification here + record.cid as CidString, + ); + + postCache.set(uri, post); + return post; +} + // TODO: Refactor out the whole "fetch post" code, and do away with the profile cache. // We already have a global profile cache for the entire app (per page-load), so this is // actually unnecessary