Skip to content

Commit

Permalink
problem: can't get replies to thread
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Apr 19, 2024
1 parent 6b5203f commit ec11729
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover" class=" bg-zinc-50 dark:bg-zinc-900 overflow-hidden">
<div class="w-full h-full">%sveltekit.body%</div>
<div class="w-screen h-screen">%sveltekit.body%</div>
</body>
</html>
2 changes: 1 addition & 1 deletion src/lib/components/ChatLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
export let hideFaucet = false;
</script>

<div class="flex h-full w-full flex-row">
<div class="flex h-screen w-screen flex-row">
<!-- Icon Sidebar -->
<div class="w-12 flex-shrink-0 block bg-orange-500 dark:bg-cyan-950">
<div class="flex h-full flex-col bg-layer-2">
Expand Down
13 changes: 12 additions & 1 deletion src/lib/snort_workers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { writable, type Writable } from 'svelte/store';
import { Command, FrontendData } from './types';

import WorkerVite from "./master_worker?worker"
import type { NostrEvent } from 'nostr-tools';

export let FrontendDataStore = writable(new FrontendData())
export let viewed: Writable<Set<string>> = writable(new Set());

let worker: Worker;

export async function Init() {
const worker = new WorkerVite()
worker = new WorkerVite()
worker.onmessage = (x: MessageEvent<FrontendData>) => {
FrontendDataStore.update((current) => {
current = x.data;
Expand All @@ -19,4 +22,12 @@ export async function Init() {

export function UpdatePubkey(pubkey:string) {

}

export function PushEvent(e: NostrEvent) {
if (worker) {
let cmd = new Command("push_event")
cmd.event = e
worker.postMessage(cmd)
}
}
11 changes: 10 additions & 1 deletion src/lib/snort_workers/master_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,22 @@ lengthOfFollows.subscribe((x) => {

//contract:
onmessage = (m: MessageEvent<Command>) => {
console.log(58)
if (m.data.command == 'start') {
start(m.data.pubkey)
.then(() => {})
.catch((err) => {
console.log(err);
});
}
if (m.data.command == 'push_event') {

workerDataStore.update(current=>{
console.log(m.data.event)
current.events.set(m.data.event!.id, m.data.event!)
return current
})
}
};

//connect to seed relays, get our follows and relays.
Expand Down Expand Up @@ -166,7 +175,7 @@ async function PermaSub(pubkeys: string[]) {
if (printed < 20 && !printedID.has(tagsForEvent.id)) {
printed++;
printedID.add(tagsForEvent.id);
console.log('unknown tag detected', printed, tagsForEvent.rawEvent);
//console.log('unknown tag detected', printed, tagsForEvent.rawEvent);
}
}
tagsForEvent.roots.forEach((r) => {
Expand Down
6 changes: 1 addition & 5 deletions src/lib/snort_workers/seed_relays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ export let seedRelays = Array.from(new Set([
// "wss://nos.lol",
// "wss://relay.wikifreedia.xyz",
'wss://relay.nostrocket.org',
'wss://search.nos.today',
//'wss://search.nos.today',
'wss://relay.damus.io',
// "wss://relay.nostr.bg",
'wss://relay.snort.social',
// "wss://offchain.pub",
'wss://relay.primal.net',
// "wss://pyramid.fiatjaf.com",
"wss://nostr.wine",
"wss://nostr-01.yakihonne.com",
"wss://nostr-02.dorafactory.org",
"wss://nostr-02.yakihonne.com",
"wss://nostr-03.dorafactory.org",
"wss://relay.damus.io",
"wss://relay.highlighter.com",
"wss://relay.nostrocket.org",
Expand Down
5 changes: 3 additions & 2 deletions src/lib/snort_workers/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { NostrEvent } from 'nostr-tools';

export class Command {
command: 'start' | 'sub_to_pubkeys' | 'fetch_events';
command: 'start' | 'sub_to_pubkeys' | 'fetch_events' | 'push_event';
pubkey?: string;
pubkeys?: string[];
events?: string[];
constructor(command: 'start' | 'sub_to_pubkeys' | 'fetch_events') {
event?: NostrEvent;
constructor(command: 'start' | 'sub_to_pubkeys' | 'fetch_events' | 'push_event') {
this.command = command;
}
}
Expand Down
41 changes: 36 additions & 5 deletions src/lib/views/messages/RenderKind1AsThreadHead.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
<script lang="ts">
import RenderNoteContent from '@/components/RenderNoteContent.svelte';
import { viewed } from '@/snort_workers/main';
import { PushEvent, viewed } from '@/snort_workers/main';
import { seedRelays } from '@/snort_workers/seed_relays';
import type { FrontendData } from '@/snort_workers/types';
import { NostrSystem, RequestBuilder, type QueryLike } from '@snort/system';
import type { NostrEvent } from 'nostr-tools';
import { onMount } from 'svelte';
import { onDestroy, onMount } from 'svelte';
import { type Writable } from 'svelte/store';
import { System, init } from './snort';
export let note: NostrEvent;
export let store: Writable<FrontendData>;
let top: HTMLDivElement;
let q: QueryLike;
onMount(() => {
(async () => {
top.scrollIntoView()
//top.scrollIntoView()
})();
// ID should be unique to the use case, this is important as all data fetched from this ID will be merged into the same NoteStore
const rb = new RequestBuilder(`get-${note.id}`);
rb.withFilter().tag('e', [note.id]).kinds([1]);
rb.withOptions({leaveOpen: false})
console.log(26)
console.log(rb)
console.log(28)
q = System.Query(rb);
// basic usage using "onEvent", fired every 100ms
q.on('event', (evs) => {
console.log(35, evs);
evs.forEach(e=>{
PushEvent(e)
})
// something else..
});
})();
(async () => {
top.scrollIntoView();
//top.scrollIntoView()
})();
});
onDestroy(()=>{
if (q) {
q.cancel()
}
})
$: childrenCount = $store?.replies.get(note.id) ? $store.replies.get(note.id)!.size : 0;
</script>

Expand Down
16 changes: 16 additions & 0 deletions src/lib/views/messages/snort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { seedRelays } from "@/snort_workers/seed_relays";
import { NostrSystem, type QueryLike } from "@snort/system";
import { writable } from "svelte/store";

export const System = new NostrSystem({});
let started = false;

export async function init() {
if (!started) {
started = true;
await System.Init();
for (let relay of seedRelays) {
await System.ConnectToRelay(relay, { read: true, write: false });
}
}
}
2 changes: 2 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import { onMount } from 'svelte';
import '../app.css';
import { Init } from '@/snort_workers/main';
import { init } from '@/views/messages/snort';
onMount(() => {
console.log("layout mounted")
Init();
init()
});
</script>
<ModeWatcher />
Expand Down

0 comments on commit ec11729

Please sign in to comment.