diff --git a/src/app/pages/explore/explore.component.ts b/src/app/pages/explore/explore.component.ts index c1a881e..93ef3e5 100644 --- a/src/app/pages/explore/explore.component.ts +++ b/src/app/pages/explore/explore.component.ts @@ -351,29 +351,6 @@ export class ExploreComponent implements OnInit, AfterViewInit, OnDestroy { // console.log('Projects updated:', projects.length); }); - // Listen for profile updates - this.relay.profileUpdates.subscribe((event) => { - const id = event.pubkey; - - // Find the project from this.indexer.projects() that has the ID. - const project = this.indexer - .projects() - .find((p) => p.details?.nostrPubKey === id); - - if (project) { - project.metadata = JSON.parse(event.content); - } - - // Update the matching project with new profile data - this.indexer.projects.update((projects) => - projects.map((project) => - project.founderKey === event.pubkey - ? { ...project, metadata: project.metadata } - : project - ) - ); - }); - // Listen for project updates with timestamp check this.relay.projectUpdates.subscribe((event) => { const update = JSON.parse(event.content); @@ -396,6 +373,10 @@ export class ExploreComponent implements OnInit, AfterViewInit, OnDestroy { // Listen for profile updates with timestamp check this.relay.profileUpdates.subscribe((event) => { + if (!event) { + return; + } + const update = JSON.parse(event.content); const id = event.pubkey; @@ -407,10 +388,10 @@ export class ExploreComponent implements OnInit, AfterViewInit, OnDestroy { // Only update if new data is newer or we don't have existing metadata if ( !project.metadata || - update.event.created_at > (project.metadata_created_at || 0) + event.created_at! > (project.metadata_created_at || 0) ) { - project.metadata = update.profile; - project.metadata_created_at = update.event.created_at; + project.metadata = update; + project.metadata_created_at = event.created_at; } } }); diff --git a/src/app/services/indexer.service.ts b/src/app/services/indexer.service.ts index 5335eda..145025a 100644 --- a/src/app/services/indexer.service.ts +++ b/src/app/services/indexer.service.ts @@ -120,19 +120,37 @@ export class IndexerService { const metadata = JSON.parse(event.content) as NDKUserProfile; this.projects.update((projects) => - projects.map((project) => - project.founderKey === pubkey ? { ...project, metadata } : project - ) + projects.map((project) => { + if (project.founderKey === pubkey) { + // Only update if the new event is newer than existing metadata + if (!project.metadata_created_at || event.created_at! > project.metadata_created_at) { + return { + ...project, + metadata, + metadata_created_at: event.created_at + }; + } + } + return project; + }) ); } private updateProjectDetails(details: any) { this.projects.update((projects) => - projects.map((project) => - project.projectIdentifier === details.projectIdentifier - ? { ...project, details } - : project - ) + projects.map((project) => { + if (project.projectIdentifier === details.projectIdentifier) { + // Only update if the new event is newer than existing details + if (!project.details_created_at || details.created_at > project.details_created_at) { + return { + ...project, + details, + details_created_at: details.created_at + }; + } + } + return project; + }) ); }