From 0e55dafd8aa7d6455321afd836078e2ab55ff31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sun, 27 Aug 2017 20:55:00 -0400 Subject: [PATCH 01/13] WIP --- client/index.html | 40 ++----------------------------- client/views/index.js | 5 ++++ client/views/windows/loading.html | 13 ++++++++++ client/views/windows/sign_in.html | 27 +++++++++++++++++++++ 4 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 client/views/windows/loading.html create mode 100644 client/views/windows/sign_in.html diff --git a/client/index.html b/client/index.html index 4e606379..66c8ee52 100644 --- a/client/index.html +++ b/client/index.html @@ -46,19 +46,7 @@
-
-
-

The Lounge is loading…

-
-
-

Loading the app… Make sure to have JavaScript enabled.

-
-

This is taking longer than it should, there might be connectivity issues.

- -
- -
-
+ {{> ./views/windows/loading}}
@@ -81,31 +69,7 @@
-
-
-

Sign in to The Lounge

-
-
- -
-
- -
- -
- -
-
+ {{> views/windows/sign_in}}
diff --git a/client/views/index.js b/client/views/index.js index 118fa60c..8fd3dc2c 100644 --- a/client/views/index.js +++ b/client/views/index.js @@ -20,6 +20,11 @@ module.exports = { whois: require("./actions/whois.tpl"), }, + windows: { + loading: require("./windows/loading.tpl"), + sign_in: require("./windows/sign_in.tpl"), + }, + chan: require("./chan.tpl"), chat: require("./chat.tpl"), contextmenu_divider: require("./contextmenu_divider.tpl"), diff --git a/client/views/windows/loading.html b/client/views/windows/loading.html new file mode 100644 index 00000000..105507ae --- /dev/null +++ b/client/views/windows/loading.html @@ -0,0 +1,13 @@ +
+
+

The Lounge is loading…

+
+
+

Loading the app… Make sure to have JavaScript enabled.

+
+

This is taking longer than it should, there might be connectivity issues.

+ +
+ +
+
diff --git a/client/views/windows/sign_in.html b/client/views/windows/sign_in.html new file mode 100644 index 00000000..7c108eaf --- /dev/null +++ b/client/views/windows/sign_in.html @@ -0,0 +1,27 @@ +
+
+

Sign in to The Lounge

+
+
+ +
+
+ +
+
+ +
+ +
+ +
+
From 303dddb12e5f9f96538df6be72017aab75e6377b Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 4 Nov 2017 19:11:20 +0200 Subject: [PATCH 02/13] wip --- client/index.html | 20 ++++++++---- client/views/windows/sign_in.html | 54 ++++++++++++++++--------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/client/index.html b/client/index.html index 66c8ee52..1c4006cf 100644 --- a/client/index.html +++ b/client/index.html @@ -46,7 +46,19 @@
- {{> ./views/windows/loading}} +
+
+

The Lounge is loading…

+
+
+

Loading the app… Make sure to have JavaScript enabled.

+
+

This is taking longer than it should, there might be connectivity issues.

+ +
+ +
+
@@ -67,11 +79,7 @@
-
-
- {{> views/windows/sign_in}} -
-
+
diff --git a/client/views/windows/sign_in.html b/client/views/windows/sign_in.html index 7c108eaf..d43a7f2e 100644 --- a/client/views/windows/sign_in.html +++ b/client/views/windows/sign_in.html @@ -1,27 +1,29 @@ -
-
-

Sign in to The Lounge

+
+
+
+

Sign in to The Lounge

