diff --git a/js/controller.js b/js/controller.js index b0c5b8c..cf31ec7 100644 --- a/js/controller.js +++ b/js/controller.js @@ -61,7 +61,7 @@ function logOut(endpoint, button) { mm_client.drop(endpoint); } -function channelNameElements(team, channel) { +function channelNameElements(team, channel, me, users) { const teamName = team ? team.name : ""; const inTeam = teamName ? " in team " + teamName : ""; let icon = ""; @@ -77,8 +77,10 @@ function channelNameElements(team, channel) { title = `${channel.name}${inTeam} (private)`; break; case "D": // Direct message - return undefined; // XXX Because they clutter the list - channelName = `👤 ...`; + const participants = channel.name.split("__"); + const other = participants[0] === me ? participants[1] : participants[0]; + const userName = users[other]["username"]; + channelName = `👤 ${userName}`; title = `Direct message`; break; case "G": // Group chat @@ -117,7 +119,7 @@ function channelNameElements(team, channel) { return [title, elements]; } -function switchToChannel(client, team, channel) { +async function switchToChannel(client, team, channel) { for (let el of byId("channel_list").childNodes) { if (el.dataset["server"] == client.endpoint && el.dataset["id"] == channel.id) { addClass(el, "active"); @@ -140,7 +142,8 @@ function switchToChannel(client, team, channel) { byId("channel_contents").innerText = `Failed to get channel contents:\n${error.message}`; }); - const [title, elements] = channelNameElements(team, channel); + const users = await client.getUsers(); + const [title, elements] = channelNameElements(team, channel, client.me["id"], users); byId("channel_header").innerHTML = ""; byId("channel_header").append(...elements); byId("compose").setAttribute("placeholder", `Write to ${byId("channel_header").textContent}`); diff --git a/js/mm_client.js b/js/mm_client.js index 6fa8c64..e709671 100644 --- a/js/mm_client.js +++ b/js/mm_client.js @@ -227,6 +227,13 @@ class MattermostClient { data.event === "user_removed" ) { this.regetUsers(); + + } else if ( + data.event === "group_added" || + data.event === "channel_created" || + data.event === "channel_deleted" + ) { + this.channelStore.fetch(); } }); diff --git a/js/view/sidebar.js b/js/view/sidebar.js index adb18b5..18cbe78 100644 --- a/js/view/sidebar.js +++ b/js/view/sidebar.js @@ -22,6 +22,7 @@ function populateServerSelectionList() { function populateChannelList() { async function addChannelItems(client) { const {teams, channels, unread} = await client.channelStore.get(); + const users = await client.getUsers(); let nodes = []; @@ -38,7 +39,7 @@ function populateChannelList() { const li = document.createElement("li"); const a = document.createElement("a"); a.href = "javascript:void(0)"; - const titleAndElements = channelNameElements(team, channel); + const titleAndElements = channelNameElements(team, channel, client.me["id"], users); if (!titleAndElements) continue; a.title = titleAndElements[0]; a.append(...titleAndElements[1]);