fix(nostr-feed): Fetch profiles for submission authors

Add watchers to fetch profiles when submissions and comments load,
ensuring display names are shown instead of pubkeys.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Patrick Mulligan 2026-01-01 21:24:06 +01:00 committed by Padreug
parent 09a1e3b9f6
commit 1904a54131
2 changed files with 39 additions and 8 deletions

View file

@ -4,7 +4,7 @@
* Displays complete submission content and threaded comments * Displays complete submission content and threaded comments
*/ */
import { ref, computed } from 'vue' import { ref, computed, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { formatDistanceToNow } from 'date-fns' import { formatDistanceToNow } from 'date-fns'
import { import {
@ -85,9 +85,7 @@ const currentUserPubkey = computed(() => authService?.user?.value?.pubkey || nul
// Get display name for a pubkey // Get display name for a pubkey
function getDisplayName(pubkey: string): string { function getDisplayName(pubkey: string): string {
if (profileService) { if (profileService) {
const profile = profileService.getProfile(pubkey) return profileService.getDisplayName(pubkey)
if (profile?.display_name) return profile.display_name
if (profile?.name) return profile.name
} }
return `${pubkey.slice(0, 8)}...` return `${pubkey.slice(0, 8)}...`
} }
@ -203,7 +201,7 @@ async function submitComment() {
await submissionService.createComment( await submissionService.createComment(
props.submissionId, props.submissionId,
commentText.value.trim(), commentText.value.trim(),
null // Top-level comment undefined // Top-level comment
) )
cancelReply() cancelReply()
} catch (err: any) { } catch (err: any) {
@ -260,6 +258,33 @@ function countReplies(comment: SubmissionCommentType): number {
function goBack() { function goBack() {
router.back() router.back()
} }
// Helper to collect all pubkeys from comments recursively
function collectCommentPubkeys(comments: SubmissionCommentType[]): string[] {
const pubkeys: string[] = []
for (const comment of comments) {
pubkeys.push(comment.pubkey)
if (comment.replies?.length) {
pubkeys.push(...collectCommentPubkeys(comment.replies))
}
}
return pubkeys
}
// Fetch profiles when submission loads
watch(submission, (sub) => {
if (profileService && sub) {
profileService.fetchProfiles([sub.pubkey])
}
}, { immediate: true })
// Fetch profiles when comments load
watch(comments, (newComments) => {
if (profileService && newComments.length > 0) {
const pubkeys = [...new Set(collectCommentPubkeys(newComments))]
profileService.fetchProfiles(pubkeys)
}
}, { immediate: true })
</script> </script>
<template> <template>

View file

@ -76,9 +76,7 @@ const isAuthenticated = computed(() => authService?.isAuthenticated?.value || fa
// Get display name for a pubkey // Get display name for a pubkey
function getDisplayName(pubkey: string): string { function getDisplayName(pubkey: string): string {
if (profileService) { if (profileService) {
const profile = profileService.getProfile(pubkey) return profileService.getDisplayName(pubkey)
if (profile?.display_name) return profile.display_name
if (profile?.name) return profile.name
} }
// Fallback to truncated pubkey // Fallback to truncated pubkey
return `${pubkey.slice(0, 8)}...` return `${pubkey.slice(0, 8)}...`
@ -143,6 +141,14 @@ function onReport(submission: SubmissionWithMeta) {
console.log('Report:', submission.id) console.log('Report:', submission.id)
} }
// Fetch profiles when submissions change
watch(submissions, (newSubmissions) => {
if (profileService && newSubmissions.length > 0) {
const pubkeys = [...new Set(newSubmissions.map(s => s.pubkey))]
profileService.fetchProfiles(pubkeys)
}
}, { immediate: true })
// Subscribe when community changes // Subscribe when community changes
watch(() => props.community, () => { watch(() => props.community, () => {
subscribe({ subscribe({