+
+
+ +
+
+ +
+
+ +
+ +
+ +
-
- -
-
- -
-
- -
- -
- -
-
+ From 2a6b255aee782adab2ba36829c6599a9a3fcdc72 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 4 Nov 2017 19:16:30 +0200 Subject: [PATCH 03/13] Make sign in work --- client/js/socket-events/auth.js | 7 +++++-- client/views/index.js | 1 - client/views/windows/loading.html | 13 ------------- client/views/windows/{sign_in.html => sign_in.tpl} | 0 4 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 client/views/windows/loading.html rename client/views/windows/{sign_in.html => sign_in.tpl} (100%) diff --git a/client/js/socket-events/auth.js b/client/js/socket-events/auth.js index e544948f..80fd0e18 100644 --- a/client/js/socket-events/auth.js +++ b/client/js/socket-events/auth.js @@ -4,6 +4,7 @@ const $ = require("jquery"); const socket = require("../socket"); const storage = require("../localStorage"); const utils = require("../utils"); +const templates = require("../../views"); socket.on("auth", function(data) { // If we reconnected and serverHash differs, that means the server restarted @@ -17,11 +18,13 @@ socket.on("auth", function(data) { utils.serverHash = data.serverHash; - const login = $("#sign-in"); let token; const user = storage.get("user"); - login.find(".btn").prop("disabled", false); + const login = $("#sign-in") + .html(templates.windows.sign_in()) + .find(".btn") + .prop("disabled", false); if (!data.success) { if (login.length === 0) { diff --git a/client/views/index.js b/client/views/index.js index 8fd3dc2c..a459ded1 100644 --- a/client/views/index.js +++ b/client/views/index.js @@ -21,7 +21,6 @@ module.exports = { }, windows: { - loading: require("./windows/loading.tpl"), sign_in: require("./windows/sign_in.tpl"), }, diff --git a/client/views/windows/loading.html b/client/views/windows/loading.html deleted file mode 100644 index 105507ae..00000000 --- a/client/views/windows/loading.html +++ /dev/null @@ -1,13 +0,0 @@ -
-
-

The Lounge is loading…

-
-
-

Loading the app… Make sure to have JavaScript enabled.

-
-

This is taking longer than it should, there might be connectivity issues.

- -
- -
-
diff --git a/client/views/windows/sign_in.html b/client/views/windows/sign_in.tpl similarity index 100% rename from client/views/windows/sign_in.html rename to client/views/windows/sign_in.tpl From 55d1625ab2fa6451c7da7fbfb8a75180c0f376c2 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 4 Nov 2017 19:19:12 +0200 Subject: [PATCH 04/13] Split connect and settings into templates --- client/index.html | 287 +----------------------------- client/views/index.js | 2 + client/views/windows/connect.tpl | 88 +++++++++ client/views/windows/settings.tpl | 193 ++++++++++++++++++++ 4 files changed, 285 insertions(+), 285 deletions(-) create mode 100644 client/views/windows/connect.tpl create mode 100644 client/views/windows/settings.tpl diff --git a/client/index.html b/client/index.html index 1c4006cf..2c6b7b78 100644 --- a/client/index.html +++ b/client/index.html @@ -80,291 +80,8 @@
-
-
- -
-
-
-
-

- {{#if public}}The Lounge - {{/if}} - Connect - {{#unless displayNetwork}} - {{#if lockNetwork}} - to {{defaults.name}} - {{/if}} - {{/unless}} -

-
- {{#if displayNetwork}} -
-
-

Network settings

-
-
- -
-
- -
-
- -
-
- -
-
-
- -
-
-
-
- -
-
- -
-
- -
-
-
- {{/if}} -
-

User preferences

-
-
- -
-
- -
- {{#unless useHexIp}} -
- -
-
- -
- {{/unless}} -
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
- -
-
-

Settings

- -
-
-

Messages

-
-
- -
-
- -
-
-

- Status messages - - - -

-
-
- - - -
-
-

Visual Aids

-
-
- - -
-
-

Theme

-
-
- - -
- {{#if prefetch}} -
-

Link previews

-
-
- -
-
- -
- {{/if}} - {{#unless public}} -
-

Push Notifications

-
-
- -
- Warning: - Push notifications are only supported over HTTPS connections. -
-
- Warning: - Push notifications are not supported by your browser. -
-
- {{/unless}} -
-

Browser Notifications

-
-
- -
-
- -
-
-
- -
-
- -
- -
- -
- -
- - {{#unless public}} - {{#unless ldap.enable}} -
-
-
-

Change password

-
-
- - -
-
- - -
-
- - -
- -
- -
-
-
- {{/unless}} - {{/unless}} -
-

Custom Stylesheet

-
-
- -
-
- - {{#unless public}} -
-

Sessions

- -

Current session

-
- -

Other sessions

-
-
- {{/unless}} -
-
+
+
diff --git a/client/views/index.js b/client/views/index.js index a459ded1..55a8266e 100644 --- a/client/views/index.js +++ b/client/views/index.js @@ -22,6 +22,8 @@ module.exports = { windows: { sign_in: require("./windows/sign_in.tpl"), + settings: require("./windows/settings.tpl"), + connect: require("./windows/connect.tpl"), }, chan: require("./chan.tpl"), diff --git a/client/views/windows/connect.tpl b/client/views/windows/connect.tpl new file mode 100644 index 00000000..b52244d8 --- /dev/null +++ b/client/views/windows/connect.tpl @@ -0,0 +1,88 @@ +
+ +
+
+
+
+

+ {{#if public}}The Lounge - {{/if}} + Connect + {{#unless displayNetwork}} + {{#if lockNetwork}} + to {{defaults.name}} + {{/if}} + {{/unless}} +

+
+ {{#if displayNetwork}} +
+
+

Network settings

+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+
+ {{/if}} +
+

User preferences

+
+
+ +
+
+ +
+ {{#unless useHexIp}} +
+ +
+
+ +
+ {{/unless}} +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
diff --git a/client/views/windows/settings.tpl b/client/views/windows/settings.tpl new file mode 100644 index 00000000..ec314752 --- /dev/null +++ b/client/views/windows/settings.tpl @@ -0,0 +1,193 @@ +
+ +
+
+

Settings

+ +
+
+

Messages

+
+
+ +
+
+ +
+
+

+ Status messages + + + +

+
+
+ + + +
+
+

Visual Aids

+
+
+ + +
+
+

Theme

+
+
+ + +
+ {{#if prefetch}} +
+

Link previews

+
+
+ +
+
+ +
+ {{/if}} + {{#unless public}} +
+

Push Notifications

+
+
+ +
+ Warning: + Push notifications are only supported over HTTPS connections. +
+
+ Warning: + Push notifications are not supported by your browser. +
+
+ {{/unless}} +
+

Browser Notifications

+
+
+ +
+
+ +
+
+
+ +
+
+ +
+ +
+ +
+ +
+ + {{#unless public}} + {{#unless ldap.enable}} +
+
+
+

Change password

+
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+
+ {{/unless}} + {{/unless}} +
+

Custom Stylesheet

+
+
+ +
+
+ + {{#unless public}} +
+

Sessions

+ +

Current session

+
+ +

Other sessions

+
+
+ {{/unless}} +
From 711b5e1d91cabdf767865a45f3793ffff04d54f0 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 4 Nov 2017 19:32:18 +0200 Subject: [PATCH 05/13] Make settings/options mostly work Fixes #1672 --- client/js/lounge.js | 1 - client/js/socket-events/configuration.js | 14 ++++++++++++++ client/js/socket-events/index.js | 1 + client/views/windows/settings.tpl | 2 +- src/server.js | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 client/js/socket-events/configuration.js diff --git a/client/js/lounge.js b/client/js/lounge.js index 307de2ac..fdeeba13 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -15,7 +15,6 @@ const templates = require("../views"); const socket = require("./socket"); require("./socket-events"); const storage = require("./localStorage"); -require("./options"); const utils = require("./utils"); require("./autocompletion"); require("./webpush"); diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js new file mode 100644 index 00000000..d7a769a7 --- /dev/null +++ b/client/js/socket-events/configuration.js @@ -0,0 +1,14 @@ +"use strict"; + +const $ = require("jquery"); +const socket = require("../socket"); +const storage = require("../localStorage"); +const utils = require("../utils"); +const templates = require("../../views"); + +socket.on("configuration", function(data) { + $("#settings").html(templates.windows.settings(data)); + $("#connect").html(templates.windows.connect(data)); + + require("../options"); +}); diff --git a/client/js/socket-events/index.js b/client/js/socket-events/index.js index b0064665..f14c670a 100644 --- a/client/js/socket-events/index.js +++ b/client/js/socket-events/index.js @@ -18,3 +18,4 @@ require("./topic"); require("./users"); require("./sign_out"); require("./sessions_list"); +require("./configuration"); diff --git a/client/views/windows/settings.tpl b/client/views/windows/settings.tpl index ec314752..c78ed80b 100644 --- a/client/views/windows/settings.tpl +++ b/client/views/windows/settings.tpl @@ -145,7 +145,7 @@
{{#unless public}} - {{#unless ldap.enable}} + {{#unless ldapEnabled}}
diff --git a/src/server.js b/src/server.js index ca29b286..fe23357f 100644 --- a/src/server.js +++ b/src/server.js @@ -467,6 +467,22 @@ function initializeClient(socket, client, token, lastMessage) { } } +function getClientConfiguration() { + const config = _.pick(Helper.config, [ + "public", + "lockNetwork", + "displayNetwork", + "useHexIp", + "defaults", + "themes", + "prefetch", + ]); + + config.ldapEnabled = Helper.config.ldap.enable; + + return config; +} + function performAuthentication(data) { const socket = this; let client; @@ -474,6 +490,8 @@ function performAuthentication(data) { const finalInit = () => initializeClient(socket, client, data.token || null, data.lastMessage || -1); const initClient = () => { + socket.emit("configuration", getClientConfiguration()); + client.ip = getClientIp(socket); // If webirc is enabled perform reverse dns lookup From e85e00ebedde78c62feeb7003f8a5508779d9e12 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 7 Nov 2017 12:47:11 +0200 Subject: [PATCH 06/13] Remove unused --- client/js/socket-events/configuration.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index d7a769a7..3a4c324e 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -2,8 +2,6 @@ const $ = require("jquery"); const socket = require("../socket"); -const storage = require("../localStorage"); -const utils = require("../utils"); const templates = require("../../views"); socket.on("configuration", function(data) { From 8d88779918ac24a7455d826de8d5fe1ae65ec977 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 7 Nov 2017 22:22:16 +0200 Subject: [PATCH 07/13] Fix options --- client/js/lounge.js | 63 ------- client/js/options.js | 227 ++++++++++++----------- client/js/socket-events/configuration.js | 63 ++++++- client/js/socket-events/msg.js | 2 - client/js/webpush.js | 12 +- client/views/windows/connect.tpl | 2 +- client/views/windows/settings.tpl | 2 +- client/views/windows/sign_in.tpl | 10 +- src/server.js | 3 +- 9 files changed, 194 insertions(+), 190 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index fdeeba13..440920f2 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -27,7 +27,6 @@ $(function() { $(document.body).data("app-name", document.title); - var windows = $("#windows"); var viewport = $("#viewport"); var sidebarSlide = slideoutMenu(viewport[0], sidebar[0]); var contextMenuContainer = $("#context-menu-container"); @@ -484,18 +483,6 @@ $(function() { container.html(templates.user_filtered({matches: result})).show(); }); - var forms = $("#sign-in, #connect, #change-password"); - - windows.on("show", "#sign-in", function() { - $(this).find("input").each(function() { - var self = $(this); - if (self.val() === "") { - self.focus(); - return false; - } - }); - }); - if ($("body").hasClass("public") && (window.location.hash === "#connect" || window.location.hash === "")) { $("#connect").one("show", function() { var params = URI(document.location.search); @@ -522,56 +509,6 @@ $(function() { }); } - forms.on("submit", "form", function(e) { - e.preventDefault(); - var event = "auth"; - var form = $(this); - form.find(".btn").attr("disabled", true); - - if (form.closest(".window").attr("id") === "connect") { - event = "conn"; - } else if (form.closest("div").attr("id") === "change-password") { - event = "change-password"; - } - - var values = {}; - $.each(form.serializeArray(), function(i, obj) { - if (obj.value !== "") { - values[obj.name] = obj.value; - } - }); - - if (values.user) { - storage.set("user", values.user); - } - - socket.emit( - event, values - ); - }); - - forms.on("focusin", ".nick", function() { - // Need to set the first "lastvalue", so it can be used in the below function - var nick = $(this); - nick.data("lastvalue", nick.val()); - }); - - forms.on("input", ".nick", function() { - var nick = $(this).val(); - var usernameInput = forms.find(".username"); - - // Because this gets called /after/ it has already changed, we need use the previous value - var lastValue = $(this).data("lastvalue"); - - // They were the same before the change, so update the username field - if (usernameInput.val() === lastValue) { - usernameInput.val(nick); - } - - // Store the "previous" value, for next time - $(this).data("lastvalue", nick); - }); - $(document).on("visibilitychange focus click", () => { if (sidebar.find(".highlight").length === 0) { utils.toggleNotificationMarkers(false); diff --git a/client/js/options.js b/client/js/options.js index f9621430..4faca65e 100644 --- a/client/js/options.js +++ b/client/js/options.js @@ -3,7 +3,6 @@ const $ = require("jquery"); require("jquery-textcomplete"); const escapeRegExp = require("lodash/escapeRegExp"); -const settings = $("#settings"); const userStyles = $("#user-specified-css"); const storage = require("./localStorage"); const tz = require("./libs/handlebars/tz"); @@ -35,6 +34,11 @@ for (const key in options) { } } +// Apply custom CSS on page load +if (typeof userOptions.userStyles === "string" && !/[?&]nocss/.test(window.location.search)) { + userStyles.html(userOptions.userStyles); +} + userOptions = null; module.exports = options; @@ -43,123 +47,126 @@ module.exports.shouldOpenMessagePreview = function(type) { return (options.links && type === "link") || (options.thumbnails && type === "image"); }; -for (var i in options) { - if (i === "userStyles") { - if (!/[?&]nocss/.test(window.location.search)) { - $(document.head).find("#user-specified-css").html(options[i]); +module.exports.initialize = () => { + module.exports.initialize = null; + + const settings = $("#settings"); + + for (var i in options) { + if (i === "userStyles") { + settings.find("#user-specified-css-input").val(options[i]); + } else if (i === "highlights") { + settings.find("input[name=" + i + "]").val(options[i]); + } else if (i === "statusMessages") { + settings.find(`input[name=${i}][value=${options[i]}]`) + .prop("checked", true); + } else if (i === "theme") { + $("#theme").attr("href", "themes/" + options[i] + ".css"); + settings.find("select[name=" + i + "]").val(options[i]); + } else if (options[i]) { + settings.find("input[name=" + i + "]").prop("checked", true); } - settings.find("#user-specified-css-input").val(options[i]); - } else if (i === "highlights") { - settings.find("input[name=" + i + "]").val(options[i]); - } else if (i === "statusMessages") { - settings.find(`input[name=${i}][value=${options[i]}]`) - .prop("checked", true); - } else if (i === "theme") { - $("#theme").attr("href", "themes/" + options[i] + ".css"); - settings.find("select[name=" + i + "]").val(options[i]); - } else if (options[i]) { - settings.find("input[name=" + i + "]").prop("checked", true); } -} -settings.on("change", "input, select, textarea", function() { - const self = $(this); - const type = self.attr("type"); - const name = self.attr("name"); + settings.on("change", "input, select, textarea", function() { + const self = $(this); + const type = self.attr("type"); + const name = self.attr("name"); - if (type === "password") { - return; - } else if (type === "radio") { - if (self.prop("checked")) { + if (type === "password") { + return; + } else if (type === "radio") { + if (self.prop("checked")) { + options[name] = self.val(); + } + } else if (type === "checkbox") { + options[name] = self.prop("checked"); + } else { options[name] = self.val(); } - } else if (type === "checkbox") { - options[name] = self.prop("checked"); + + storage.set("settings", JSON.stringify(options)); + + if (name === "motd") { + chat.toggleClass("hide-" + name, !self.prop("checked")); + } else if (name === "statusMessages") { + chat.toggleClass("hide-status-messages", options[name] === "hidden"); + chat.toggleClass("condensed-status-messages", options[name] === "condensed"); + } else if (name === "coloredNicks") { + chat.toggleClass("colored-nicks", self.prop("checked")); + } else if (name === "theme") { + $("#theme").attr("href", "themes/" + options[name] + ".css"); + } else if (name === "userStyles") { + userStyles.html(options[name]); + } else if (name === "highlights") { + var highlightString = options[name]; + options.highlights = highlightString.split(",").map(function(h) { + return h.trim(); + }).filter(function(h) { + // Ensure we don't have empty string in the list of highlights + // otherwise, users get notifications for everything + return h !== ""; + }); + // Construct regex with wordboundary for every highlight item + const highlightsTokens = options.highlights.map(function(h) { + return escapeRegExp(h); + }); + if (highlightsTokens && highlightsTokens.length) { + module.exports.highlightsRE = new RegExp("\\b(?:" + highlightsTokens.join("|") + ")\\b", "i"); + } else { + module.exports.highlightsRE = null; + } + } else if (name === "showSeconds") { + chat.find(".msg > .time").each(function() { + $(this).text(tz($(this).parent().data("time"))); + }); + chat.toggleClass("show-seconds", self.prop("checked")); + } else if (name === "autocomplete") { + if (self.prop("checked")) { + $("#input").trigger("autocomplete:on"); + } else { + $("#input").textcomplete("destroy"); + } + } + }).find("input") + .trigger("change"); + + $("#desktopNotifications").on("change", function() { + if ($(this).prop("checked") && Notification.permission !== "granted") { + Notification.requestPermission(updateDesktopNotificationStatus); + } + }); + + // Updates the checkbox and warning in settings when the Settings page is + // opened or when the checkbox state is changed. + // When notifications are not supported, this is never called (because + // checkbox state can not be changed). + var updateDesktopNotificationStatus = function() { + if (Notification.permission === "denied") { + desktopNotificationsCheckbox.attr("disabled", true); + desktopNotificationsCheckbox.attr("checked", false); + warningBlocked.show(); + } else { + if (Notification.permission === "default" && desktopNotificationsCheckbox.prop("checked")) { + desktopNotificationsCheckbox.attr("checked", false); + } + desktopNotificationsCheckbox.attr("disabled", false); + warningBlocked.hide(); + } + }; + + // If browser does not support notifications, override existing settings and + // display proper message in settings. + var desktopNotificationsCheckbox = $("#desktopNotifications"); + var warningUnsupported = $("#warnUnsupportedDesktopNotifications"); + var warningBlocked = $("#warnBlockedDesktopNotifications"); + warningBlocked.hide(); + if (("Notification" in window)) { + warningUnsupported.hide(); + windows.on("show", "#settings", updateDesktopNotificationStatus); } else { - options[name] = self.val(); - } - - storage.set("settings", JSON.stringify(options)); - - if (name === "motd") { - chat.toggleClass("hide-" + name, !self.prop("checked")); - } else if (name === "statusMessages") { - chat.toggleClass("hide-status-messages", options[name] === "hidden"); - chat.toggleClass("condensed-status-messages", options[name] === "condensed"); - } else if (name === "coloredNicks") { - chat.toggleClass("colored-nicks", self.prop("checked")); - } else if (name === "theme") { - $("#theme").attr("href", "themes/" + options[name] + ".css"); - } else if (name === "userStyles") { - userStyles.html(options[name]); - } else if (name === "highlights") { - var highlightString = options[name]; - options.highlights = highlightString.split(",").map(function(h) { - return h.trim(); - }).filter(function(h) { - // Ensure we don't have empty string in the list of highlights - // otherwise, users get notifications for everything - return h !== ""; - }); - // Construct regex with wordboundary for every highlight item - const highlightsTokens = options.highlights.map(function(h) { - return escapeRegExp(h); - }); - if (highlightsTokens && highlightsTokens.length) { - module.exports.highlightsRE = new RegExp("\\b(?:" + highlightsTokens.join("|") + ")\\b", "i"); - } else { - module.exports.highlightsRE = null; - } - } else if (name === "showSeconds") { - chat.find(".msg > .time").each(function() { - $(this).text(tz($(this).parent().data("time"))); - }); - chat.toggleClass("show-seconds", self.prop("checked")); - } else if (name === "autocomplete") { - if (self.prop("checked")) { - $("#input").trigger("autocomplete:on"); - } else { - $("#input").textcomplete("destroy"); - } - } -}).find("input") - .trigger("change"); - -$("#desktopNotifications").on("change", function() { - if ($(this).prop("checked") && Notification.permission !== "granted") { - Notification.requestPermission(updateDesktopNotificationStatus); - } -}); - -// Updates the checkbox and warning in settings when the Settings page is -// opened or when the checkbox state is changed. -// When notifications are not supported, this is never called (because -// checkbox state can not be changed). -var updateDesktopNotificationStatus = function() { - if (Notification.permission === "denied") { + options.desktopNotifications = false; desktopNotificationsCheckbox.attr("disabled", true); desktopNotificationsCheckbox.attr("checked", false); - warningBlocked.show(); - } else { - if (Notification.permission === "default" && desktopNotificationsCheckbox.prop("checked")) { - desktopNotificationsCheckbox.attr("checked", false); - } - desktopNotificationsCheckbox.attr("disabled", false); - warningBlocked.hide(); } }; - -// If browser does not support notifications, override existing settings and -// display proper message in settings. -var desktopNotificationsCheckbox = $("#desktopNotifications"); -var warningUnsupported = $("#warnUnsupportedDesktopNotifications"); -var warningBlocked = $("#warnBlockedDesktopNotifications"); -warningBlocked.hide(); -if (("Notification" in window)) { - warningUnsupported.hide(); - windows.on("show", "#settings", updateDesktopNotificationStatus); -} else { - options.desktopNotifications = false; - desktopNotificationsCheckbox.attr("disabled", true); - desktopNotificationsCheckbox.attr("checked", false); -} diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index 3a4c324e..901170ca 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -3,10 +3,71 @@ const $ = require("jquery"); const socket = require("../socket"); const templates = require("../../views"); +const options = require("../options"); +const webpush = require("../webpush"); +const storage = require("../localStorage"); socket.on("configuration", function(data) { + if (!options.initialize) { + return; + } + $("#settings").html(templates.windows.settings(data)); $("#connect").html(templates.windows.connect(data)); - require("../options"); + $("#play").on("click", () => { + const pop = new Audio(); + pop.src = "audio/pop.ogg"; + pop.play(); + }); + + options.initialize(); + webpush.initialize(); + + // TODO: #sign-in needs to be handled in auth.js otherwise its broken + const forms = $("#sign-in, #connect, #change-password"); + + forms.on("submit", "form", function() { + const form = $(this); + const event = form.data("event"); + + form.find(".btn").attr("disabled", true); + + const values = {}; + $.each(form.serializeArray(), function(i, obj) { + if (obj.value !== "") { + values[obj.name] = obj.value; + } + }); + + if (values.user) { + storage.set("user", values.user); + } + + socket.emit(event, values); + + return false; + }); + + forms.on("focusin", ".nick", function() { + // Need to set the first "lastvalue", so it can be used in the below function + const nick = $(this); + nick.data("lastvalue", nick.val()); + }); + + forms.on("input", ".nick", function() { + const nick = $(this).val(); + const usernameInput = forms.find(".username"); + + // Because this gets called /after/ it has already changed, we need use the previous value + const lastValue = $(this).data("lastvalue"); + + // They were the same before the change, so update the username field + if (usernameInput.val() === lastValue) { + usernameInput.val(nick); + } + + // Store the "previous" value, for next time + $(this).data("lastvalue", nick); + }); }); diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index 585dc7ef..d8f50958 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -21,8 +21,6 @@ try { }; } -$("#play").on("click", () => pop.play()); - socket.on("msg", function(data) { // We set a maximum timeout of 2 seconds so that messages don't take too long to appear. utils.requestIdleCallback(() => processReceivedMessage(data), 2000); diff --git a/client/js/webpush.js b/client/js/webpush.js index 16eb9dd8..bffe65c7 100644 --- a/client/js/webpush.js +++ b/client/js/webpush.js @@ -4,7 +4,7 @@ const $ = require("jquery"); const storage = require("./localStorage"); const socket = require("./socket"); -const pushNotificationsButton = $("#pushNotifications"); +let pushNotificationsButton; let clientSubscribed = null; let applicationServerKey; @@ -29,7 +29,13 @@ module.exports.configurePushNotifications = (subscribedOnServer, key) => { } }; -if (isAllowedServiceWorkersHost()) { +module.exports.initialize = () => { + pushNotificationsButton = $("#pushNotifications"); + + if (!isAllowedServiceWorkersHost()) { + return; + } + $("#pushNotificationsHttps").hide(); if ("serviceWorker" in navigator) { @@ -57,7 +63,7 @@ if (isAllowedServiceWorkersHost()) { $("#pushNotificationsUnsupported span").text(err); }); } -} +}; function onPushButton() { pushNotificationsButton.attr("disabled", true); diff --git a/client/views/windows/connect.tpl b/client/views/windows/connect.tpl index b52244d8..9ef5d09e 100644 --- a/client/views/windows/connect.tpl +++ b/client/views/windows/connect.tpl @@ -1,7 +1,7 @@
- +

diff --git a/client/views/windows/settings.tpl b/client/views/windows/settings.tpl index c78ed80b..f22a3bdf 100644 --- a/client/views/windows/settings.tpl +++ b/client/views/windows/settings.tpl @@ -147,7 +147,7 @@ {{#unless public}} {{#unless ldapEnabled}}
- +

Change password

diff --git a/client/views/windows/sign_in.tpl b/client/views/windows/sign_in.tpl index d43a7f2e..cdd5cf22 100644 --- a/client/views/windows/sign_in.tpl +++ b/client/views/windows/sign_in.tpl @@ -1,4 +1,4 @@ - +

Sign in to The Lounge

@@ -6,7 +6,7 @@
@@ -15,12 +15,6 @@
-
- -
diff --git a/src/server.js b/src/server.js index fe23357f..5550aae6 100644 --- a/src/server.js +++ b/src/server.js @@ -210,7 +210,6 @@ function index(req, res, next) { Helper.config ); data.gitCommit = Helper.getGitCommit(); - data.themes = themes.getAll(); const policies = [ "default-src *", @@ -479,6 +478,8 @@ function getClientConfiguration() { ]); config.ldapEnabled = Helper.config.ldap.enable; + config.gitCommit = Helper.getGitCommit(); + config.themes = themes.getAll(); return config; } From 90861effb4d22f0e3415b653f0c339c5a7c15780 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 11 Nov 2017 20:33:21 +0200 Subject: [PATCH 08/13] Fix sign in --- client/js/socket-events/auth.js | 24 ++++++++++--- client/js/socket-events/configuration.js | 45 +++++++++++------------- client/views/windows/sign_in.tpl | 2 +- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/client/js/socket-events/auth.js b/client/js/socket-events/auth.js index 80fd0e18..ef9f4d5c 100644 --- a/client/js/socket-events/auth.js +++ b/client/js/socket-events/auth.js @@ -6,6 +6,8 @@ const storage = require("../localStorage"); const utils = require("../utils"); const templates = require("../../views"); +const login = $("#sign-in").html(templates.windows.sign_in()); + socket.on("auth", function(data) { // If we reconnected and serverHash differs, that means the server restarted // And we will reload the page to grab the latest version @@ -21,10 +23,24 @@ socket.on("auth", function(data) { let token; const user = storage.get("user"); - const login = $("#sign-in") - .html(templates.windows.sign_in()) - .find(".btn") - .prop("disabled", false); + login.find(".btn").prop("disabled", false); + + login.find("form").on("submit", function() { + const form = $(this); + + form.find(".btn").attr("disabled", true); + + const values = {}; + $.each(form.serializeArray(), function(i, obj) { + values[obj.name] = obj.value; + }); + + storage.set("user", values.user); + + socket.emit("auth", values); + + return false; + }); if (!data.success) { if (login.length === 0) { diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index 901170ca..eae98644 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -24,10 +24,9 @@ socket.on("configuration", function(data) { options.initialize(); webpush.initialize(); - // TODO: #sign-in needs to be handled in auth.js otherwise its broken - const forms = $("#sign-in, #connect, #change-password"); + const forms = $("#connect form, #change-password form"); - forms.on("submit", "form", function() { + forms.on("submit", function() { const form = $(this); const event = form.data("event"); @@ -40,34 +39,30 @@ socket.on("configuration", function(data) { } }); - if (values.user) { - storage.set("user", values.user); - } - socket.emit(event, values); return false; }); - forms.on("focusin", ".nick", function() { - // Need to set the first "lastvalue", so it can be used in the below function - const nick = $(this); - nick.data("lastvalue", nick.val()); - }); + $(".nick") + .on("focusin", function() { + // Need to set the first "lastvalue", so it can be used in the below function + const nick = $(this); + nick.data("lastvalue", nick.val()); + }) + .on("input", function() { + const nick = $(this).val(); + const usernameInput = forms.find(".username"); - forms.on("input", ".nick", function() { - const nick = $(this).val(); - const usernameInput = forms.find(".username"); + // Because this gets called /after/ it has already changed, we need use the previous value + const lastValue = $(this).data("lastvalue"); - // Because this gets called /after/ it has already changed, we need use the previous value - const lastValue = $(this).data("lastvalue"); + // They were the same before the change, so update the username field + if (usernameInput.val() === lastValue) { + usernameInput.val(nick); + } - // They were the same before the change, so update the username field - if (usernameInput.val() === lastValue) { - usernameInput.val(nick); - } - - // Store the "previous" value, for next time - $(this).data("lastvalue", nick); - }); + // Store the "previous" value, for next time + $(this).data("lastvalue", nick); + }); }); diff --git a/client/views/windows/sign_in.tpl b/client/views/windows/sign_in.tpl index cdd5cf22..2f0e2e5a 100644 --- a/client/views/windows/sign_in.tpl +++ b/client/views/windows/sign_in.tpl @@ -1,4 +1,4 @@ - +

Sign in to The Lounge

From dbc6b099feb395b4c6ec5f9a1803b19667bf1c2f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 12 Nov 2017 19:57:24 +0200 Subject: [PATCH 09/13] unused var --- client/js/socket-events/configuration.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index eae98644..dc5d996f 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -5,7 +5,6 @@ const socket = require("../socket"); const templates = require("../../views"); const options = require("../options"); const webpush = require("../webpush"); -const storage = require("../localStorage"); socket.on("configuration", function(data) { if (!options.initialize) { From c30f4aaaeb534cba5f40d0909639d40723459530 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 12 Nov 2017 20:00:34 +0200 Subject: [PATCH 10/13] Move help to view --- client/index.html | 486 +---------------------- client/js/socket-events/configuration.js | 1 + client/views/index.js | 1 + client/views/windows/help.tpl | 482 ++++++++++++++++++++++ src/server.js | 9 +- 5 files changed, 487 insertions(+), 492 deletions(-) create mode 100644 client/views/windows/help.tpl diff --git a/client/index.html b/client/index.html index 2c6b7b78..b22b180e 100644 --- a/client/index.html +++ b/client/index.html @@ -82,491 +82,7 @@
- -
-
- -
-
-

Help

- -

Keyboard Shortcuts

- -
-
- Ctrl + / -
-
-

Switch to the previous/next window in the channel list

-
-
- -
-
- Ctrl + K -
-
-

- Mark any text typed after this shortcut to be colored. After - hitting this shortcut, enter an integer in the range - 0—15 to select the desired color, or use the - autocompletion menu to choose a color name (see below). -

-

- Background color can be specified by putting a comma and - another integer in the range 0—15 after the - foreground color number (autocompletion works too). -

-

- A color reference can be found - here. -

-
-
- -
-
- Ctrl + B -
-
-

Mark all text typed after this shortcut as bold.

-
-
- -
-
- Ctrl + U -
-
-

Mark all text typed after this shortcut as underlined.

-
-
- -
-
- Ctrl + I -
-
-

Mark all text typed after this shortcut as italics.

-
-
- -
-
- Ctrl + O -
-
-

- Mark all text typed after this shortcut to be reset to its - original formatting. -

-
-
- -

Autocompletion

- -

- To auto-complete nicknames, channels, commands, and emoji, type one of the characters below to open - a suggestion list. Use the and keys to highlight an item, and insert it by - pressing Tab or Enter (or by clicking the desired item). -

-

- Autocompletion can be disabled in settings. -

- -
-
- @ -
-
-

Nickname

-
-
- -
-
- # -
-
-

Channel

-
-
- -
-
- / -
-
-

Commands (see list of commands below)

-
-
- -
-
- : -
-
-

Emoji (note: requires two search characters, to avoid conflicting with common emoticons like :))

-
-
- -

Commands

- -
-
- /away [message] -
-
-

Mark yourself as away with an optional message.

-
-
- -
-
- /back -
-
-

Remove your away status (set with /away).

-
-
- -
-
- /ban nick -
-
-

Ban (+b) a user from the current channel. - This can be a nickname or a hostmask.

-
-
- -
-
- /banlist -
-
-

Load the banlist for the current channel.

-
-
- -
-
- /collapse -
-
-

- Collapse all previews in the current channel (opposite of - /expand) -

-
-
- -
-
- /connect host [port] -
-
-

- Connect to a new IRC network. If port starts with - a + sign, the connection will be made secure - using TLS. -

-

Alias: /server

-
-
- -
-
- /ctcp target cmd [args] -
-
-

- Send a CTCP - request. Read more about this on - the dedicated Wikipedia article. -

-
-
- -
-
- /deop nick [...nick] -
-
-

- Remove op (-o) from one or several users in the - current channel. -

-
-
- -
-
- /devoice nick [...nick] -
-
-

- Remove voice (-v) from one or several users in - the current channel. -

-
-
- -
-
- /disconnect [message] -
-
-

- Disconnect from the current network with an - optionally-provided message. -

-
-
- -
-
- /expand -
-
-

- Expand all previews in the current channel (opposite of - /collapse) -

-
-
- -
-
- /invite nick [channel] -
-
-

- Invite a user to the specified channel. If - channel is ommitted, user will be invited to the - current channel. -

-
-
- -
-
- /join channel -
-
-

Join a channel.

-
-
- -
-
- /kick nick -
-
-

Kick a user from the current channel.

-
-
- -
-
- /list -
-
-

Retrieve a list of available channels on this network.

-
-
- -
-
- /me message -
-
-

- Send an action message to the current channel. The Lounge will - display it inline, as if the message was posted in the third - person. -

-
-
- -
-
- /mode flags [args] -
-
-

- Set the given flags to the current channel if the active - window is a channel, another user if the active window is a - private message window, or yourself if the current window is a - server window. -

-
-
- -
-
- /msg channel message -
-
-

Send a message to the specified channel.

-
-
- -
-
- /nick newnick -
-
-

Change your nickname on the current network.

-
-
- -
-
- /notice channel message -
-
-

Sends a notice message to the specified channel.

-
-
- -
-
- /op nick [...nick] -
-
-

- Give op (+o) to one or several users in the - current channel. -

-
-
- -
-
- /part [channel] -
-
-

- Close the specified channel or private message window, or the - current channel if channel is ommitted. -

-

Aliases: /close, /leave

-
-
- -
-
- /rejoin -
-
-

- Leave and immediately rejoin the current channel. Useful to - quickly get op from ChanServ in an empty channel, for example. -

-

Alias: /cycle

-
-
- -
-
- /query nick -
-
-

Send a private message to the specified user.

-
-
- -
-
- /quit [message] -
-
-

- Disconnect from the current network with an optional message. -

-
-
- -
-
- /raw message -
-
-

Send a raw message to the current IRC network.

-

Aliases: /quote, /send

-
-
- -
-
- /slap nick -
-
-

Slap someone in the current channel with a trout!

-
-
- -
-
- /topic newtopic -
-
-

Set the topic in the current channel.

-
-
- -
-
- /unban nick -
-
-

Unban (-b) a user from the current channel. - This can be a nickname or a hostmask.

-
-
- -
-
- /voice nick [...nick] -
-
-

- Give voice (+v) to one or several users in the - current channel. -

-
-
- -
-
- /whois nick -
-
-

- Retrieve information about the given user on the current - network. -

-
-
- -

About The Lounge

- -

- {{#if gitCommit}} - The Lounge is running from source - ({{ gitCommit }}).
- {{else}} - The Lounge is in version {{version}} - (See release notes).
- {{/if}} - - Website
- Documentation
- Report a bug -

-
-
+
diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index dc5d996f..fd687a7b 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -13,6 +13,7 @@ socket.on("configuration", function(data) { $("#settings").html(templates.windows.settings(data)); $("#connect").html(templates.windows.connect(data)); + $("#help").html(templates.windows.help(data)); $("#play").on("click", () => { const pop = new Audio(); diff --git a/client/views/index.js b/client/views/index.js index 55a8266e..267f0691 100644 --- a/client/views/index.js +++ b/client/views/index.js @@ -24,6 +24,7 @@ module.exports = { sign_in: require("./windows/sign_in.tpl"), settings: require("./windows/settings.tpl"), connect: require("./windows/connect.tpl"), + help: require("./windows/help.tpl"), }, chan: require("./chan.tpl"), diff --git a/client/views/windows/help.tpl b/client/views/windows/help.tpl new file mode 100644 index 00000000..6db8d46d --- /dev/null +++ b/client/views/windows/help.tpl @@ -0,0 +1,482 @@ +
+ +
+
+

Help

+ +

Keyboard Shortcuts

+ +
+
+ Ctrl + / +
+
+

Switch to the previous/next window in the channel list

+
+
+ +
+
+ Ctrl + K +
+
+

+ Mark any text typed after this shortcut to be colored. After + hitting this shortcut, enter an integer in the range + 0—15 to select the desired color, or use the + autocompletion menu to choose a color name (see below). +

+

+ Background color can be specified by putting a comma and + another integer in the range 0—15 after the + foreground color number (autocompletion works too). +

+

+ A color reference can be found + here. +

+
+
+ +
+
+ Ctrl + B +
+
+

Mark all text typed after this shortcut as bold.

+
+
+ +
+
+ Ctrl + U +
+
+

Mark all text typed after this shortcut as underlined.

+
+
+ +
+
+ Ctrl + I +
+
+

Mark all text typed after this shortcut as italics.

+
+
+ +
+
+ Ctrl + O +
+
+

+ Mark all text typed after this shortcut to be reset to its + original formatting. +

+
+
+ +

Autocompletion

+ +

+ To auto-complete nicknames, channels, commands, and emoji, type one of the characters below to open + a suggestion list. Use the and keys to highlight an item, and insert it by + pressing Tab or Enter (or by clicking the desired item). +

+

+ Autocompletion can be disabled in settings. +

+ +
+
+ @ +
+
+

Nickname

+
+
+ +
+
+ # +
+
+

Channel

+
+
+ +
+
+ / +
+
+

Commands (see list of commands below)

+
+
+ +
+
+ : +
+
+

Emoji (note: requires two search characters, to avoid conflicting with common emoticons like :))

+
+
+ +

Commands

+ +
+
+ /away [message] +
+
+

Mark yourself as away with an optional message.

+
+
+ +
+
+ /back +
+
+

Remove your away status (set with /away).

+
+
+ +
+
+ /ban nick +
+
+

Ban (+b) a user from the current channel. + This can be a nickname or a hostmask.

+
+
+ +
+
+ /banlist +
+
+

Load the banlist for the current channel.

+
+
+ +
+
+ /collapse +
+
+

+ Collapse all previews in the current channel (opposite of + /expand) +

+
+
+ +
+
+ /connect host [port] +
+
+

+ Connect to a new IRC network. If port starts with + a + sign, the connection will be made secure + using TLS. +

+

Alias: /server

+
+
+ +
+
+ /ctcp target cmd [args] +
+
+

+ Send a CTCP + request. Read more about this on + the dedicated Wikipedia article. +

+
+
+ +
+
+ /deop nick [...nick] +
+
+

+ Remove op (-o) from one or several users in the + current channel. +

+
+
+ +
+
+ /devoice nick [...nick] +
+
+

+ Remove voice (-v) from one or several users in + the current channel. +

+
+
+ +
+
+ /disconnect [message] +
+
+

+ Disconnect from the current network with an + optionally-provided message. +

+
+
+ +
+
+ /expand +
+
+

+ Expand all previews in the current channel (opposite of + /collapse) +

+
+
+ +
+
+ /invite nick [channel] +
+
+

+ Invite a user to the specified channel. If + channel is ommitted, user will be invited to the + current channel. +

+
+
+ +
+
+ /join channel +
+
+

Join a channel.

+
+
+ +
+
+ /kick nick +
+
+

Kick a user from the current channel.

+
+
+ +
+
+ /list +
+
+

Retrieve a list of available channels on this network.

+
+
+ +
+
+ /me message +
+
+

+ Send an action message to the current channel. The Lounge will + display it inline, as if the message was posted in the third + person. +

+
+
+ +
+
+ /mode flags [args] +
+
+

+ Set the given flags to the current channel if the active + window is a channel, another user if the active window is a + private message window, or yourself if the current window is a + server window. +

+
+
+ +
+
+ /msg channel message +
+
+

Send a message to the specified channel.

+
+
+ +
+
+ /nick newnick +
+
+

Change your nickname on the current network.

+
+
+ +
+
+ /notice channel message +
+
+

Sends a notice message to the specified channel.

+
+
+ +
+
+ /op nick [...nick] +
+
+

+ Give op (+o) to one or several users in the + current channel. +

+
+
+ +
+
+ /part [channel] +
+
+

+ Close the specified channel or private message window, or the + current channel if channel is ommitted. +

+

Aliases: /close, /leave

+
+
+ +
+
+ /rejoin +
+
+

+ Leave and immediately rejoin the current channel. Useful to + quickly get op from ChanServ in an empty channel, for example. +

+

Alias: /cycle

+
+
+ +
+
+ /query nick +
+
+

Send a private message to the specified user.

+
+
+ +
+
+ /quit [message] +
+
+

+ Disconnect from the current network with an optional message. +

+
+
+ +
+
+ /raw message +
+
+

Send a raw message to the current IRC network.

+

Aliases: /quote, /send

+
+
+ +
+
+ /slap nick +
+
+

Slap someone in the current channel with a trout!

+
+
+ +
+
+ /topic newtopic +
+
+

Set the topic in the current channel.

+
+
+ +
+
+ /unban nick +
+
+

Unban (-b) a user from the current channel. + This can be a nickname or a hostmask.

+
+
+ +
+
+ /voice nick [...nick] +
+
+

+ Give voice (+v) to one or several users in the + current channel. +

+
+
+ +
+
+ /whois nick +
+
+

+ Retrieve information about the given user on the current + network. +

+
+
+ +

About The Lounge

+ +

+ {{#if gitCommit}} + The Lounge is running from source + ({{ gitCommit }}).
+ {{else}} + The Lounge is in version {{version}} + (See release notes).
+ {{/if}} + + Website
+ Documentation
+ Report a bug +

+
diff --git a/src/server.js b/src/server.js index 5550aae6..34305c4b 100644 --- a/src/server.js +++ b/src/server.js @@ -205,12 +205,6 @@ function index(req, res, next) { return next(); } - var data = _.merge( - pkg, - Helper.config - ); - data.gitCommit = Helper.getGitCommit(); - const policies = [ "default-src *", "connect-src 'self' ws: wss:", @@ -229,7 +223,7 @@ function index(req, res, next) { res.setHeader("Content-Security-Policy", policies.join("; ")); res.setHeader("Referrer-Policy", "no-referrer"); - res.render("index", data); + res.render("index", Helper.config); } function initializeClient(socket, client, token, lastMessage) { @@ -478,6 +472,7 @@ function getClientConfiguration() { ]); config.ldapEnabled = Helper.config.ldap.enable; + config.version = pkg.version; config.gitCommit = Helper.getGitCommit(); config.themes = themes.getAll(); From e86a155ec28fd172552fb5642b78eb2c5bc2fb06 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 12 Nov 2017 20:24:21 +0200 Subject: [PATCH 11/13] Remove express-handlebars, read manifest.json to get theme-color --- client/index.html | 8 ++++---- package.json | 1 - src/helper.js | 4 ++++ src/server.js | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/client/index.html b/client/index.html index b22b180e..78051d25 100644 --- a/client/index.html +++ b/client/index.html @@ -9,23 +9,23 @@ - + The Lounge - + - + - + " data-transports="<%- JSON.stringify(transports) %>">
diff --git a/package.json b/package.json index 4a708b30..10b557a1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "colors": "1.1.2", "commander": "2.11.0", "express": "4.16.2", - "express-handlebars": "3.0.0", "fs-extra": "4.0.2", "irc-framework": "2.9.1", "ldapjs": "1.0.1", diff --git a/src/helper.js b/src/helper.js index 1f44d81e..0f65d085 100644 --- a/src/helper.js +++ b/src/helper.js @@ -78,6 +78,10 @@ function setHome(homePath) { log.warn(`${colors.bold("displayNetwork")} and ${colors.bold("lockNetwork")} are false, setting ${colors.bold("lockNetwork")} to true.`); } + // Load theme color from manifest.json + const manifest = require("../public/manifest.json"); + this.config.themeColor = manifest.theme_color; + // TODO: Remove in future release if (this.config.debug === true) { log.warn("debug option is now an object, see defaults file for more information."); diff --git a/src/server.js b/src/server.js index 34305c4b..f7497f0d 100644 --- a/src/server.js +++ b/src/server.js @@ -5,7 +5,6 @@ var pkg = require("../package.json"); var Client = require("./client"); var ClientManager = require("./clientManager"); var express = require("express"); -var expressHandlebars = require("express-handlebars"); var fs = require("fs"); var path = require("path"); var io = require("socket.io"); @@ -39,21 +38,14 @@ module.exports = function() { } var app = express() + .disable("x-powered-by") .use(allRequests) .use(index) .use(express.static("public")) .use("/storage/", express.static(Helper.getStoragePath(), { redirect: false, maxAge: 86400 * 1000, - })) - .engine("html", expressHandlebars({ - extname: ".html", - helpers: { - tojson: (c) => JSON.stringify(c), - }, - })) - .set("view engine", "html") - .set("views", path.join(__dirname, "..", "public")); + })); app.get("/themes/:theme.css", (req, res) => { const themeName = req.params.theme; @@ -221,9 +213,17 @@ function index(req, res, next) { policies.unshift("block-all-mixed-content"); } + res.setHeader("Content-Type", "text/html"); res.setHeader("Content-Security-Policy", policies.join("; ")); res.setHeader("Referrer-Policy", "no-referrer"); - res.render("index", Helper.config); + + return fs.readFile(path.join(__dirname, "..", "public", "index.html"), "utf-8", (err, file) => { + if (err) { + throw err; + } + + res.send(_.template(file)(Helper.config)); + }); } function initializeClient(socket, client, token, lastMessage) { From adab03f730402056732dcc27d718bf46a3100308 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 12 Nov 2017 20:28:13 +0200 Subject: [PATCH 12/13] Fix test --- src/command-line/index.js | 14 ++++++++++++++ src/server.js | 5 ----- test/server.js | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/command-line/index.js b/src/command-line/index.js index 44170481..a1c5451c 100644 --- a/src/command-line/index.js +++ b/src/command-line/index.js @@ -2,6 +2,8 @@ global.log = require("../log.js"); +const fs = require("fs"); +const path = require("path"); const program = require("commander"); const colors = require("colors/safe"); const Helper = require("../helper"); @@ -22,6 +24,18 @@ if (program.home) { log.warn(`Use the ${colors.green("LOUNGE_HOME")} environment variable instead.`); } +// Check if the app was built before calling setHome as it wants to load manifest.json from the public folder +if (!fs.existsSync(path.join( + __dirname, + "..", + "..", + "public", + "manifest.json" +))) { + log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production npm run build")} to resolve this.`); + process.exit(1); +} + let home = program.home || process.env.LOUNGE_HOME; if (!home) { diff --git a/src/server.js b/src/server.js index f7497f0d..965e8284 100644 --- a/src/server.js +++ b/src/server.js @@ -32,11 +32,6 @@ module.exports = function() { (Node.js ${colors.green(process.versions.node)} on ${colors.green(process.platform)} ${process.arch})`); log.info(`Configuration file: ${colors.green(Helper.CONFIG_PATH)}`); - if (!fs.existsSync("public/js/bundle.js")) { - log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production npm run build")} to resolve this.`); - process.exit(); - } - var app = express() .disable("x-powered-by") .use(allRequests) diff --git a/test/server.js b/test/server.js index 4c0e9005..d417bc68 100644 --- a/test/server.js +++ b/test/server.js @@ -23,7 +23,7 @@ describe("Server", () => { request(webURL, (error, response, body) => { expect(error).to.be.null; expect(body).to.include("The Lounge"); - expect(body).to.include("https://thelounge.github.io/"); + expect(body).to.include("js/bundle.js"); done(); }); From 01f524b7c57b7f5feb70b957a82451a7a5fb334e Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 15 Nov 2017 20:43:38 +0200 Subject: [PATCH 13/13] Don't send defaults if not displaying network --- src/server.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index 965e8284..418fbc92 100644 --- a/src/server.js +++ b/src/server.js @@ -461,7 +461,6 @@ function getClientConfiguration() { "lockNetwork", "displayNetwork", "useHexIp", - "defaults", "themes", "prefetch", ]); @@ -471,6 +470,10 @@ function getClientConfiguration() { config.gitCommit = Helper.getGitCommit(); config.themes = themes.getAll(); + if (config.displayNetwork) { + config.defaults = Helper.config.defaults; + } + return config; }