mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 01:15:28 +00:00
Change invite rendering logic.
Handle link warnings on embeds. Remove "EDIT!!" 🙏🙏🙏
This commit is contained in:
43
src/lib/links.ts
Normal file
43
src/lib/links.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
type LinkType =
|
||||
| { type: "profile"; id: string }
|
||||
| { type: "navigate"; path: string }
|
||||
| { type: "external"; href: string; url: URL }
|
||||
| { type: "none" };
|
||||
|
||||
const ALLOWED_ORIGINS = [
|
||||
location.hostname,
|
||||
"app.revolt.chat",
|
||||
"nightly.revolt.chat",
|
||||
"local.revolt.chat",
|
||||
];
|
||||
|
||||
export function determineLink(href?: string): LinkType {
|
||||
let internal,
|
||||
url: URL | null = null;
|
||||
|
||||
if (href) {
|
||||
try {
|
||||
url = new URL(href, location.href);
|
||||
|
||||
if (ALLOWED_ORIGINS.includes(url.hostname)) {
|
||||
const path = url.pathname;
|
||||
if (path.startsWith("/@")) {
|
||||
const id = path.substr(2);
|
||||
if (/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}/.test(id)) {
|
||||
return { type: "profile", id };
|
||||
}
|
||||
} else {
|
||||
return { type: "navigate", path };
|
||||
}
|
||||
|
||||
internal = true;
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
if (!internal && url) {
|
||||
return { type: "external", href, url };
|
||||
}
|
||||
}
|
||||
|
||||
return { type: "none" };
|
||||
}
|
||||
@@ -73,7 +73,6 @@ export const SimpleRenderer: RendererRoutines = {
|
||||
});
|
||||
},
|
||||
edit: async (renderer) => {
|
||||
console.log("EDIT!!");
|
||||
renderer.emitScroll({
|
||||
type: "StayAtBottom",
|
||||
smooth: false,
|
||||
|
||||
Reference in New Issue
Block a user