2017-05-18 20:08:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../socket");
|
|
|
|
|
2017-10-01 08:52:34 +00:00
|
|
|
// Sync unread badge and marker when other clients open a channel
|
2017-05-18 20:08:54 +00:00
|
|
|
socket.on("open", function(id) {
|
2017-10-01 08:52:34 +00:00
|
|
|
if (id < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const channel = $("#chat #chan-" + id);
|
|
|
|
|
|
|
|
// Don't do anything if the channel is active on this client
|
|
|
|
if (channel.length === 0 || channel.hasClass("active")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the unread badge
|
2017-05-18 20:08:54 +00:00
|
|
|
$("#sidebar").find(".chan[data-id='" + id + "'] .badge")
|
|
|
|
.removeClass("highlight")
|
|
|
|
.empty();
|
2017-10-01 08:52:34 +00:00
|
|
|
|
|
|
|
// Move unread marker to the bottom
|
|
|
|
channel
|
|
|
|
.find(".unread-marker")
|
|
|
|
.data("unread-id", 0)
|
|
|
|
.appendTo(channel.find(".messages"));
|
2017-05-18 20:08:54 +00:00
|
|
|
});
|