Merge pull request #1757 from thelounge/xpaw/detached-sign-in

Do not keep sign-in and loader references in memory
This commit is contained in:
Jérémie Astori 2017-11-27 18:32:20 -05:00 committed by GitHub
commit c9da29f2fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 28 deletions

View File

@ -6,8 +6,6 @@ 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
@ -18,30 +16,36 @@ socket.on("auth", function(data) {
return;
}
utils.serverHash = data.serverHash;
const login = $("#sign-in");
if (data.serverHash > -1) {
utils.serverHash = data.serverHash;
login.html(templates.windows.sign_in());
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;
});
} else {
login.find(".btn").prop("disabled", false);
}
let token;
const user = storage.get("user");
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) {
socket.disconnect();

View File

@ -4,7 +4,6 @@ const $ = require("jquery");
const io = require("socket.io-client");
const utils = require("./utils");
const path = window.location.pathname + "socket.io/";
const status = $("#loading-page-message, #connection-error");
const socket = io({
transports: $(document.body).data("transports"),
@ -18,11 +17,11 @@ socket.on("connect_error", handleDisconnect);
socket.on("error", handleDisconnect);
socket.on("reconnecting", function(attempt) {
status.text(`Reconnecting… (attempt ${attempt})`);
$("#loading-page-message, #connection-error").text(`Reconnecting… (attempt ${attempt})`);
});
socket.on("connecting", function() {
status.text("Connecting…");
$("#loading-page-message, #connection-error").text("Connecting…");
});
socket.on("connect", function() {
@ -31,17 +30,17 @@ socket.on("connect", function() {
// nothing is sent to the server that might have happened.
socket.sendBuffer = [];
status.text("Finalizing connection…");
$("#loading-page-message, #connection-error").text("Finalizing connection…");
});
socket.on("authorized", function() {
status.text("Loading messages…");
$("#loading-page-message, #connection-error").text("Loading messages…");
});
function handleDisconnect(data) {
const message = data.message || data;
status.text(`Waiting to reconnect… (${message})`).addClass("shown");
$("#loading-page-message, #connection-error").text(`Waiting to reconnect… (${message})`).addClass("shown");
$(".show-more-button, #input").prop("disabled", true);
$("#submit").hide();