Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process received messages in queue #1041

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 0 additions & 86 deletions client/js/lounge.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const emojiMap = require("./libs/simplemap.json");
require("./libs/jquery/inputhistory");
require("./libs/jquery/stickyscroll");
require("./libs/jquery/tabcomplete");
const helpers_roundBadgeNumber = require("./libs/handlebars/roundBadgeNumber");
const slideoutMenu = require("./libs/slideout");
const templates = require("../views");
const socket = require("./socket");
Expand All @@ -29,20 +28,6 @@ $(function() {

$(document.body).data("app-name", document.title);

var pop;
try {
pop = new Audio();
pop.src = "audio/pop.ogg";
} catch (e) {
pop = {
play: $.noop
};
}

$("#play").on("click", function() {
pop.play();
});

// Autocompletion Strategies

const emojiSearchTerms = Object.keys(emojiMap);
Expand Down Expand Up @@ -637,77 +622,6 @@ $(function() {
container.html(templates.user_filtered({matches: result})).show();
});

chat.on("msg", ".messages", function(e, target, msg) {
var unread = msg.unread;
msg = msg.msg;

if (msg.self) {
return;
}

var button = sidebar.find(".chan[data-target='" + target + "']");
if (msg.highlight || (options.notifyAllMessages && msg.type === "message")) {
if (!document.hasFocus() || !$(target).hasClass("active")) {
if (options.notification) {
try {
pop.play();
} catch (exception) {
// On mobile, sounds can not be played without user interaction.
}
}
utils.toggleNotificationMarkers(true);

if (options.desktopNotifications && Notification.permission === "granted") {
var title;
var body;

if (msg.type === "invite") {
title = "New channel invite:";
body = msg.from + " invited you to " + msg.channel;
} else {
title = msg.from;
if (!button.hasClass("query")) {
title += " (" + button.data("title").trim() + ")";
}
if (msg.type === "message") {
title += " says:";
}
body = msg.text.replace(/\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?|[\x00-\x1F]|\x7F/g, "").trim();
}

try {
var notify = new Notification(title, {
body: body,
icon: "img/logo-64.png",
tag: target
});
notify.addEventListener("click", function() {
window.focus();
button.click();
this.close();
});
} catch (exception) {
// `new Notification(...)` is not supported and should be silenced.
}
}
}
}

if (button.hasClass("active")) {
return;
}

if (!unread) {
return;
}

var badge = button.find(".badge").html(helpers_roundBadgeNumber(unread));

if (msg.highlight) {
badge.addClass("highlight");
}
});

chat.on("click", ".show-more-button", function() {
var self = $(this);
var lastMessage = self.parent().next(".messages").children(".msg").first();
Expand Down
19 changes: 12 additions & 7 deletions client/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,28 @@ module.exports = {

function buildChannelMessages(data) {
return data.messages.reduce(function(docFragment, message) {
appendMessage(docFragment, data.id, data.type, message.type, buildChatMessage({
chan: data.id,
msg: message
}));
appendMessage(
docFragment,
data.id,
data.type,
message.type,
buildChatMessage({
chan: data.id,
msg: message
}),
docFragment.children("div.msg").last()
);
return docFragment;
}, $(document.createDocumentFragment()));
}

function appendMessage(container, chan, chanType, messageType, msg) {
function appendMessage(container, chan, chanType, messageType, msg, lastChild) {
// TODO: To fix #1432, statusMessage option should entirely be implemented in CSS
if (constants.condensedTypes.indexOf(messageType) === -1 || chanType !== "channel" || options.statusMessages !== "condensed") {
container.append(msg);
return;
}

const lastChild = container.children("div.msg").last();

if (lastChild && $(lastChild).hasClass("condensed")) {
lastChild.append(msg);
condensed.updateText(lastChild, [messageType]);
Expand Down
Loading