Improve API start procedure

This commit is contained in:
Midgard 2022-06-09 15:26:44 +02:00
parent 0f8559f22a
commit bf5798c4e5
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 13 additions and 13 deletions

View file

@ -20,6 +20,7 @@ function logIn() {
client.logIn(byId("login_login_id").value, byId("login_password").value)
.then(json => {
client.start();
buttonEnable(byId("login_button"));
byId("login_message").innerText = "";
byId("channel_list").innerText = `Logged in as ${json.username}`;

View file

@ -18,7 +18,8 @@ populateServerSelectionList();
localstorage_credentials.getServers()
.map(server => server.endpoint)
.forEach(mm_client.getOrCreate);
.map(mm_client.getOrCreate)
.forEach(client => client.start());
populateChannelList();

View file

@ -9,13 +9,6 @@ class MattermostClient {
const creds = this.credentials.get(this.endpoint);
this.token = creds ? creds.token : null;
console.info(`Created MattermostClient for ${this.endpoint}, ${this.token ? "found token" : "did not find token"}`);
if (this.token) {
this.userMe().then(data => {
this.me = data;
this.websocket();
});
}
}
async get(path, queryParams) {
@ -60,6 +53,16 @@ class MattermostClient {
return data;
}
start() {
assert(this.token);
let _ = this.getUsers();
return this.userMe().then(data => {
this.me = data;
this.websocket();
});
}
async loggedIn() {
if (!this.token) {
return false;
@ -88,11 +91,6 @@ class MattermostClient {
}
this.credentials.store(this.endpoint, login_id, token);
this.token = token;
let _ = this.getUsers();
this.userMe().then(data => {
this.me = data;
this.websocket();
});
return response.responseJson;
}