keanu-weblite/src/models/user.js

32 lines
980 B
JavaScript
Raw Normal View History

2020-11-09 10:26:56 +01:00
export default class User {
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
}
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(":");
return parts[0].substring(1);
}
return user_id;
}
static serverName(user_id) {
if (user_id && user_id.startsWith('@') && user_id.includes(':')) {
const parts = user_id.split(":");
return parts[1];
}
return user_id;
}
2020-11-09 10:26:56 +01:00
}