Support new multiple_channels_viewed event

This commit is contained in:
Midgard 2023-11-08 14:40:13 +01:00
parent 916a9b1839
commit 41276481a6
Signed by: midgard
GPG key ID: 511C112F1331BBB4
4 changed files with 30 additions and 4 deletions

View file

@ -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", () => {

View file

@ -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" ||

View file

@ -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",
];

View file

@ -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