diff --git a/webpage/channel.ts b/webpage/channel.ts index da043a8..3bb081f 100644 --- a/webpage/channel.ts +++ b/webpage/channel.ts @@ -658,7 +658,7 @@ class Channel{ const prom=this.infinite.delete(); history.pushState(null, "","/channels/"+this.guild_id+"/"+this.snowflake); - (document.getElementById("channelname") as HTMLSpanElement).textContent="#"+this.name; + this.localuser.pageTitle("#"+this.name); const channelTopic=document.getElementById("channelTopic") as HTMLSpanElement; if (this.topic) { channelTopic.innerHTML=new MarkDown(this.topic, this).makeHTML().innerHTML; diff --git a/webpage/direct.ts b/webpage/direct.ts index 5fc543b..e258e47 100644 --- a/webpage/direct.ts +++ b/webpage/direct.ts @@ -138,7 +138,7 @@ class Group extends Channel{ } this.buildmessages(); history.pushState(null, "","/channels/"+this.guild_id+"/"+this.id); - (document.getElementById("channelname") as HTMLElement).textContent="@"+this.name; + this.localuser.pageTitle("@"+this.name); (document.getElementById("channelTopic") as HTMLElement).setAttribute("hidden",""); (document.getElementById("typebox") as HTMLDivElement).contentEditable=""+true; } diff --git a/webpage/localuser.ts b/webpage/localuser.ts index dcd02f8..fb50dda 100644 --- a/webpage/localuser.ts +++ b/webpage/localuser.ts @@ -37,6 +37,9 @@ class Localuser{ typing:Map=new Map(); connectionSucceed=0; errorBackoff=0; + instancePing={ + name:"Unknown", + }; mfa_enabled:boolean; constructor(userinfo:Specialuser|-1){ if(userinfo===-1){ @@ -100,6 +103,8 @@ class Localuser{ user.nickname=thing.nickname; user.relationshipType=thing.type; } + + this.pingEndpoint() } outoffocus():void{ const servers=document.getElementById("servers") as HTMLDivElement; @@ -1353,6 +1358,39 @@ class Localuser{ }) } } + async pingEndpoint() { + const userInfo = getBulkInfo(); + if (!userInfo.instances) userInfo.instances = {}; + const wellknown = this.info.wellknown; + if (!userInfo.instances[wellknown]) { + const pingRes = await fetch(this.info.api + "/ping"); + const pingJSON = await pingRes.json(); + userInfo.instances[wellknown] = pingJSON; + localStorage.setItem("userinfos", JSON.stringify(userInfo)); + } + this.instancePing = userInfo.instances[wellknown].instance; + + this.pageTitle("Loading..."); + } + pageTitle(channelName = "", guildName = "") { + (document.getElementById("channelname") as HTMLSpanElement).textContent = channelName; + (document.getElementsByTagName("title")[0] as HTMLTitleElement).textContent = channelName + (guildName ? " | " + guildName : "") + " | " + this.instancePing.name + " | Jank Client (Tomato fork)"; + } + async instanceStats() { + const res = await fetch(this.info.api + "/policies/stats", { + headers: this.headers + }); + const json = await res.json(); + + const dialog = new Dialog(["vdiv", + ["title", "Instance stats: " + this.instancePing.name], + ["text", "Registered users: " + json.counts.user], + ["text", "Servers: " + json.counts.guild], + ["text", "Messages: " + json.counts.message], + ["text", "Members: " + json.counts.members] + ]); + dialog.show(); + } } export {Localuser}; let fixsvgtheme:Function;