Add undo to channel messages

This commit is contained in:
Jon Staab
2024-10-16 15:57:18 -07:00
parent 13628aeb71
commit 86622b7ce5
7 changed files with 69 additions and 65 deletions
-2
View File
@@ -24,7 +24,6 @@
initStorage,
repository,
pubkey,
publishStatusData,
plaintext,
freshness,
storageAdapters,
@@ -106,7 +105,6 @@
events: storageAdapters.fromRepository(repository, {throttle: 300, migrate: migrateEvents}),
relays: {keyPath: "url", store: throttled(1000, relays)},
handles: {keyPath: "nip05", store: throttled(1000, handles)},
publishStatus: storageAdapters.fromObjectStore(publishStatusData),
freshness: storageAdapters.fromObjectStore(freshness, {
throttle: 1000,
migrate: migrateFreshness,
@@ -9,10 +9,12 @@
<script lang="ts">
import {page} from "$app/stores"
import {sortBy, append} from "@welshman/lib"
import {writable} from 'svelte/store'
import {sortBy, assoc, append} from "@welshman/lib"
import type {TrustedEvent, EventContent} from "@welshman/util"
import {createEvent} from "@welshman/util"
import {formatTimestampAsDate, publishThunk} from "@welshman/app"
import type {Thunk} from "@welshman/app"
import {fly} from "@lib/transition"
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
@@ -36,13 +38,15 @@
const {nrelay, room = GENERAL} = $page.params
const url = decodeNRelay(nrelay)
const channel = deriveChannel(makeChannelId(url, room))
const thunks = writable({} as Record<string, Thunk>)
const assertEvent = (e: any) => e as TrustedEvent
const onSubmit = ({content, tags}: EventContent) => {
const event = createEvent(MESSAGE, {content, tags: append(tagRoom(room, url), tags)})
const thunk = publishThunk({event, relays: [url], delay: 60_000})
publishThunk({event, relays: [url]})
thunks.update(assoc(thunk.event.id, thunk))
}
let loading = true
@@ -108,8 +112,10 @@
{#if type === "date"}
<Divider>{value}</Divider>
{:else}
{@const event = assertEvent(value)}
{@const thunk = $thunks[event.id]}
<div in:fly>
<ChannelMessage {url} {room} event={assertEvent(value)} {showPubkey} />
<ChannelMessage {url} {room} {event} {thunk} {showPubkey} />
</div>
{/if}
{/each}