Rename function to better reflect effect

This commit is contained in:
Midgard 2022-06-09 14:35:49 +02:00
parent 4480477e49
commit 64285bdf71
Signed by: midgard
GPG key ID: 511C112F1331BBB4
5 changed files with 11 additions and 11 deletions

View file

@ -14,7 +14,7 @@ function buttonEnable(element) {
} }
function logIn() { 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..."); buttonDisable(byId("login_button"), "Logging in...");
@ -39,7 +39,7 @@ function logIn() {
} }
function logOut(endpoint, button) { function logOut(endpoint, button) {
const client = mm_client.get(endpoint); const client = mm_client.getOrCreate(endpoint);
buttonDisable(button, "Logging out..."); buttonDisable(button, "Logging out...");
@ -153,7 +153,7 @@ function switchToChannel(client, team, channel) {
} }
function sendMessage(endpoint, channel_id, message) { function sendMessage(endpoint, channel_id, message) {
const client = mm_client.get(endpoint); const client = mm_client.getOrCreate(endpoint);
client.writePost(channel_id, message); client.writePost(channel_id, message);
//pubsub.publish("MESSAGES_NEW", { //pubsub.publish("MESSAGES_NEW", {
//endpoint, //endpoint,
@ -165,7 +165,7 @@ function sendMessage(endpoint, channel_id, message) {
} }
async function executeSlashCommand(endpoint, channel_id, command) { 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); const response = await client.executeSlashCommand(channel_id, command);
if ( if (

View file

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

View file

@ -216,21 +216,21 @@ class MattermostClient {
let clients = Object.create(null); let clients = Object.create(null);
function get(endpoint) { function getOrCreate(endpoint) {
if (!clients[endpoint]) { if (!clients[endpoint]) {
clients[endpoint] = new MattermostClient(endpoint, localstorage_credentials); clients[endpoint] = new MattermostClient(endpoint, localstorage_credentials);
} }
return clients[endpoint]; return clients[endpoint];
} }
function getMultiple(endpoints) { function getOrCreateMultiple(endpoints) {
return endpoints.map(get); return endpoints.map(getOrCreate);
} }
function drop(endpoint) { function drop(endpoint) {
delete clients[endpoint]; delete clients[endpoint];
} }
return {get, getMultiple, drop}; return {getOrCreate, getOrCreateMultiple, drop};
})(); })();

View file

@ -152,6 +152,6 @@ function currentChannel() {
pubsub.subscribe("MESSAGES_NEW", post => { pubsub.subscribe("MESSAGES_NEW", post => {
const chan = currentChannel(); const chan = currentChannel();
if (post.endpoint === chan.endpoint && post.channel_id === chan.channel_id) { 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);
} }
}); });

View file

@ -69,7 +69,7 @@ function populateChannelList() {
byId("channel_list").innerHTML = ""; byId("channel_list").innerHTML = "";
const endpoints = localstorage_credentials.getServers().map(server => server.endpoint); 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); addChannelItems(client);
} }
} }