thelounge/client/js/socket-events/open.js
Pavel Djundik 2f635069e0 Move vuex state to a separate file and reorganize some code
Co-Authored-By: Tim Miller-Williams <timmw@users.noreply.github.com>
2019-11-25 20:12:54 +02:00

33 lines
768 B
JavaScript

"use strict";
const socket = require("../socket");
const {vueApp, findChannel} = require("../vue");
const store = require("../store").default;
// Sync unread badge and marker when other clients open a channel
socket.on("open", function(id) {
if (id < 1) {
return;
}
// Don't do anything if the channel is active on this client
if (store.state.activeChannel && store.state.activeChannel.channel.id === id) {
return;
}
// Clear the unread badge
const channel = findChannel(id);
if (channel) {
channel.channel.highlight = 0;
channel.channel.unread = 0;
if (channel.channel.messages.length > 0) {
channel.channel.firstUnread =
channel.channel.messages[channel.channel.messages.length - 1].id;
}
}
vueApp.synchronizeNotifiedState();
});