Fix issue with subscription retry logic

This commit is contained in:
SondreB 2023-01-06 17:53:20 +01:00
parent 0cb83fed07
commit 5c7c00541b
No known key found for this signature in database
GPG Key ID: D6CC44C75005FDBF
2 changed files with 15 additions and 5 deletions

View File

@ -51,7 +51,7 @@ export class ProfileComponent {
this.subscriptions.push(
this.profileService.profile$.subscribe((profile) => {
if (!profile) {
profile = this.defaultProfile();
profile = this.defaultProfile(this.appState.getPublicKey());
}
console.log('PROFILE SERVICE:', profile);
@ -64,7 +64,7 @@ export class ProfileComponent {
);
}
defaultProfile(): NostrProfileDocument {
defaultProfile(pubkey: string): NostrProfileDocument {
return {
name: '',
about: '',
@ -75,7 +75,7 @@ export class ProfileComponent {
website: '',
created: Math.floor(Date.now() / 1000),
verifications: [],
pubkey: this.appState.getPublicKey(),
pubkey: pubkey,
};
}

View File

@ -461,6 +461,12 @@ export class RelayService {
subscribeToFollowing(relay: Relay) {
const authors = this.profileService.profiles.map((p) => p.pubkey);
// Just skip subscription if we are not following anyone yet.
if (authors.length === 0) {
console.log('Skipping subscription, zero following.');
return;
}
// Append ourself to the authors list so we receive everything we publish to any relay.
authors.push(this.appState.getPublicKey());
@ -482,8 +488,12 @@ export class RelayService {
if (sub.loading) {
console.log('Unsubbing and restarting subscription.', relay);
sub.unsub();
this.subscribeToFollowing(relay);
// Only re-attempt the subscription if we actually have an active connection to this relay.
if (relay.status === 1) {
sub.unsub();
this.subscribeToFollowing(relay);
}
}
}, 5 * 60 * 1000);