2019-11-16 19:24:03 +02:00
|
|
|
import socket from "../socket";
|
2022-06-18 16:25:21 -08:00
|
|
|
import {store} from "../store";
|
2017-05-18 21:08:54 +01:00
|
|
|
|
2017-10-01 11:52:34 +03:00
|
|
|
// Sync unread badge and marker when other clients open a channel
|
2020-03-21 22:55:36 +02:00
|
|
|
socket.on("open", function (id) {
|
2017-10-01 11:52:34 +03:00
|
|
|
if (id < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't do anything if the channel is active on this client
|
2019-11-02 21:40:59 +02:00
|
|
|
if (store.state.activeChannel && store.state.activeChannel.channel.id === id) {
|
2017-10-01 11:52:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the unread badge
|
2019-11-03 16:59:43 +02:00
|
|
|
const channel = store.getters.findChannel(id);
|
2018-07-06 21:15:15 +03:00
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
channel.channel.highlight = 0;
|
|
|
|
channel.channel.unread = 0;
|
2018-07-17 11:41:12 +03:00
|
|
|
|
|
|
|
if (channel.channel.messages.length > 0) {
|
2019-07-17 10:33:59 +01:00
|
|
|
channel.channel.firstUnread =
|
|
|
|
channel.channel.messages[channel.channel.messages.length - 1].id;
|
2018-07-17 11:41:12 +03:00
|
|
|
}
|
2018-07-06 21:15:15 +03:00
|
|
|
}
|
2017-05-18 21:08:54 +01:00
|
|
|
});
|