From a1b0a97eb59a4b8c4f96f4676f7ea3bb13546372 Mon Sep 17 00:00:00 2001 From: dskvr Date: Fri, 12 Apr 2024 00:15:50 +0200 Subject: [PATCH] improved get config --- src/lib/core/MRPConfig.ts | 5 +- src/lib/core/kinds/app-config.ts | 104 +------------------------------ 2 files changed, 4 insertions(+), 105 deletions(-) diff --git a/src/lib/core/MRPConfig.ts b/src/lib/core/MRPConfig.ts index 5a05fb7..47037f6 100644 --- a/src/lib/core/MRPConfig.ts +++ b/src/lib/core/MRPConfig.ts @@ -1,4 +1,4 @@ -import NDK, { NDKEvent, NDKKind, NDKRelaySet } from "@nostr-dev-kit/ndk"; +import NDK, { NDKEvent, NDKKind, NDKRelaySet, NDKSubscription } from "@nostr-dev-kit/ndk"; import { AppConfig } from "./kinds/app-config"; import type { EventEmitter } from 'tseep'; @@ -16,7 +16,6 @@ export class MRPConfig extends MRPData { private _event: AppConfig | null; private _data: any; private _pubkey: string | undefined; - private _operator: MRPUser | undefined private _relay: string | undefined constructor($state: MRPState, relay?: string, pubkey?: string){ @@ -49,7 +48,7 @@ export class MRPConfig extends MRPData { (await this.$.ndk .fetchEvent( { kinds: [NDKKind.AppSpecificData], authors: [this.pubkey], '#d': [this.configKey()] }, - { unrefUnsubscribeTimeout: 1000 }, + undefined, this._relay? NDKRelaySet.fromRelayUrls([this._relay], this?.$?.ndk as NDK): undefined ) ) as AppConfig diff --git a/src/lib/core/kinds/app-config.ts b/src/lib/core/kinds/app-config.ts index 8985509..8345f5b 100644 --- a/src/lib/core/kinds/app-config.ts +++ b/src/lib/core/kinds/app-config.ts @@ -59,8 +59,8 @@ export class AppConfig extends NDKEvent { return json } - get(key: string): any | undefined { - return this._config?.[key] + get(key?: string): any | undefined { + return key? this._config?.[key]: this._config } set(key: string, payload: Json){ @@ -69,104 +69,4 @@ export class AppConfig extends NDKEvent { this.content = jsonpack.pack(json) } - // get colors(): Colors | undefined{ - // const result = new Object() as Colors; - // (this.tags as ColorTuple[]) - // .filter( (tag: ColorTuple) => tag[0] === 'color') - // .forEach( (tag: ColorTuple) => { - // result[tag[1]] = String(tag[2]) - // }) - // return result; - // } - - // set backgroundColor(color: string){ - // this.removeByKeyAndValue('color', 'background') - // this.tags.push(["color", 'background', color]); - // } - - // get backgroundColor(): string | undefined{ - // return this.tags.find( (tag: NDKTag) => tag[1] === 'background')?.[2] - // } - - // set foregroundColor(color: string){ - // this.removeByKeyAndValue('color', 'foreground') - // this.tags.push(["color", 'foreground', color]); - // } - - // get foregroundColor(): string | undefined{ - // return this.tags.find( (tag: NDKTag) => tag[1] === 'foreground')?.[2] - // } - - // set primaryColor(color: string){ - // this.removeByKeyAndValue('color', 'primary') - // this.tags.push(["color", 'primary', color]); - // } - - // get primaryColor(): string | undefined{ - // return this.tags.find( (tag: NDKTag) => tag[1] === 'primary')?.[2] - // } - - // set secondaryColor(color: string){ - // this.removeByKeyAndValue('color', 'secondary') - // this.tags.push(["color", 'secondary', color]); - // } - - // get secondaryColor(): string | undefined{ - // return this.tags.find( (tag: NDKTag) => tag[1] === 'secondary')?.[2] - // } - - // set accentColor(color: string){ - // this.removeByKeyAndValue('color', 'accent') - // this.tags.push(["color", 'accent', color]); - // } - - // get accentColor(): string | undefined{ - // return this.tags.find( (tag: NDKTag) => tag[1] === 'accent')?.[2] - // } - - // set mutedColor(color: string){ - // this.removeByKeyAndValue('color', 'muted') - // this.tags.push(["color", 'muted', color]); - // } - - // get mutedColor(): string | undefined{ - // return this.tags.find( (tag: NDKTag) => tag[1] === 'muted')?.[2] - // } - - // get font(): Font | undefined{ - // return this._font - // } - - // set font(font: Font){ - // this._font = font - // } - - // get theme(): string | undefined{ - // return this._theme - // } - - // set theme(theme: string){ - // this._theme = theme - // } - - // get visible(): ComponentVisible | undefined{ - // const result = new Object() as ComponentVisible; - // (this.tags) - // .filter( (tag: NDKTag) => tag[0] === 'visible') - // .forEach( (tag: NDKTag) => { - // result[tag[1]] = true - // }) - // return result; - // } - - // set visible(visible: ComponentVisible ){ - // for (const key in visible){ - // this.removeByKeyAndValue('visible', key) - // this.tags.push(["visible", key, 'true']); - // } - // } - - // private removeByKeyAndValue(key: string, value: string){ - // this.tags = this.tags.filter( (tag: NDKTag) => tag[0] === key && tag[1] !== value) - // } } \ No newline at end of file