Get nip 17 chat working

This commit is contained in:
Jon Staab
2024-10-08 13:20:55 -07:00
parent 8698dcc359
commit a351d9d792
8 changed files with 106 additions and 119 deletions
+23 -19
View File
@@ -68,28 +68,32 @@
}
}
onMount(() => {
onMount(async () => {
Object.assign(window, {get, ...app, ...state})
ready = db
? Promise.resolve()
: initStorage("flotilla", 4, {
events: storageAdapters.fromRepository(repository, {throttle: 300}),
relays: {keyPath: "url", store: throttled(1000, relays)},
handles: {keyPath: "nip05", store: throttled(1000, handles)},
publishStatus: storageAdapters.fromObjectStore(publishStatusData),
freshness: storageAdapters.fromObjectStore(freshness, {throttle: 1000}),
plaintext: storageAdapters.fromObjectStore(plaintext, {throttle: 1000}),
tracker: storageAdapters.fromTracker(tracker, {throttle: 1000}),
}).then(() => sleep(300)) // Wait an extra few ms because of repository throttle
if (!db) {
await initStorage("flotilla", 4, {
events: storageAdapters.fromRepository(repository, {throttle: 300}),
relays: {keyPath: "url", store: throttled(1000, relays)},
handles: {keyPath: "nip05", store: throttled(1000, handles)},
publishStatus: storageAdapters.fromObjectStore(publishStatusData),
freshness: storageAdapters.fromObjectStore(freshness, {throttle: 1000}),
plaintext: storageAdapters.fromObjectStore(plaintext, {throttle: 1000}),
tracker: storageAdapters.fromTracker(tracker, {throttle: 1000}),
})
dialog.addEventListener("close", () => {
if (modal) {
clearModal()
}
})
repository.on("update", ({added}) => {
for (const event of added) {
state.ensureUnwrapped(event)
}
})
dialog.addEventListener("close", () => {
if (modal) {
clearModal()
}
})
ready.then(() => {
for (const url of INDEXER_RELAYS) {
loadRelay(url)
}
@@ -97,7 +101,7 @@
if ($pubkey) {
loadUserData($pubkey)
}
})
}
})
</script>
+5 -2
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import {onMount} from "svelte"
import {page} from "$app/stores"
import {ctx, ago, remove} from "@welshman/lib"
import {WRAP} from "@welshman/util"
import {pubkey, subscribe} from "@welshman/app"
@@ -65,7 +66,7 @@
</div>
</SecondaryNavSection>
<label
class="input input-sm input-bordered mx-6 -mt-4 flex items-center gap-2"
class="input input-sm input-bordered mx-6 -mt-4 flex items-center gap-2 mb-2"
in:fly={{delay: 200}}>
<Icon icon="magnifer" />
<input bind:value={term} class="grow" type="text" />
@@ -74,8 +75,10 @@
{#each chats as { id, pubkeys, messages }, i (id)}
{@const message = messages[0]}
{@const others = remove($pubkey, pubkeys)}
{@const active = $page.params.chat === id}
<div
class="cursor-pointer border-t border-solid border-base-100 px-6 py-2 transition-colors hover:bg-base-100">
class="cursor-pointer border-t border-solid border-base-100 px-6 py-2 transition-colors hover:bg-base-100"
class:bg-base-100={active}>
<Link class="flex flex-col justify-start gap-1" href="/home/{id}">
<div class="flex items-center gap-2">
{#if others.length === 1}
+2 -11
View File
@@ -30,6 +30,7 @@
import ChatMessage from "@app/components/ChatMessage.svelte"
import ChatCompose from "@app/components/ChannelCompose.svelte"
import {deriveChat, splitChatId} from "@app/state"
import {sendWrapped} from "@app/commands"
const {chat: id} = $page.params
const chat = deriveChat(id)
@@ -41,18 +42,8 @@
const onSubmit = async ({content, ...params}: EventContent) => {
const tags = [...params.tags, ...pubkeys.map(pubkey => tagPubkey(pubkey))]
const template = createEvent(DIRECT_MESSAGE, {content, tags})
const nip59 = Nip59.fromSigner($signer!)
for (const recipient of uniq(pubkeys)) {
const rumor = await nip59.wrap(recipient, template)
publishThunk(
makeThunk({
event: rumor.wrap,
relays: ctx.app.router.PublishMessage(recipient).getUrls(),
}),
)
}
await sendWrapped({template, pubkeys})
}
let loading = true
+7 -5
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import {onMount} from "svelte"
import {page} from "$app/stores"
import {sort} from "@welshman/lib"
import {sort, ago} from "@welshman/lib"
import {displayRelayUrl, REACTION, NOTE, EVENT_DATE, EVENT_TIME, CLASSIFIED} from "@welshman/util"
import {subscribe} from "@welshman/app"
import {fly, slide} from "@lib/transition"
@@ -16,7 +16,7 @@
import SpaceExit from "@app/components/SpaceExit.svelte"
import SpaceJoin from "@app/components/SpaceJoin.svelte"
import RoomCreate from "@app/components/RoomCreate.svelte"
import {userMembership, roomsByUrl, decodeNRelay, GENERAL, MESSAGE} from "@app/state"
import {userMembership, pullConservatively, roomsByUrl, decodeNRelay, GENERAL, MESSAGE} from "@app/state"
import {pushModal} from "@app/modal"
import {makeSpacePath} from "@app/routes"
@@ -52,8 +52,10 @@
$: otherRooms = ($roomsByUrl.get(url) || []).filter(room => !rooms.concat(GENERAL).includes(room))
onMount(() => {
const kinds = [NOTE, REACTION, MESSAGE, EVENT_DATE, EVENT_TIME, CLASSIFIED]
const sub = subscribe({filters: [{kinds}], relays: [url]})
const filter = {kinds: [NOTE, REACTION, MESSAGE, EVENT_DATE, EVENT_TIME, CLASSIFIED]}
const sub = subscribe({filters: [{...filter, since: ago(30)}]})
pullConservatively({filters: [filter], relays: [url]})
return () => sub.close()
})
@@ -99,7 +101,7 @@
</div>
<div in:fly={{delay: getDelay(true)}}>
<SecondaryNavItem href={makeSpacePath(url, "threads")}>
<Icon icon="notes-minimalistic" /> Threads
<Icon icon="notes-minimalistic" /> Notes
</SecondaryNavItem>
</div>
<div in:fly={{delay: getDelay()}}>