Display "Following" as total number of following both public and private

This commit is contained in:
SondreB 2023-01-03 07:34:38 +01:00
parent 1a5dfaf38e
commit 2f7c75ab8f
No known key found for this signature in database
GPG Key ID: D6CC44C75005FDBF
2 changed files with 18 additions and 5 deletions

View File

@ -62,7 +62,7 @@
<div class="data">
<ul>
<li>0 <span>Followers</span></li>
<li>0 <span>Following</span></li>
<li *ngIf="profileService.following$ | async as following">{{ following.length }} <span>Following</span></li>
</ul>
</div>
</div>

View File

@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { NostrProfile, NostrProfileDocument } from './interfaces';
import { StorageService } from './storage.service';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, map, Observable } from 'rxjs';
import * as moment from 'moment';
import { ApplicationState } from './applicationstate.service';
@ -15,6 +15,21 @@ export class ProfileService {
// #profile: NostrProfileDocument;
/** TODO: Destroy this array when there are zero subscribers left. */
profiles: NostrProfileDocument[] = [];
#followingChanged: BehaviorSubject<NostrProfileDocument[]> = new BehaviorSubject<NostrProfileDocument[]>(this.profiles);
get following$(): Observable<NostrProfileDocument[]> {
// value.follow == true
return this.#profilesChanged.asObservable().pipe(
map((data) => {
const filtered = data.filter((events) => events.follow == true);
return filtered;
})
);
}
#profileChanged: BehaviorSubject<NostrProfileDocument | undefined> = new BehaviorSubject<NostrProfileDocument | undefined>(undefined);
/** Profile of the authenticated user. */
@ -26,9 +41,6 @@ export class ProfileService {
this.#profileChanged.next(profile);
}
/** TODO: Destroy this array when there are zero subscribers left. */
profiles: NostrProfileDocument[] = [];
#profilesChanged: BehaviorSubject<NostrProfileDocument[]> = new BehaviorSubject<NostrProfileDocument[]>(this.profiles);
get profiles$(): Observable<NostrProfileDocument[]> {
@ -43,6 +55,7 @@ export class ProfileService {
#updated() {
this.#profilesChanged.next(this.profiles);
this.#followingChanged.next(this.profiles);
}
mutedPublicKeys() {