generated from mehotkhan/totoro
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
31 changed files
with
441 additions
and
816 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"localforage", | ||
"nomicfoundation", | ||
"nomiclabs", | ||
"nostr", | ||
"Nuxt", | ||
"nuxtjs", | ||
"pinia", | ||
|
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,29 +1,84 @@ | ||
import { Event as NostrEvent, Relay, finalizeEvent } from "nostr-tools"; | ||
import { useWebSocket } from "@vueuse/core"; | ||
|
||
export default async () => { | ||
const { profile } = useUser() | ||
const { $dexie } = useNuxtApp() | ||
const relayURL = "ws://localhost:3000/nostr-relay"; | ||
|
||
let relay: any = null; | ||
export default () => { | ||
const { profile } = useUser(); | ||
const { $dexie } = useNuxtApp(); | ||
const sending = ref(false); | ||
const { status, data, send, open, close } = useWebSocket(relayURL, { | ||
autoReconnect: { | ||
retries: 3, | ||
delay: 1000, | ||
onFailed() { | ||
console.log("Failed to connect WebSocket after 3 retries"); | ||
}, | ||
}, | ||
}); | ||
|
||
watch(data, () => { | ||
console.log('incming websocket', data.value); | ||
}); | ||
watch(status, () => { | ||
console.log(status.value); | ||
}); | ||
|
||
onMounted(async () => { | ||
open(); | ||
relay = new Relay(relayURL); | ||
await relay.connect(); | ||
console.log(`Connected to ${relay.url}`); | ||
startStream(); | ||
}); | ||
|
||
// Correctly typed function for adding a comment | ||
const sendComment = async (message: string) => { | ||
await $dexie.comments.add({ | ||
owner: profile.value.pub, | ||
message: message, | ||
create_at: 'sdss', | ||
hash: 'sdss' | ||
}) | ||
return | ||
} | ||
|
||
// const allComments = useLiveQuery( | ||
// async () => | ||
// await $dexie.comments | ||
// .orderBy("created_at") | ||
// .toArray(), | ||
// [], | ||
// ); | ||
const allComments: any[] = [] | ||
sending.value = true; | ||
if (!profile.value?.pub) { | ||
sending.value = false; | ||
throw new Error("User profile is not loaded"); | ||
} | ||
const newComment = { | ||
owner: String(profile.value.pub), | ||
message, | ||
created_at: Date.now(), // Now saving as timestamp | ||
hash: "some_hash_generation_logic_here", // You should replace this with actual hash generation logic | ||
status: "draft", | ||
}; | ||
|
||
sending.value = false; | ||
$dexie.comments.add(newComment); | ||
}; | ||
|
||
// Use `useLiveQuery` to reactively fetch all comments ordered by 'created_at' | ||
const allComments = useLiveQuery(async () => { | ||
return await $dexie.comments.orderBy("created_at").reverse().toArray(); | ||
}, []); | ||
|
||
const startStream = async () => { | ||
if (relay !== null && relay.connected) { | ||
console.log("listen"); | ||
relay.subscribe( | ||
[ | ||
{ | ||
// authors: mockRelay.authors, | ||
kinds: [1], | ||
}, | ||
], | ||
{ | ||
onevent(event: any) { | ||
console.log("incoming", event); | ||
}, | ||
} | ||
); | ||
} | ||
}; | ||
|
||
return { | ||
sending, | ||
sendComment, | ||
allComments | ||
} | ||
|
||
} | ||
allComments, | ||
}; | ||
}; |
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
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
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
Oops, something went wrong.