2017-05-18 20:08:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../socket");
|
|
|
|
const render = require("../render");
|
2017-07-10 19:47:03 +00:00
|
|
|
const webpush = require("../webpush");
|
2017-05-18 20:08:54 +00:00
|
|
|
const sidebar = $("#sidebar");
|
|
|
|
const storage = require("../localStorage");
|
|
|
|
|
|
|
|
socket.on("init", function(data) {
|
|
|
|
$("#loading-page-message").text("Rendering…");
|
|
|
|
|
|
|
|
if (data.networks.length === 0) {
|
|
|
|
$("#footer").find(".connect").trigger("click", {
|
|
|
|
pushState: false,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
render.renderNetworks(data);
|
|
|
|
}
|
|
|
|
|
2017-06-21 07:58:29 +00:00
|
|
|
if (data.token) {
|
2017-05-18 20:08:54 +00:00
|
|
|
storage.set("token", data.token);
|
|
|
|
}
|
|
|
|
|
2017-07-10 19:47:03 +00:00
|
|
|
webpush.configurePushNotifications(data.pushSubscription, data.applicationServerKey);
|
|
|
|
|
2017-05-18 20:08:54 +00:00
|
|
|
$("body").removeClass("signed-out");
|
|
|
|
$("#loading").remove();
|
|
|
|
$("#sign-in").remove();
|
|
|
|
|
|
|
|
const id = data.active;
|
|
|
|
const target = sidebar.find("[data-id='" + id + "']").trigger("click", {
|
|
|
|
replaceHistory: true
|
|
|
|
});
|
2017-06-28 21:37:07 +00:00
|
|
|
const dataTarget = document.querySelector("[data-target='" + window.location.hash + "']");
|
|
|
|
if (window.location.hash && dataTarget) {
|
|
|
|
dataTarget.click();
|
|
|
|
} else if (target.length === 0) {
|
2017-05-18 20:08:54 +00:00
|
|
|
const first = sidebar.find(".chan")
|
|
|
|
.eq(0)
|
|
|
|
.trigger("click");
|
|
|
|
if (first.length === 0) {
|
|
|
|
$("#footer").find(".connect").trigger("click", {
|
|
|
|
pushState: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|