Skip to content

Commit

Permalink
problem: can't see user names
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Apr 20, 2024
1 parent 0ce6eac commit af3712a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
58 changes: 58 additions & 0 deletions src/lib/components/UserDisplayName.svelte
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}
27 changes: 0 additions & 27 deletions src/lib/components/UserName.svelte

This file was deleted.

Empty file.
5 changes: 4 additions & 1 deletion src/lib/stores/user.ts
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>)
3 changes: 2 additions & 1 deletion src/lib/views/messages/RenderKind1.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { inview } from 'svelte-inview';
import { onMount } from 'svelte';
import { viewed } from '@/snort_workers/main';
import UserDisplayName from '@/components/UserDisplayName.svelte';
export let note: NostrEvent;
export let onClickReply: () => void;
Expand Down Expand Up @@ -38,7 +39,7 @@ onMount(() => {
alt="profile pic"
/>
<div class="grid">
<h5 class="text-gray-900 dark:text-orange-600 font-semibold leading-snug pb-1">Marcus</h5>
<h5 class="text-gray-900 dark:text-orange-600 font-semibold leading-snug pb-1"><UserDisplayName pubkey={note.pubkey}/></h5>
<div class="grid overflow-hidden mr-2 min-w-56">
<div
class="px-3.5 py-2 bg-gray-200 dark:bg-gray-700 rounded-e-xl rounded-es-xl flex flex-col gap-2"
Expand Down

0 comments on commit af3712a

Please sign in to comment.