Merge pull request #1437 from thelounge/xpaw/cleanup-condensed

Cleanup condensed appendMessage
This commit is contained in:
Pavel Djundik 2017-08-20 19:37:32 +03:00 committed by GitHub
commit 1e9910f899
2 changed files with 27 additions and 18 deletions

View file

@ -91,6 +91,7 @@ module.exports = {
colorCodeMap: colorCodeMap, colorCodeMap: colorCodeMap,
commands: commands, commands: commands,
condensedTypes: condensedTypes, condensedTypes: condensedTypes,
condensedTypesQuery: "." + condensedTypes.join(", ."),
actionTypes: actionTypes, actionTypes: actionTypes,
timeFormats: timeFormats timeFormats: timeFormats
}; };

View file

@ -7,7 +7,7 @@ const renderPreview = require("./renderPreview");
const utils = require("./utils"); const utils = require("./utils");
const sorting = require("./sorting"); const sorting = require("./sorting");
const constants = require("./constants"); const constants = require("./constants");
const condense = require("./condensed"); const condensed = require("./condensed");
const chat = $("#chat"); const chat = $("#chat");
const sidebar = $("#sidebar"); const sidebar = $("#sidebar");
@ -33,23 +33,31 @@ function buildChannelMessages(data) {
} }
function appendMessage(container, chan, chanType, messageType, msg) { function appendMessage(container, chan, chanType, messageType, msg) {
if (constants.condensedTypes.indexOf(messageType) !== -1 && chanType !== "lobby") { // TODO: To fix #1432, statusMessage option should entirely be implemented in CSS
var condensedTypesClasses = "." + constants.condensedTypes.join(", ."); if (constants.condensedTypes.indexOf(messageType) === -1 || chanType !== "channel" || options.statusMessages !== "condensed") {
var lastChild = container.children("div.msg").last(); container.append(msg);
var lastDate = (new Date(lastChild.attr("data-time"))).toDateString(); return;
var msgDate = (new Date(msg.attr("data-time"))).toDateString(); }
if (lastChild && $(lastChild).hasClass("condensed") && !$(msg).hasClass("message") && lastDate === msgDate) {
lastChild.append(msg); const lastChild = container.children("div.msg").last();
condense.updateText(lastChild, [messageType]);
} else if (lastChild && $(lastChild).is(condensedTypesClasses) && options.statusMessages === "condensed") { if (lastChild && $(lastChild).hasClass("condensed")) {
var condensed = buildChatMessage({msg: {type: "condensed", time: msg.attr("data-time"), previews: []}, chan: chan}); lastChild.append(msg);
condensed.append(lastChild); condensed.updateText(lastChild, [messageType]);
condensed.append(msg); } else if (lastChild && $(lastChild).is(constants.condensedTypesQuery)) {
container.append(condensed); const newCondensed = buildChatMessage({
condense.updateText(condensed, [messageType, lastChild.attr("data-type")]); chan: chan,
} else { msg: {
container.append(msg); type: "condensed",
} time: msg.attr("data-time"),
previews: []
}
});
condensed.updateText(newCondensed, [messageType, lastChild.attr("data-type")]);
container.append(newCondensed);
newCondensed.append(lastChild);
newCondensed.append(msg);
} else { } else {
container.append(msg); container.append(msg);
} }