Fix quote relays, add backwards compat for reading legacy messages/threads

This commit is contained in:
Jon Staab
2024-12-10 10:49:21 -08:00
parent 523c54a1f1
commit a65f6f6323
10 changed files with 55 additions and 17 deletions

View File

@@ -81,7 +81,7 @@
</div>
{/if}
<div class="text-sm">
<Content {event} quoteProps={{minimal: true}} />
<Content {event} quoteProps={{minimal: true, relays: [url]}} />
{#if thunk}
<ThunkStatus {thunk} class="mt-2" />
{/if}

View File

@@ -134,7 +134,7 @@
{#if isBlock(i)}
<ContentQuote {...quoteProps} value={parsed.value} {depth} {event}>
<div slot="note-content" let:event>
<svelte:self {hideMedia} {event} depth={depth + 1} />
<svelte:self {quoteProps} {hideMedia} {event} depth={depth + 1} />
</div>
</ContentQuote>
{:else}

View File

@@ -13,14 +13,19 @@
export let value
export let event
export let depth = 0
export let relays: string[] = []
export let minimal = false
const {id, identifier, kind, pubkey, relays: relayHints = []} = value
const addr = new Address(kind, pubkey, identifier)
const idOrAddress = id || addr.toString()
const relays = ctx.app.router.Quote(event, idOrAddress, relayHints).getUrls()
const quote = deriveEvent(idOrAddress, relays)
const entity = id ? nip19.neventEncode({id, relays}) : addr.toNaddr()
const idOrAddress = id || new Address(kind, pubkey, identifier).toString()
const mergedRelays = [
...relays,
...ctx.app.router.Quote(event, idOrAddress, relayHints).getUrls(),
]
const quote = deriveEvent(idOrAddress, mergedRelays)
const entity = id
? nip19.neventEncode({id, relays: mergedRelays})
: new Address(kind, pubkey, identifier, mergedRelays).toNaddr()
const scrollToEvent = (id: string) => {
const element = document.querySelector(`[data-event="${id}"]`) as any

View File

@@ -28,7 +28,7 @@
{formatTimestamp(event.created_at)}
</p>
{/if}
<Content {event} expandMode="inline" />
<Content {event} expandMode="inline" quoteProps={{relays: [url]}} />
<div class="flex w-full flex-col items-end justify-between gap-2 sm:flex-row">
<span class="whitespace-nowrap py-1 text-sm opacity-75">
Posted by

View File

@@ -21,7 +21,7 @@
if ($loading) return
const content = $editor.getText({blockSeparator: "\n"})
const tags = [...getEditorTags($editor), tagRoom(GENERAL, url), [PROTECTED]]
const tags = [...getEditorTags($editor), tagRoom(GENERAL, url), PROTECTED]
if (!content.trim()) {
return pushToast({

View File

@@ -9,6 +9,7 @@ import {makeSpacePath} from "@app/routes"
import {
MESSAGE,
THREAD,
LEGACY_THREAD,
COMMENT,
deriveEventsForUrl,
getMembershipUrls,
@@ -33,8 +34,8 @@ export const SPACE_FILTERS: Filter[] = [{kinds: [THREAD, MESSAGE, COMMENT]}]
export const ROOM_FILTERS: Filter[] = [{kinds: [MESSAGE]}]
export const THREAD_FILTERS: Filter[] = [
{kinds: [THREAD]},
{kinds: [COMMENT], "#K": [String(THREAD)]},
{kinds: [THREAD, LEGACY_THREAD]},
{kinds: [COMMENT], "#K": [String(THREAD), String(LEGACY_THREAD)]},
]
export const getNotificationFilters = (since: number): Filter[] =>

View File

@@ -73,8 +73,12 @@ export const PROTECTED = ["-"]
export const MESSAGE = 9
export const LEGACY_MESSAGE = 209
export const THREAD = 11
export const LEGACY_THREAD = 309
export const COMMENT = 1111
export const MEMBERSHIPS = 10009
@@ -454,7 +458,24 @@ export const chatSearch = derived(chats, $chats =>
// Messages
export const messages = deriveEvents(repository, {filters: [{kinds: [MESSAGE]}]})
// TODO: remove support for legacy messages
export const messages = derived(
deriveEvents(repository, {filters: [{kinds: [MESSAGE, LEGACY_MESSAGE]}]}),
$events =>
$events.map(e => {
if (e.kind === LEGACY_MESSAGE) {
let room = e.tags.find(nthEq(0, "~"))?.[1] || GENERAL
if (room === "general") {
room = GENERAL
}
return {...e, kind: MESSAGE, tags: [...e.tags, tagRoom(room, "")]}
}
return e
}),
)
// Group Meta

View File

@@ -10,7 +10,7 @@
import {throttled} from "@welshman/store"
import {createEvent, DELETE} from "@welshman/util"
import {PublishStatus} from "@welshman/net"
import {formatTimestampAsDate, publishThunk, deriveRelay} from "@welshman/app"
import {formatTimestampAsDate, load, publishThunk, deriveRelay} from "@welshman/app"
import {slide} from "@lib/transition"
import {createScroller, type Scroller} from "@lib/html"
import Icon from "@lib/components/Icon.svelte"
@@ -31,6 +31,7 @@
GENERAL,
tagRoom,
MESSAGE,
LEGACY_MESSAGE,
getMembershipRoomsByUrl,
} from "@app/state"
import {setChecked} from "@app/notifications"
@@ -124,6 +125,14 @@
// Sveltekiiit
await sleep(100)
if (!nip29.isSupported($relay)) {
load({
delay: 0,
relays: [url],
filters: [{kinds: [LEGACY_MESSAGE], "#~": [room]}],
})
}
pullConservatively({
relays: [url],
filters: [{kinds: [MESSAGE, DELETE], "#h": [room]}],

View File

@@ -16,13 +16,15 @@
import MenuSpaceButton from "@app/components/MenuSpaceButton.svelte"
import ThreadItem from "@app/components/ThreadItem.svelte"
import ThreadCreate from "@app/components/ThreadCreate.svelte"
import {THREAD, COMMENT, decodeRelay, deriveEventsForUrl} from "@app/state"
import {THREAD, LEGACY_THREAD, COMMENT, decodeRelay, deriveEventsForUrl} from "@app/state"
import {THREAD_FILTERS, setChecked} from "@app/notifications"
import {pushModal} from "@app/modal"
const url = decodeRelay($page.params.relay)
const threads = deriveEventsForUrl(url, [{kinds: [THREAD]}])
const comments = deriveEventsForUrl(url, [{kinds: [COMMENT], "#K": [String(THREAD)]}])
const threads = deriveEventsForUrl(url, [{kinds: [THREAD, LEGACY_THREAD]}])
const comments = deriveEventsForUrl(url, [
{kinds: [COMMENT], "#K": [String(THREAD), String(LEGACY_THREAD)]},
])
const mutedPubkeys = getPubkeyTagValues(getListTags($userMutes))
const events = throttled(

View File

@@ -81,7 +81,7 @@
{/if}
<NoteCard event={$event} class="card2 bg-alt z-feature w-full">
<div class="col-3 ml-12">
<Content showEntire event={$event} />
<Content showEntire event={$event} quoteProps={{relays: [url]}} />
<ThreadActions event={$event} {url} />
</div>
</NoteCard>