diff --git a/js/controller.js b/js/controller.js index 864160d..6bbaf05 100644 --- a/js/controller.js +++ b/js/controller.js @@ -14,7 +14,7 @@ function buttonEnable(element) { } function logIn() { - const client = mm_client.get(normalizedEndpoint(byId("login_server").value)); + const client = mm_client.getOrCreate(normalizedEndpoint(byId("login_server").value)); buttonDisable(byId("login_button"), "Logging in..."); @@ -39,7 +39,7 @@ function logIn() { } function logOut(endpoint, button) { - const client = mm_client.get(endpoint); + const client = mm_client.getOrCreate(endpoint); buttonDisable(button, "Logging out..."); @@ -153,7 +153,7 @@ function switchToChannel(client, team, channel) { } function sendMessage(endpoint, channel_id, message) { - const client = mm_client.get(endpoint); + const client = mm_client.getOrCreate(endpoint); client.writePost(channel_id, message); //pubsub.publish("MESSAGES_NEW", { //endpoint, @@ -165,7 +165,7 @@ function sendMessage(endpoint, channel_id, message) { } async function executeSlashCommand(endpoint, channel_id, command) { - const client = mm_client.get(endpoint); + const client = mm_client.getOrCreate(endpoint); const response = await client.executeSlashCommand(channel_id, command); if ( diff --git a/js/main.js b/js/main.js index 3cdca13..c2998bb 100644 --- a/js/main.js +++ b/js/main.js @@ -18,7 +18,7 @@ populateServerSelectionList(); localstorage_credentials.getServers() .map(server => server.endpoint) - .map(mm_client.get) + .map(mm_client.getOrCreate) .forEach(client => client.getUsers()); populateChannelList(); diff --git a/js/mm_client.js b/js/mm_client.js index 02f9eea..f312a26 100644 --- a/js/mm_client.js +++ b/js/mm_client.js @@ -216,21 +216,21 @@ class MattermostClient { let clients = Object.create(null); -function get(endpoint) { +function getOrCreate(endpoint) { if (!clients[endpoint]) { clients[endpoint] = new MattermostClient(endpoint, localstorage_credentials); } return clients[endpoint]; } -function getMultiple(endpoints) { - return endpoints.map(get); +function getOrCreateMultiple(endpoints) { + return endpoints.map(getOrCreate); } function drop(endpoint) { delete clients[endpoint]; } -return {get, getMultiple, drop}; +return {getOrCreate, getOrCreateMultiple, drop}; })(); diff --git a/js/view/messages.js b/js/view/messages.js index 0fa2848..9fcecaf 100644 --- a/js/view/messages.js +++ b/js/view/messages.js @@ -152,6 +152,6 @@ function currentChannel() { pubsub.subscribe("MESSAGES_NEW", post => { const chan = currentChannel(); if (post.endpoint === chan.endpoint && post.channel_id === chan.channel_id) { - addMessage(mm_client.get(post.endpoint), post); + addMessage(mm_client.getOrCreate(post.endpoint), post); } }); diff --git a/js/view/sidebar.js b/js/view/sidebar.js index 7c16282..6f5f79e 100644 --- a/js/view/sidebar.js +++ b/js/view/sidebar.js @@ -69,7 +69,7 @@ function populateChannelList() { byId("channel_list").innerHTML = ""; const endpoints = localstorage_credentials.getServers().map(server => server.endpoint); - for (let client of mm_client.getMultiple(endpoints)) { + for (let client of mm_client.getOrCreateMultiple(endpoints)) { addChannelItems(client); } }