diff --git a/js/controller.js b/js/controller.js index da82b88..761d930 100644 --- a/js/controller.js +++ b/js/controller.js @@ -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}`; diff --git a/js/main.js b/js/main.js index aa94dc6..bf17d3d 100644 --- a/js/main.js +++ b/js/main.js @@ -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(); diff --git a/js/mm_client.js b/js/mm_client.js index f5e2043..c6b1954 100644 --- a/js/mm_client.js +++ b/js/mm_client.js @@ -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; }