From 37573395b602e0559d82cca2139d84fbfb902fc0 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 24 Jun 2026 17:24:12 -0500 Subject: [PATCH] shorter invite links --- src/webpage/channel.ts | 2 +- src/webpage/guild.ts | 6 +++--- src/webpage/localuser.ts | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/webpage/channel.ts b/src/webpage/channel.ts index bd3f30f..17385f9 100644 --- a/src/webpage/channel.ts +++ b/src/webpage/channel.ts @@ -371,7 +371,7 @@ class Channel extends SnowFlake { .then((_) => _.json()) .then((json) => { const params = new URLSearchParams(""); - params.set("instance", this.info.wellknown); + params.set("instance", this.localuser.instanceString()); const encoded = params.toString(); text.textContent = `${location.origin}/invite/${json.code}?${encoded}`; }); diff --git a/src/webpage/guild.ts b/src/webpage/guild.ts index 24734e9..dfbedd4 100644 --- a/src/webpage/guild.ts +++ b/src/webpage/guild.ts @@ -64,7 +64,7 @@ export async function makeInviteMenu(inviteMenu: Options, guild: Guild, url: str "/invite/" + invite.code + "?" + - new URLSearchParams([["instance", guild.info.wellknown]]), + new URLSearchParams([["instance", guild.localuser.instanceString()]]), undefined, ), ); @@ -1282,7 +1282,7 @@ class Guild extends SnowFlake { headers: this.headers, }, ); - const search = new URLSearchParams([["instance", this.info.wellknown]]); + const search = new URLSearchParams([["instance", this.localuser.instanceString()]]); form.addMDText( new MarkDown( I18n.guild.templateURL( @@ -1431,7 +1431,7 @@ class Guild extends SnowFlake { .then((_) => _.json()) .then((json) => { const params = new URLSearchParams(""); - params.set("instance", this.info.wellknown); + params.set("instance", this.localuser.instanceString()); const encoded = params.toString(); text.textContent = `${location.origin}/invite/${json.code}?${encoded}`; }); diff --git a/src/webpage/localuser.ts b/src/webpage/localuser.ts index 3a43765..31e88cf 100644 --- a/src/webpage/localuser.ts +++ b/src/webpage/localuser.ts @@ -2,7 +2,7 @@ import {Guild} from "./guild.js"; import {Channel} from "./channel.js"; import {Direct, Group} from "./direct.js"; import {User} from "./user.js"; -import {createImg, getapiurls, getBulkUsers, installPGet, SW} from "./utils/utils.js"; +import {createImg, getapiurls, getBulkUsers, getInstances, installPGet, SW} from "./utils/utils.js"; import {getBulkInfo, setTheme, Specialuser} from "./utils/utils.js"; import { channeljson, @@ -49,6 +49,7 @@ import {getLocalSettings, ServiceWorkerModeValues} from "./utils/storage/localSe import {PromiseLock} from "./utils/promiseLock.js"; import {CDNParams} from "./utils/cdnParams.js"; import {SnowFlake} from "./snowflake.js"; +import {trimTrailingSlashes} from "./utils/netUtils.js"; type traceObj = { micros: number; calls?: (string | traceObj)[]; @@ -1451,6 +1452,18 @@ class Localuser { elms.set("online", online); this.generateListHTML(elms, channel); } + instanceString(): string { + const insts = getInstances(); + if (insts) { + for (const inst of insts) { + if (trimTrailingSlashes(inst.url ?? "") === trimTrailingSlashes(this.info.wellknown)) { + return inst.name; + } + } + } + console.log("failed with", insts, this.info.wellknown); + return this.info.wellknown; + } roleListMap = new WeakMap< HTMLDivElement, { @@ -3485,7 +3498,7 @@ class Localuser { } else if (format.index === 2) { if (urlOptionsJSON.type === "Fermi") { const options = new URLSearchParams(); - options.set("instance", this.info.wellknown); + options.set("instance", this.instanceString()); pre.textContent = json.tokens .map((token) => { options.set("token", token);