From 85b411bb24e665b7a409045ec869625ce8f1461b Mon Sep 17 00:00:00 2001 From: SondreB Date: Thu, 12 Jan 2023 22:44:49 +0100 Subject: [PATCH] Add support for dynamically loading following --- src/app/following/following.component.ts | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/following/following.component.ts b/src/app/following/following.component.ts index b18b383..8fb1063 100644 --- a/src/app/following/following.component.ts +++ b/src/app/following/following.component.ts @@ -3,6 +3,8 @@ import { MatTabChangeEvent } from '@angular/material/tabs'; import { ActivatedRoute, Router } from '@angular/router'; import { Subscription } from 'rxjs'; import { ApplicationState } from '../services/applicationstate.service'; +import { DataService } from '../services/data.service'; +import { NostrEventDocument, NostrProfileDocument } from '../services/interfaces'; import { ProfileService } from '../services/profile.service'; @Component({ @@ -18,16 +20,24 @@ export class FollowingComponent { pubkeys?: string[] = []; - constructor(private appState: ApplicationState, public profileService: ProfileService, private activatedRoute: ActivatedRoute, private router: Router) {} + constructor(private appState: ApplicationState, private dataService: DataService, public profileService: ProfileService, private activatedRoute: ActivatedRoute, private router: Router) {} ngOnInit() { this.appState.showBackButton = true; this.subscriptions.push( this.profileService.item$.subscribe((profile) => { - this.appState.title = `@${profile?.name}`; + if (!profile) { + return; + } - this.pubkeys = profile?.following; + this.appState.title = `@${profile.name}`; + + if (profile.following) { + this.pubkeys = profile.following; + } else { + this.downloadFollowingAndRelays(profile); + } }) ); @@ -46,4 +56,16 @@ export class FollowingComponent { this.subscriptions[i].unsubscribe(); } } + + downloadFollowingAndRelays(profile: NostrProfileDocument) { + this.subscriptions.push( + this.dataService.downloadNewestContactsEvents([profile.pubkey]).subscribe((event) => { + const nostrEvent = event as NostrEventDocument; + const publicKeys = nostrEvent.tags.map((t) => t[1]); + + this.profileService.following(profile.pubkey, publicKeys); + this.pubkeys = publicKeys; + }) + ); + } }