|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
const tippy = require("tippy.js");
|
|
|
|
|
const {q, ElemJS, ejs} = require("./basic.js")
|
|
|
|
|
const {S_RE_DOMAIN, S_RE_IPV6, S_RE_IPV4} = require("./re.js")
|
|
|
|
|
|
|
|
|
@ -52,6 +53,16 @@ class Username extends ElemJS {
|
|
|
|
|
class Homeserver extends ElemJS {
|
|
|
|
|
constructor() {
|
|
|
|
|
super(q("#homeserver"));
|
|
|
|
|
|
|
|
|
|
this.tippy = tippy.default(q("#homeserver-question"), {
|
|
|
|
|
content: q("#homeserver-popup-template").innerHTML,
|
|
|
|
|
allowHTML: true,
|
|
|
|
|
interactive: true,
|
|
|
|
|
interactiveBorder: 10,
|
|
|
|
|
trigger: "mouseenter",
|
|
|
|
|
theme: "carbon",
|
|
|
|
|
arrow: tippy.roundArrow,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suggest(value) {
|
|
|
|
@ -85,7 +96,7 @@ class Feedback extends ElemJS {
|
|
|
|
|
this.removeClass("form-feedback")
|
|
|
|
|
this.removeClass("form-error")
|
|
|
|
|
if (content) this.class("form-feedback")
|
|
|
|
|
if(isError) this.class("form-error")
|
|
|
|
|
if (isError) this.class("form-error")
|
|
|
|
|
|
|
|
|
|
this.messageSpan.text(content)
|
|
|
|
|
}
|
|
|
|
@ -112,7 +123,7 @@ class Form extends ElemJS {
|
|
|
|
|
let domain
|
|
|
|
|
try {
|
|
|
|
|
domain = await this.findHomeserver(this.homeserver.getServer())
|
|
|
|
|
} catch(e) {
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return this.cancel(e.message)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -149,16 +160,16 @@ class Form extends ElemJS {
|
|
|
|
|
//Protects from servers sending us on a redirect loop
|
|
|
|
|
maxDepth--
|
|
|
|
|
if (maxDepth <= 0) throw new Error(`Failed to look up homeserver, maximum search depth reached`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Normalise the address
|
|
|
|
|
if (!address.match(/^https?:\/\//)) {
|
|
|
|
|
console.warn(`${address} doesn't specify the protocol, assuming https`)
|
|
|
|
|
address = "https://" + address
|
|
|
|
|
}
|
|
|
|
|
address = address.replace(/\/*$/, "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.status(`Looking up homeserver... trying ${address}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if we found the actual matrix server
|
|
|
|
|
try {
|
|
|
|
|
const versionsReq = await fetch(`${address}/_matrix/client/versions`)
|
|
|
|
@ -166,11 +177,11 @@ class Form extends ElemJS {
|
|
|
|
|
const versions = await versionsReq.json()
|
|
|
|
|
if (Array.isArray(versions.versions)) return address
|
|
|
|
|
}
|
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
|
|
// Find the next matrix server in the chain
|
|
|
|
|
const root = await fetch(`${address}/.well-known/matrix/client`).then(res => res.json()).catch(e => {
|
|
|
|
|
console.error(e)
|
|
|
|
|
console.error(e)
|
|
|
|
|
throw new Error(`Failed to look up server ${address}`)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|