Sort channels by last used
This commit is contained in:
parent
c3a24ee300
commit
245cfae68a
4 changed files with 32 additions and 3 deletions
|
@ -216,6 +216,8 @@ pubsub.subscribe("MESSAGES_NEW", post => {
|
|||
} else {
|
||||
client.channelStore.increaseUnread(post);
|
||||
}
|
||||
|
||||
client.channelStore.updateLastPostTime(post.channel_id, post["create_at"]);
|
||||
});
|
||||
|
||||
pubsub.subscribe("CHANNEL_READ", ({endpoint, channel_id}) => {
|
||||
|
|
|
@ -6,6 +6,7 @@ const topics = [
|
|||
"CHANNELS_RELOADED", //
|
||||
"CHANNEL_UPDATED", // {endpoint, channel}
|
||||
"CHANNEL_UNREAD_UPDATED", // {endpoint, channel_id, unread, mentions}
|
||||
"CHANNEL_LAST_POST_TIME_UPDATED", // {endpoint, channel_id, time}
|
||||
"USERS_NEW",
|
||||
"USERS_CHANGED",
|
||||
"CHANNEL_MEMBERS_NEW",
|
||||
|
|
12
js/store.js
12
js/store.js
|
@ -98,6 +98,18 @@ class ChannelStore {
|
|||
|
||||
pubsub.publish("CHANNEL_UNREAD_UPDATED", {endpoint: this.client.endpoint, channel_id, unread, mentions});
|
||||
}
|
||||
|
||||
async updateLastPostTime(channel_id, time) {
|
||||
if (this._promise === null) {
|
||||
// Data does not exist yet and is not being requested
|
||||
return;
|
||||
}
|
||||
await this._promise;
|
||||
|
||||
this._channels[channel_id]["last_post_at"] = time;
|
||||
|
||||
pubsub.publish("CHANNEL_LAST_POST_TIME_UPDATED", {endpoint: this.client.endpoint, channel_id, time});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,8 +25,11 @@ function populateChannelList() {
|
|||
|
||||
let nodes = [];
|
||||
|
||||
for (let channel_id in channels) {
|
||||
const channel = channels[channel_id];
|
||||
let sortedChannels = Object.values(channels).sort((a, b) =>
|
||||
b["last_post_at"] - a["last_post_at"]
|
||||
);
|
||||
|
||||
for (const channel of sortedChannels) {
|
||||
const team = teams[channel["team_id"]];
|
||||
|
||||
const chanUnread = unread[channel.id].unread;
|
||||
|
@ -53,7 +56,14 @@ function populateChannelList() {
|
|||
li.dataset["id"] = channel.id;
|
||||
li.dataset["server"] = client.endpoint;
|
||||
|
||||
if (chanUnread > 0) li.className = "unread";
|
||||
const curChan = currentChannel();
|
||||
if (curChan.endpoint === client.endpoint && curChan.channel_id === channel.id) {
|
||||
li.className = "active";
|
||||
}
|
||||
if (chanUnread > 0) {
|
||||
li.className += " unread";
|
||||
}
|
||||
|
||||
nodes.push(li);
|
||||
}
|
||||
byId("channel_list").append(...nodes);
|
||||
|
@ -92,3 +102,7 @@ pubsub.subscribe("CHANNEL_UNREAD_UPDATED", ({endpoint, channel_id, unread, menti
|
|||
pubsub.subscribe("CHANNELS_RELOADED", () => {
|
||||
populateChannelList();
|
||||
});
|
||||
|
||||
pubsub.subscribe("CHANNEL_LAST_POST_TIME_UPDATED", () => {
|
||||
populateChannelList();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue