-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ce6eac
commit af3712a
Showing
5 changed files
with
64 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script lang="ts"> | ||
import { kind0 } from '@/stores/user'; | ||
import { System } from '@/views/messages/snort'; | ||
import { RequestBuilder, type QueryLike } from '@snort/system'; | ||
import { nip19 } from 'nostr-tools'; | ||
import { onDestroy, onMount } from 'svelte'; | ||
import { derived } from 'svelte/store'; | ||
export let pubkey: string; | ||
let q: QueryLike; | ||
onMount(()=>{ | ||
if (pubkey) { | ||
if (!$kind0.get(pubkey)) { | ||
const rb = new RequestBuilder(pubkey); | ||
rb.withFilter().authors([pubkey]).kinds([0]); | ||
rb.withOptions({ leaveOpen: false }); | ||
q = System.Query(rb); | ||
q.on('event', (evs) => { | ||
if (evs.length > 0) { | ||
kind0.update((existing) => { | ||
for (let e of evs) { | ||
let _existing = existing.get(e.pubkey); | ||
if (!_existing || (_existing && _existing.created_at <= e.created_at)) { | ||
existing.set(e.pubkey, e); | ||
} | ||
} | ||
return existing; | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
}) | ||
onDestroy(() => { | ||
if (q) { | ||
q.cancel(); | ||
} | ||
}); | ||
let displayName = derived(kind0, ($kind0) => { | ||
let content = $kind0.get(pubkey)?.content | ||
let name = nip19.npubEncode(pubkey).substring(0,8) | ||
if (content) { | ||
try { | ||
let json = JSON.parse(content) | ||
if (json.Name && json.Name.length > 0) { | ||
name = json.Name | ||
} else if (json.display_name && json.display_name.length > 0){ | ||
name = json.display_name | ||
} | ||
} catch {} | ||
} | ||
return name | ||
}); | ||
</script> | ||
{$displayName} |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import type { NostrEvent } from "nostr-tools"; | ||
import { writable, type Writable } from "svelte/store"; | ||
|
||
export let currentPubkey = writable(undefined) | ||
export let currentPubkey = writable(undefined) | ||
|
||
export let kind0 = writable(new Map<string, NostrEvent>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters