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:
parent
09a1e3b9f6
commit
1904a54131
2 changed files with 39 additions and 8 deletions
|
|
@ -4,7 +4,7 @@
|
|||
* 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 { formatDistanceToNow } from 'date-fns'
|
||||
import {
|
||||
|
|
@ -85,9 +85,7 @@ const currentUserPubkey = computed(() => authService?.user?.value?.pubkey || nul
|
|||
// Get display name for a pubkey
|
||||
function getDisplayName(pubkey: string): string {
|
||||
if (profileService) {
|
||||
const profile = profileService.getProfile(pubkey)
|
||||
if (profile?.display_name) return profile.display_name
|
||||
if (profile?.name) return profile.name
|
||||
return profileService.getDisplayName(pubkey)
|
||||
}
|
||||
return `${pubkey.slice(0, 8)}...`
|
||||
}
|
||||
|
|
@ -203,7 +201,7 @@ async function submitComment() {
|
|||
await submissionService.createComment(
|
||||
props.submissionId,
|
||||
commentText.value.trim(),
|
||||
null // Top-level comment
|
||||
undefined // Top-level comment
|
||||
)
|
||||
cancelReply()
|
||||
} catch (err: any) {
|
||||
|
|
@ -260,6 +258,33 @@ function countReplies(comment: SubmissionCommentType): number {
|
|||
function goBack() {
|
||||
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>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
|
|
@ -76,9 +76,7 @@ const isAuthenticated = computed(() => authService?.isAuthenticated?.value || fa
|
|||
// Get display name for a pubkey
|
||||
function getDisplayName(pubkey: string): string {
|
||||
if (profileService) {
|
||||
const profile = profileService.getProfile(pubkey)
|
||||
if (profile?.display_name) return profile.display_name
|
||||
if (profile?.name) return profile.name
|
||||
return profileService.getDisplayName(pubkey)
|
||||
}
|
||||
// Fallback to truncated pubkey
|
||||
return `${pubkey.slice(0, 8)}...`
|
||||
|
|
@ -143,6 +141,14 @@ function onReport(submission: SubmissionWithMeta) {
|
|||
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
|
||||
watch(() => props.community, () => {
|
||||
subscribe({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue