Fix legacy message loading
This commit is contained in:
+15
-14
@@ -455,22 +455,23 @@ export const chatSearch = derived(chats, $chats =>
|
|||||||
// Messages
|
// Messages
|
||||||
|
|
||||||
// TODO: remove support for legacy messages
|
// TODO: remove support for legacy messages
|
||||||
|
export const adaptLegacyMessage = (event: TrustedEvent) => {
|
||||||
|
if (event.kind === LEGACY_MESSAGE) {
|
||||||
|
let room = event.tags.find(nthEq(0, "~"))?.[1] || GENERAL
|
||||||
|
|
||||||
|
if (room === "general") {
|
||||||
|
room = GENERAL
|
||||||
|
}
|
||||||
|
|
||||||
|
return {...event, kind: MESSAGE, tags: [...event.tags, tagRoom(room, "")]}
|
||||||
|
}
|
||||||
|
|
||||||
|
return event
|
||||||
|
}
|
||||||
|
|
||||||
export const messages = derived(
|
export const messages = derived(
|
||||||
deriveEvents(repository, {filters: [{kinds: [MESSAGE, LEGACY_MESSAGE]}]}),
|
deriveEvents(repository, {filters: [{kinds: [MESSAGE, LEGACY_MESSAGE]}]}),
|
||||||
$events =>
|
$events => $events.map(adaptLegacyMessage),
|
||||||
$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
|
// Group Meta
|
||||||
|
|||||||
@@ -49,7 +49,14 @@
|
|||||||
const content = popKey<string>("content") || ""
|
const content = popKey<string>("content") || ""
|
||||||
const url = decodeRelay($page.params.relay)
|
const url = decodeRelay($page.params.relay)
|
||||||
const relay = deriveRelay(url)
|
const relay = deriveRelay(url)
|
||||||
const events = throttled(300, deriveEventsForUrl(url, [{kinds: [MESSAGE], "#h": [room]}]))
|
const legacyRoom = room === GENERAL ? "general" : room
|
||||||
|
const events = throttled(
|
||||||
|
300,
|
||||||
|
deriveEventsForUrl(url, [
|
||||||
|
{kinds: [MESSAGE], "#h": [room]},
|
||||||
|
{kinds: [LEGACY_MESSAGE], "#~": [legacyRoom]},
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
|
||||||
const assertEvent = (e: any) => e as TrustedEvent
|
const assertEvent = (e: any) => e as TrustedEvent
|
||||||
|
|
||||||
@@ -132,7 +139,7 @@
|
|||||||
load({
|
load({
|
||||||
delay: 0,
|
delay: 0,
|
||||||
relays: [url],
|
relays: [url],
|
||||||
filters: [{kinds: [LEGACY_MESSAGE], "#~": [room]}],
|
filters: [{kinds: [LEGACY_MESSAGE], "#~": [legacyRoom]}],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user