Skip to content

Commit

Permalink
update to draft7
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jul 28, 2024
2 parents 0740c7a + 253e344 commit 2cc2568
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 357 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "myrelay.site",
"type": "module",
"version": "0.2.9",
"version": "0.2.10",
"main": "index.js",
"repository": "[email protected]:sandwichfarm/myrelay.site.git",
"author": "dskvr <[email protected]>",
Expand Down
8 changes: 4 additions & 4 deletions src/lib/components/blocks/repeatable/feed/feed.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
<FeedGrid
{notes}
{pointers}
maxColWidth={options.gridMaxColWidth}
minColWidth={options.gridMinColWidth}
gap={options.gridGap}
animate={options.gridAnimate}
maxColWidth={options?.gridMaxColWidth}
minColWidth={options?.gridMinColWidth}
gap={options?.gridGap}
animate={options?.gridAnimate}
/>
{:else}
<FeedGridSkeleton />
Expand Down
9 changes: 5 additions & 4 deletions src/lib/components/blocks/unique/map/map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
const setMonitor = (monitor: MRPMonitor) => {
const dd = monitor.dd
const rtt = $MRP.nostr?.monitors?.metaEventsFor(monitor.pubkey)?.[0].rtt?.open || undefined
const rtt = $MRP.nostr?.monitors?.discoveryEventsFor(monitor.pubkey)?.[0]?.rttOpen || undefined
const point: MapPoint = {
id: monitor.geohash,
Expand All @@ -98,12 +98,12 @@
brightness: 0.1
}
const link: MapLink = {
const link: MapLink = {
source: $relayMapPoint.id || $relayMapPoint,
target: point.id || point,
color: 'black',
cursor: 'crosshair'
}
}
$monitorMapPoints.push(point)
$monitorLinks.push(link)
Expand Down Expand Up @@ -180,7 +180,8 @@
updateMapData()
}
$MRP.signal.on('monitors:ready', setMapPoints)
$MRP?.$.signal.on('monitors:ready', setMapPoints)
onMount( () => {
if($MRP.nostr.monitors.isComplete) {
setMapPoints()
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/blocks/unique/map/monitors.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import { MY_RELAY_PAGE } from '$lib/contextKeys';
import { Badge } from "$lib/components/ui/badge/index.js";
import 'nostr-zap'
import type { MRPMonitors } from "$lib/core/monitors";
// import type { MRPMonitors } from "$lib/core/monitors";
import type { MyRelayPage } from '$lib/core/MRP';
import type { Writable } from 'svelte/store';
export let key: string;
export let mapChange: () => void
Expand All @@ -12,9 +14,8 @@
export let setMonitors: () => void
export let resetMonitors: () => void
export let updateMapData: () => void
const MRP = getContext(MY_RELAY_PAGE);
const MRP: Writable<MyRelayPage> = getContext(MY_RELAY_PAGE);
const hovered = (monitor: MRPMonitor | boolean): undefined => {
if(monitorVis !== 'onhover') return
Expand Down
48 changes: 4 additions & 44 deletions src/lib/core/MRPMonitors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import NDK, { NDKRelaySet, type NDKEvent, NDKRelay, type NDKUserProfile, NDKUser } from "@nostr-dev-kit/ndk";
import { RelayMonitor } from "./kinds/monitor";
import { RelayMeta } from "./kinds/relay-meta";
import { RelayDiscovery } from "./kinds/relay-discovery";
import type { RelayMetaParsed } from "./kinds/relay-meta";
import type { DD } from "./kinds/geocoded";
import type { MRPState } from "./MRP";
import { MRPData } from "./MRPData";

type RelayMetaDictionary = Record<string, RelayMeta[]>
type RelayDiscoveryDictionary = Record<string, RelayDiscovery[]>

export class MRPMonitors extends MRPData {
Expand All @@ -19,8 +16,7 @@ export class MRPMonitors extends MRPData {
private relaySet: NDKRelaySet;
private _monitors: Set<RelayMonitor> = new Set();
private _monitorEvents: Set<NDKEvent> = new Set();
private _relayMeta: RelayMetaDictionary = {};
private _relayDiscovery: RelayDiscoveryDictionary = {};
public _relayDiscovery: RelayDiscoveryDictionary = {};
private _operators: Record<string, NDKUserProfile> = {};
private _url: string;

Expand All @@ -34,16 +30,8 @@ export class MRPMonitors extends MRPData {

async init(){
this.begin()
const metaEvents = await this.$.ndk.fetchEvents({ kinds: [30066], "#d": [new URL(this._url).toString()], since: this.livenessThreshold }, null, this.relaySet)
const dedupedMetaEvents = new Set(Array.from(metaEvents).map((event: NDKEvent) => new RelayMeta(this.$.ndk, event.rawEvent())))
Array.from(dedupedMetaEvents).forEach((event: RelayMeta) => {
if(!this._relayMeta[event.pubkey]){
this._relayMeta[event.pubkey] = []
}
this._relayMeta[event.pubkey].push(event)
})

const discoveryEvents = await this.$.ndk.fetchEvents({ kinds: [30166], "#d": [new URL(this._url).toString()], since: this.livenessThreshold }, null, this.relaySet).catch( err => this.error(err) )
const discoveryEvents = await this?.$?.ndk?.fetchEvents({ kinds: [30166], "#d": [new URL(this._url).toString()], since: this.livenessThreshold }, null, this.relaySet).catch( err => this.error(err) )
const dedupedDiscoveryEvents = new Set(Array.from(discoveryEvents).map((event: NDKEvent) => new RelayDiscovery(this.$.ndk, event.rawEvent())))
Array.from(dedupedDiscoveryEvents).forEach((event: RelayDiscovery) => {
if(!this._relayDiscovery[event.pubkey]){
Expand All @@ -52,7 +40,7 @@ export class MRPMonitors extends MRPData {
this._relayDiscovery[event.pubkey].push(event)
})

const authors = Array.from(new Set(this.getAllRelayMeta().map((event: NDKEvent) => event.pubkey) ))
const authors = Array.from(new Set(this.getAllRelayDiscovery().map((event: NDKEvent) => event.pubkey) ))

const monitorEvents: Set<NDKEvent> | void = await this.$.ndk.fetchEvents({ kinds: [10166], authors }, null, this.relaySet).catch( err => this.error(err) )

Expand All @@ -76,21 +64,12 @@ export class MRPMonitors extends MRPData {
if(!this.isError) this.complete(true)
}

getRtt(): RelayMetaParsed | undefined {
let rtt: RelayMetaParsed | undefined;
for (const event of this.getAllRelayMeta()) {
if(rtt) break
rtt = event?.rtt
}
return rtt
}

getRelayDD() {
let dd: DD | undefined;
for (const event of this.getAllRelayDiscovery()) {
if(dd) break
if(!event?.dd) continue
dd = event.dd
if(dd) break
}
return dd
}
Expand All @@ -106,10 +85,6 @@ export class MRPMonitors extends MRPData {
return dd
}

metaEventsFor(pubkey: string): RelayMeta[] | undefined {
return this._relayMeta[pubkey]
}

discoveryEventsFor(pubkey: string): RelayDiscovery[] | undefined {
return this._relayDiscovery[pubkey]
}
Expand All @@ -118,14 +93,6 @@ export class MRPMonitors extends MRPData {
return this._monitors.size
}

getAllRelayMeta(): RelayMeta[] {
let result: RelayMeta[] = []
Object.keys(this._relayMeta).forEach((key) => {
result = result.concat(Array.from(this._relayMeta[key]))
})
return result
}

getAllRelayDiscovery(): RelayDiscovery[] {
let result: RelayDiscovery[] = []
Object.keys(this._relayDiscovery).forEach((key) => {
Expand All @@ -134,10 +101,6 @@ export class MRPMonitors extends MRPData {
return result
}

countReports(): number {
return this.getAllRelayMeta().length
}

get operators(): Record<string, NDKUserProfile> {
return this._operators
}
Expand All @@ -150,9 +113,6 @@ export class MRPMonitors extends MRPData {
return this._monitors
}

get relayMetaEvents(): RelayMetaDictionary {
return this._relayMeta
}

get relayDiscovery(): RelayDiscoveryDictionary {
return this._relayDiscovery
Expand Down
20 changes: 4 additions & 16 deletions src/lib/core/MRPNostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class MRPNostr {
}

public async init(){
await this.ndk.connect();
await this._relay.init()
this.monitors.init()
}
Expand All @@ -46,15 +47,15 @@ export class MRPNostr {
const user = await this.signer.user();
this.user = new MRPUser(this.$, user, 'currentUser');
await this.user.init();
await this.ndk.connect();

this._authed = true;
this.ndk.emit('mrp:login')
this.$.signal.emit('mrp:login')
}

public logout(){
this.user = undefined
this._authed = false
this.ndk.emit('mrp:logout')
this.$.signal.emit('mrp:logout')
}

async toggleRelay(relay: string){
Expand Down Expand Up @@ -92,8 +93,6 @@ export class MRPNostr {
return this._authed
}



get monitors(): MRPMonitors {
return this._monitors
}
Expand Down Expand Up @@ -150,15 +149,4 @@ export class MRPNostr {
this._user = user
}

// public async sign (kind: NDKKind, event: NDKEvent | NostrEvent ){
// if(event as NostrEvent){
// return this.ndk.sign(kind, event as NostrEvent)
// }
// return this.ndk.sign(kind, event as NDKEvent)
// }

// public async publish ( event: NDKEvent ) {
// return this.ndk.publish(event as NDKEvent)
// }

}
2 changes: 1 addition & 1 deletion src/lib/core/kinds/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class AppConfig extends NDKEvent {
}

configDiffersFromDefault(): boolean {
console.log(this.configHash, this._configDefaultHash, this.configHash !== this._configDefaultHash)
// console.log(this.configHash, this._configDefaultHash, this.configHash !== this._configDefaultHash)
return this.configHash !== this._configDefaultHash;
}

Expand Down
33 changes: 17 additions & 16 deletions src/lib/core/kinds/geocoded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class NDKEventGeoCoded extends NDKEvent {
private static readonly EARTH_RADIUS: number = 6371; // km
private static readonly GEOHASH_PRECISION: number = 12;
private static readonly BASE32: string = '0123456789bcdefghjkmnpqrstuvwxyz';
private static readonly geohashFilterFn = (tag: NDKTag) => tag[0] === 'g' && (tag[2] === "gh" || tag[2] === "geohash" || tag.length === 2); //`g` tags with a length of 2 are NIP-52 geohashes
private static readonly geohashFilterFn = (tag: NDKTag) => tag[0] === 'g' && (tag.length === 2 || tag['2'] === 'gh' || tag['2'] === 'geohash'); //`g` tags with a length of 2 are NIP-52 geohashes

private _dd: DD | undefined;

Expand Down Expand Up @@ -181,26 +181,26 @@ export class NDKEventGeoCoded extends NDKEvent {
}

get countryCode(): string[] | undefined {
return this.tagValuesByMarker("g", "countryCode");
return this.tagValuesByMarker("l", "countryCode");
}

set countryCode(values: string[]) {
this.removeTagByMarker("g", "countryCode");
this.removeTagByMarker("l", "countryCode");
values.forEach(value => {
this._setGeoTag("countryCode", value);
this.addTag("l", value, "countryCode");
});
}

get countryName(): string | undefined {
return this.tagValueByMarker("g", "countryName");
return this.tagValueByMarker("l", "countryName");
}

set countryName(value: string) {
this._setGeoTag("countryName", value);
}

get regionCode(): string | undefined {
return this.tagValueByMarker("g", "regionCode");
return this.tagValueByMarker("l", "regionCode");
}

set regionCode(value: string) {
Expand All @@ -212,26 +212,27 @@ export class NDKEventGeoCoded extends NDKEvent {
}

get regionName(): string | undefined {
return this.tagValueByMarker("g", "regionName");
return this.tagValueByMarker("l", "regionName");
}

set continentName(value: string) {

this._setGeoTag("continentName", value);
}

get continentName(): string | undefined {
return this.tagValueByMarker("g", "continentName");
return this.tagValueByMarker("l", "continentName");
}

get geo(): NDKTag[] {
return [...this.getMatchingTags("G"), ...this.getMatchingTags("g")];
}
// get geo(): NDKTag[] {
// return [...this.getMatchingTags("G"), ...this.getMatchingTags("g")];
// }

set geo(tags: NDKTag[]) {
this.removeTag("G");
this.removeTag("g");
tags.forEach(tag => this.tags.push(tag));
}
// set geo(tags: NDKTag[]) {
// this.removeTag("G");
// this.removeTag("g");
// tags.forEach(tag => this.tags.push(tag));
// }

private set lat(value: number) {
if(!this._dd) this._dd = { lat: 0, lon: 0 } as DD;
Expand Down
Loading

0 comments on commit 2cc2568

Please sign in to comment.