2017-05-18 20:08:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../socket");
|
2018-06-21 13:51:07 +00:00
|
|
|
const utils = require("../utils");
|
2018-07-06 18:15:15 +00:00
|
|
|
const {vueApp, findChannel} = require("../vue");
|
2017-05-18 20:08:54 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't do anything if the channel is active on this client
|
2018-07-06 18:15:15 +00:00
|
|
|
if (vueApp.activeChannel && vueApp.activeChannel.channel.id === id) {
|
2017-10-01 08:52:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the unread badge
|
2018-07-06 18:15:15 +00:00
|
|
|
const channel = findChannel(id);
|
|
|
|
|
|
|
|
if (channel) {
|
|
|
|
channel.channel.highlight = 0;
|
|
|
|
channel.channel.unread = 0;
|
|
|
|
}
|
2017-10-01 08:52:34 +00:00
|
|
|
|
2018-06-21 13:51:07 +00:00
|
|
|
utils.updateTitle();
|
|
|
|
|
2017-10-01 08:52:34 +00:00
|
|
|
// Move unread marker to the bottom
|
2018-07-06 18:15:15 +00:00
|
|
|
const channelContainer = $("#chat #chan-" + id);
|
|
|
|
channelContainer
|
2017-10-01 08:52:34 +00:00
|
|
|
.find(".unread-marker")
|
|
|
|
.data("unread-id", 0)
|
2018-07-06 18:15:15 +00:00
|
|
|
.appendTo(channelContainer.find(".messages"));
|
2017-05-18 20:08:54 +00:00
|
|
|
});
|