Improved BaseURL and DM link handling

This commit is contained in:
N Pex 2023-12-01 08:20:03 +00:00
parent b14749c28f
commit dd70e4a576
9 changed files with 373 additions and 322 deletions

View file

@ -1,19 +1,10 @@
export default class User {
constructor(home_server, user_id, password, is_guest) {
this.home_server = home_server;
constructor(user_id, password, is_guest) {
this.user_id = user_id;
this.password = password;
this.is_guest = is_guest || false
}
normalize = function () {
if (this.user_id.startsWith('@') && this.user_id.includes(':')) {
const parts = this.user_id.split(":");
this.user_id = parts[0].substring(1);
this.home_server = "https://" + parts[1];
}
};
static localPart(user_id) {
if (user_id && user_id.startsWith('@') && user_id.includes(':')) {
const parts = user_id.split(":");
@ -22,19 +13,11 @@ export default class User {
return user_id;
}
static serverName(user_id) {
static domainPart(user_id) {
if (user_id && user_id.startsWith('@') && user_id.includes(':')) {
const parts = user_id.split(":");
return parts[1];
}
return user_id;
}
// Get the domain out of the home_server, so if that one is e.g.
// "https://yourdomain.com:8008" then we return "yourdomain.com"
static serverDomain(home_server) {
const parts = home_server.split("://");
const serverAndPort = parts[parts.length - 1].split(/:|\//);
return serverAndPort[0];
return undefined;
}
}