2017-05-18 16:08:54 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const socket = require("../socket");
|
2019-11-03 09:59:43 -05:00
|
|
|
const {vueApp} = require("../vue");
|
2019-11-02 15:40:59 -04:00
|
|
|
const store = require("../store").default;
|
2017-05-18 16:08:54 -04:00
|
|
|
|
2017-10-01 04:52:34 -04:00
|
|
|
// Sync unread badge and marker when other clients open a channel
|
2017-05-18 16:08:54 -04:00
|
|
|
socket.on("open", function(id) {
|
2017-10-01 04:52:34 -04:00
|
|
|
if (id < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't do anything if the channel is active on this client
|
2019-11-02 15:40:59 -04:00
|
|
|
if (store.state.activeChannel && store.state.activeChannel.channel.id === id) {
|
2017-10-01 04:52:34 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the unread badge
|
2019-11-03 09:59:43 -05:00
|
|
|
const channel = store.getters.findChannel(id);
|
2018-07-06 14:15:15 -04:00
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
channel.channel.highlight = 0;
|
|
|
|
channel.channel.unread = 0;
|
2018-07-17 04:41:12 -04:00
|
|
|
|
|
|
|
if (channel.channel.messages.length > 0) {
|
2019-07-17 05:33:59 -04:00
|
|
|
channel.channel.firstUnread =
|
|
|
|
channel.channel.messages[channel.channel.messages.length - 1].id;
|
2018-07-17 04:41:12 -04:00
|
|
|
}
|
2018-07-06 14:15:15 -04:00
|
|
|
}
|
2017-10-01 04:52:34 -04:00
|
|
|
|
2019-10-17 12:56:44 -04:00
|
|
|
vueApp.synchronizeNotifiedState();
|
2017-05-18 16:08:54 -04:00
|
|
|
});
|