Skip to content

Commit

Permalink
Fix some bugs with loading of old events
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Dec 28, 2024
1 parent 79812b7 commit 7c79f7c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
33 changes: 7 additions & 26 deletions src/app/pages/explore/explore.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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;
}
}
});
Expand Down
34 changes: 26 additions & 8 deletions src/app/services/indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
);
}

Expand Down

0 comments on commit 7c79f7c

Please sign in to comment.