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
|
|
|
|
});
|
|
|
|
if (target.length === 0) {
|
|
|
|
const first = sidebar.find(".chan")
|
|
|
|
.eq(0)
|
|
|
|
.trigger("click");
|
|
|
|
if (first.length === 0) {
|
|
|
|
$("#footer").find(".connect").trigger("click", {
|
|
|
|
pushState: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|