2020-11-09 10:26:56 +01:00
|
|
|
export default class User {
|
2021-01-27 12:57:23 +01:00
|
|
|
constructor(home_server, user_id, password, is_guest) {
|
|
|
|
|
this.home_server = home_server;
|
|
|
|
|
this.user_id = user_id;
|
2020-11-09 10:26:56 +01:00
|
|
|
this.password = password;
|
2020-11-25 10:02:24 +01:00
|
|
|
this.is_guest = is_guest || false
|
2020-11-09 10:26:56 +01:00
|
|
|
}
|
2021-01-27 12:57:23 +01:00
|
|
|
|
2021-06-29 17:02:40 +02:00
|
|
|
normalize = function () {
|
2021-01-27 12:57:23 +01:00
|
|
|
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(":");
|
|
|
|
|
return parts[0].substring(1);
|
|
|
|
|
}
|
|
|
|
|
return user_id;
|
|
|
|
|
}
|
2021-06-29 17:02:40 +02:00
|
|
|
|
|
|
|
|
static serverName(user_id) {
|
|
|
|
|
if (user_id && user_id.startsWith('@') && user_id.includes(':')) {
|
|
|
|
|
const parts = user_id.split(":");
|
|
|
|
|
return parts[1];
|
|
|
|
|
}
|
|
|
|
|
return user_id;
|
|
|
|
|
}
|
2023-10-09 19:10:07 +02:00
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
|
}
|
2020-11-09 10:26:56 +01:00
|
|
|
}
|