diff --git a/js/controller.js b/js/controller.js index 6bbaf05..5047a1d 100644 --- a/js/controller.js +++ b/js/controller.js @@ -133,13 +133,7 @@ function switchToChannel(client, team, channel) { response.order.reverse(); populateChannelContents(client, channel, response); - markChannelAsRead(client, channel) - .then(_ => { - pubsub.publish("CHANNEL_READ", { - endpoint: client.endpoint, - channel_id: channel.id - }); - }); + markChannelAsRead(client, channel); }) .catch(error => { console.error(error); diff --git a/js/mm_client.js b/js/mm_client.js index f312a26..f5e2043 100644 --- a/js/mm_client.js +++ b/js/mm_client.js @@ -207,7 +207,11 @@ class MattermostClient { if (data.event === "posted") { const post = JSON.parse(data.data.post); 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}); } + }); }