Support new multiple_channels_viewed event
This commit is contained in:
parent
916a9b1839
commit
41276481a6
4 changed files with 30 additions and 4 deletions
|
@ -223,8 +223,20 @@ pubsub.subscribe("MESSAGES_NEW", post => {
|
|||
client.channelStore.updateLastPostTime(post.channel_id, post["create_at"]);
|
||||
});
|
||||
|
||||
pubsub.subscribe("CHANNEL_READ", ({endpoint, channel_id}) => {
|
||||
mm_client.getOrCreate(endpoint).channelStore.setUnread(channel_id, 0, 0);
|
||||
pubsub.subscribe("CHANNEL_READ", ({endpoint, channel_id, time}) => {
|
||||
const chanStore = mm_client.getOrCreate(endpoint).channelStore;
|
||||
const store = chanStore.getNoFetch();
|
||||
if (
|
||||
store !== null && channel_id in store.channels &&
|
||||
time !== null && time < store.channels[channel_id]["last_post_at"]
|
||||
) {
|
||||
// We don't keep track of messages, immediately writing them to the DOM instead, so we don't
|
||||
// know how many unread messages there are when we get a "channel read up to a certain
|
||||
// timestamp" if there are newer messages than that. So refetch the channel list.
|
||||
chanStore.fetch();
|
||||
} else {
|
||||
mm_client.getOrCreate(endpoint).channelStore.setUnread(channel_id, 0, 0);
|
||||
}
|
||||
});
|
||||
|
||||
pubsub.subscribe("WINDOW_FOCUSED", () => {
|
||||
|
|
|
@ -245,7 +245,14 @@ class MattermostClient {
|
|||
pubsub.publish("MESSAGES_NEW", {...post, endpoint: this.endpoint});
|
||||
|
||||
} else if (data.event === "channel_viewed") {
|
||||
pubsub.publish("CHANNEL_READ", {endpoint: this.endpoint, channel_id: data.data.channel_id});
|
||||
pubsub.publish("CHANNEL_READ", {endpoint: this.endpoint, channel_id: data.data.channel_id, time: null});
|
||||
|
||||
} else if (data.event === "multiple_channels_viewed") {
|
||||
console.log(data.data.channel_times);
|
||||
for (let channel_id in data.data.channel_times) {
|
||||
const time = data.data.channel_times[channel_id];
|
||||
pubsub.publish("CHANNEL_READ", {endpoint: this.endpoint, channel_id, time});
|
||||
}
|
||||
|
||||
} else if (
|
||||
data.event === "user_added" ||
|
||||
|
|
|
@ -11,7 +11,7 @@ const topics = [
|
|||
"USERS_CHANGED",
|
||||
"CHANNEL_MEMBERS_NEW",
|
||||
"CHANNEL_MEMBERS_REMOVED",
|
||||
"CHANNEL_READ", // {endpoint, channel_id}
|
||||
"CHANNEL_READ", // {endpoint, channel_id, time}
|
||||
"WINDOW_FOCUSED",
|
||||
];
|
||||
|
||||
|
|
|
@ -62,6 +62,13 @@ class ChannelStore {
|
|||
return {teams: this._teams, channels: this._channels, unread: this._unread};
|
||||
}
|
||||
|
||||
getNoFetch() {
|
||||
if (this._promise === null) {
|
||||
return null;
|
||||
}
|
||||
return {teams: this._teams, channels: this._channels, unread: this._unread};
|
||||
}
|
||||
|
||||
async updateChannel(channel) {
|
||||
if (this._promise === null) {
|
||||
// Data does not exist yet and is not being requested
|
||||
|
|
Loading…
Reference in a new issue