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) client.logIn(byId("login_login_id").value, byId("login_password").value)
.then(json => { .then(json => {
client.start();
buttonEnable(byId("login_button")); buttonEnable(byId("login_button"));
byId("login_message").innerText = ""; byId("login_message").innerText = "";
byId("channel_list").innerText = `Logged in as ${json.username}`; byId("channel_list").innerText = `Logged in as ${json.username}`;

View file

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

View file

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