Add shift+click to channel links

This commit is contained in:
brecert
2021-09-07 09:26:12 -04:00
parent 82366cf1ea
commit 53451b58f3
2 changed files with 48 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
type LinkType =
| { type: "profile"; id: string }
| { type: "navigate"; path: string }
| { type: "navigate"; path: string; navigation_type?: null }
| { type: "navigate"; path: string; navigation_type: 'channel'; channel_id: string }
| { type: "external"; href: string; url: URL }
| { type: "none" };
@@ -11,6 +12,8 @@ const ALLOWED_ORIGINS = [
"local.revolt.chat",
];
const CHANNEL_PATH_RE = /^\/server\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}\/channel\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/
export function determineLink(href?: string): LinkType {
let internal,
url: URL | null = null;
@@ -27,6 +30,10 @@ export function determineLink(href?: string): LinkType {
return { type: "profile", id };
}
} else {
console.log(path)
if(CHANNEL_PATH_RE.test(path)) {
return { type: 'navigate', path, navigation_type: 'channel', channel_id: path.slice(43) }
}
return { type: "navigate", path };
}