Add DMs; update channel list when new channel arrives
This commit is contained in:
parent
245cfae68a
commit
60f047c0fd
3 changed files with 17 additions and 6 deletions
|
@ -61,7 +61,7 @@ function logOut(endpoint, button) {
|
||||||
mm_client.drop(endpoint);
|
mm_client.drop(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
function channelNameElements(team, channel) {
|
function channelNameElements(team, channel, me, users) {
|
||||||
const teamName = team ? team.name : "";
|
const teamName = team ? team.name : "";
|
||||||
const inTeam = teamName ? " in team " + teamName : "";
|
const inTeam = teamName ? " in team " + teamName : "";
|
||||||
let icon = "";
|
let icon = "";
|
||||||
|
@ -77,8 +77,10 @@ function channelNameElements(team, channel) {
|
||||||
title = `${channel.name}${inTeam} (private)`;
|
title = `${channel.name}${inTeam} (private)`;
|
||||||
break;
|
break;
|
||||||
case "D": // Direct message
|
case "D": // Direct message
|
||||||
return undefined; // XXX Because they clutter the list
|
const participants = channel.name.split("__");
|
||||||
channelName = `👤 ...`;
|
const other = participants[0] === me ? participants[1] : participants[0];
|
||||||
|
const userName = users[other]["username"];
|
||||||
|
channelName = `👤 ${userName}`;
|
||||||
title = `Direct message`;
|
title = `Direct message`;
|
||||||
break;
|
break;
|
||||||
case "G": // Group chat
|
case "G": // Group chat
|
||||||
|
@ -117,7 +119,7 @@ function channelNameElements(team, channel) {
|
||||||
return [title, elements];
|
return [title, elements];
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchToChannel(client, team, channel) {
|
async function switchToChannel(client, team, channel) {
|
||||||
for (let el of byId("channel_list").childNodes) {
|
for (let el of byId("channel_list").childNodes) {
|
||||||
if (el.dataset["server"] == client.endpoint && el.dataset["id"] == channel.id) {
|
if (el.dataset["server"] == client.endpoint && el.dataset["id"] == channel.id) {
|
||||||
addClass(el, "active");
|
addClass(el, "active");
|
||||||
|
@ -140,7 +142,8 @@ function switchToChannel(client, team, channel) {
|
||||||
byId("channel_contents").innerText = `Failed to get channel contents:\n${error.message}`;
|
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").innerHTML = "";
|
||||||
byId("channel_header").append(...elements);
|
byId("channel_header").append(...elements);
|
||||||
byId("compose").setAttribute("placeholder", `Write to ${byId("channel_header").textContent}`);
|
byId("compose").setAttribute("placeholder", `Write to ${byId("channel_header").textContent}`);
|
||||||
|
|
|
@ -227,6 +227,13 @@ class MattermostClient {
|
||||||
data.event === "user_removed"
|
data.event === "user_removed"
|
||||||
) {
|
) {
|
||||||
this.regetUsers();
|
this.regetUsers();
|
||||||
|
|
||||||
|
} else if (
|
||||||
|
data.event === "group_added" ||
|
||||||
|
data.event === "channel_created" ||
|
||||||
|
data.event === "channel_deleted"
|
||||||
|
) {
|
||||||
|
this.channelStore.fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,7 @@ function populateServerSelectionList() {
|
||||||
function populateChannelList() {
|
function populateChannelList() {
|
||||||
async function addChannelItems(client) {
|
async function addChannelItems(client) {
|
||||||
const {teams, channels, unread} = await client.channelStore.get();
|
const {teams, channels, unread} = await client.channelStore.get();
|
||||||
|
const users = await client.getUsers();
|
||||||
|
|
||||||
let nodes = [];
|
let nodes = [];
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ function populateChannelList() {
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
a.href = "javascript:void(0)";
|
a.href = "javascript:void(0)";
|
||||||
const titleAndElements = channelNameElements(team, channel);
|
const titleAndElements = channelNameElements(team, channel, client.me["id"], users);
|
||||||
if (!titleAndElements) continue;
|
if (!titleAndElements) continue;
|
||||||
a.title = titleAndElements[0];
|
a.title = titleAndElements[0];
|
||||||
a.append(...titleAndElements[1]);
|
a.append(...titleAndElements[1]);
|
||||||
|
|
Loading…
Reference in a new issue