thelounge/client/js/socket-events/open.js

36 lines
817 B
JavaScript
Raw Normal View History

2017-05-18 22:08:54 +02:00
"use strict";
const $ = require("jquery");
const socket = require("../socket");
const utils = require("../utils");
const {vueApp, findChannel} = require("../vue");
2017-05-18 22:08:54 +02:00
// Sync unread badge and marker when other clients open a channel
2017-05-18 22:08:54 +02:00
socket.on("open", function(id) {
if (id < 1) {
return;
}
// Don't do anything if the channel is active on this client
if (vueApp.activeChannel && vueApp.activeChannel.channel.id === id) {
return;
}
// Clear the unread badge
const channel = findChannel(id);
if (channel) {
channel.channel.highlight = 0;
channel.channel.unread = 0;
}
utils.updateTitle();
// Move unread marker to the bottom
const channelContainer = $("#chat #chan-" + id);
channelContainer
.find(".unread-marker")
.data("unread-id", 0)
.appendTo(channelContainer.find(".messages"));
2017-05-18 22:08:54 +02:00
});