refactor: move room and space mention rendering into link components

This commit is contained in:
2026-04-07 00:30:46 +05:30
parent 12fd552e1b
commit ddb8391b02
8 changed files with 53 additions and 181 deletions
+22 -3
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import {call, displayUrl} from "@welshman/lib"
import {isRelayUrl, getTagValue} from "@welshman/util"
import {isRelayUrl, getTagValue, normalizeRelayUrl} from "@welshman/util"
import {preventDefault, stopPropagation} from "@lib/html"
import LinkRound from "@assets/icons/link-round.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
@@ -8,14 +8,33 @@
import ContentLinkDetail from "@app/components/ContentLinkDetail.svelte"
import {pushModal} from "@app/util/modal"
import {PLATFORM_URL, IMAGE_CONTENT_TYPES} from "@app/core/state"
import {makeSpacePath} from "@app/util/routes"
import {makeRoomPath, makeSpacePath} from "@app/util/routes"
const {value, event} = $props()
const url = value.url.toString()
const splitRoomReference = (input: string) => {
const separatorIndex = input.indexOf("'")
if (separatorIndex === -1) {
return undefined
}
const roomUrl = input.slice(0, separatorIndex)
const h = input.slice(separatorIndex + 1)
if (!h || !isRelayUrl(roomUrl)) {
return undefined
}
return {url: normalizeRelayUrl(roomUrl), h}
}
const roomReference = splitRoomReference(url)
const fileType = getTagValue("file-type", event.tags) || ""
const [href, external] = call(() => {
if (isRelayUrl(url)) return [makeSpacePath(url), false]
if (roomReference) return [makeRoomPath(roomReference.url, roomReference.h), false]
if (isRelayUrl(url)) return [makeSpacePath(normalizeRelayUrl(url)), false]
if (url.startsWith(PLATFORM_URL)) return [url.replace(PLATFORM_URL, ""), false]
return [url, true]