Fix reconnection state
This commit is contained in:
parent
cd94b5d655
commit
c42fc55c6f
@ -5,6 +5,7 @@ const socket = require("../socket");
|
|||||||
const storage = require("../localStorage");
|
const storage = require("../localStorage");
|
||||||
const utils = require("../utils");
|
const utils = require("../utils");
|
||||||
const templates = require("../../views");
|
const templates = require("../../views");
|
||||||
|
const {vueApp} = require("../vue");
|
||||||
|
|
||||||
socket.on("auth", function(data) {
|
socket.on("auth", function(data) {
|
||||||
// If we reconnected and serverHash differs, that means the server restarted
|
// If we reconnected and serverHash differs, that means the server restarted
|
||||||
@ -67,7 +68,19 @@ socket.on("auth", function(data) {
|
|||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
$("#loading-page-message, #connection-error").text("Authorizing…");
|
$("#loading-page-message, #connection-error").text("Authorizing…");
|
||||||
const lastMessage = utils.lastMessageId;
|
|
||||||
|
let lastMessage = -1;
|
||||||
|
|
||||||
|
for (const network of vueApp.networks) {
|
||||||
|
for (const chan of network.channels) {
|
||||||
|
for (const msg of chan.messages) {
|
||||||
|
if (msg.id > lastMessage) {
|
||||||
|
lastMessage = msg.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
socket.emit("auth", {user, token, lastMessage});
|
socket.emit("auth", {user, token, lastMessage});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,33 @@ const {vueApp} = require("../vue");
|
|||||||
socket.on("init", function(data) {
|
socket.on("init", function(data) {
|
||||||
$("#loading-page-message, #connection-error").text("Rendering…");
|
$("#loading-page-message, #connection-error").text("Rendering…");
|
||||||
|
|
||||||
const lastMessageId = utils.lastMessageId;
|
let previousActive = vueApp.activeChannel && vueApp.activeChannel.channel.id;
|
||||||
let previousActive = 0;
|
|
||||||
|
|
||||||
if (lastMessageId > -1) {
|
|
||||||
previousActive = sidebar.find(".active").data("id");
|
|
||||||
}
|
|
||||||
|
|
||||||
const networks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));
|
const networks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));
|
||||||
|
|
||||||
for (const network of data.networks) {
|
for (const network of data.networks) {
|
||||||
network.isJoinChannelShown = false;
|
const currentNetwork = vueApp.networks.find((n) => n.uuid === network.uuid);
|
||||||
network.isCollapsed = networks.has(network.uuid);
|
|
||||||
|
// TODO: Make this updating more efficient
|
||||||
|
if (currentNetwork) {
|
||||||
|
network.isJoinChannelShown = currentNetwork.isJoinChannelShown;
|
||||||
|
network.isCollapsed = currentNetwork.isCollapsed;
|
||||||
|
|
||||||
|
for (const channel of network.channels) {
|
||||||
|
const currentChannel = currentNetwork.channels.find((c) => c.id === channel.id);
|
||||||
|
|
||||||
|
if (currentChannel && currentChannel.messages) {
|
||||||
|
channel.messages = currentChannel.messages.concat(channel.messages);
|
||||||
|
|
||||||
|
if (currentChannel.moreHistoryAvailable) {
|
||||||
|
channel.moreHistoryAvailable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
network.isJoinChannelShown = false;
|
||||||
|
network.isCollapsed = networks.has(network.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
for (const channel of network.channels) {
|
for (const channel of network.channels) {
|
||||||
if (channel.type === "channel") {
|
if (channel.type === "channel") {
|
||||||
@ -38,7 +53,9 @@ socket.on("init", function(data) {
|
|||||||
|
|
||||||
$("#connection-error").removeClass("shown");
|
$("#connection-error").removeClass("shown");
|
||||||
|
|
||||||
if (lastMessageId < 0) {
|
if (!vueApp.initialized) {
|
||||||
|
vueApp.initialized = true;
|
||||||
|
|
||||||
if (data.token) {
|
if (data.token) {
|
||||||
storage.set("token", data.token);
|
storage.set("token", data.token);
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,6 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
socket.on("msg", function(data) {
|
socket.on("msg", function(data) {
|
||||||
if (utils.lastMessageId < data.msg.id) {
|
|
||||||
utils.lastMessageId = data.msg.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
let targetId = data.chan;
|
let targetId = data.chan;
|
||||||
let {channel} = findChannel(data.chan);
|
let {channel} = findChannel(data.chan);
|
||||||
|
|
||||||
|
@ -6,14 +6,12 @@ const viewport = $("#viewport");
|
|||||||
const {vueApp} = require("./vue");
|
const {vueApp} = require("./vue");
|
||||||
|
|
||||||
var serverHash = -1; // eslint-disable-line no-var
|
var serverHash = -1; // eslint-disable-line no-var
|
||||||
var lastMessageId = -1; // eslint-disable-line no-var
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// Same value as media query in CSS that forces sidebars to become overlays
|
// Same value as media query in CSS that forces sidebars to become overlays
|
||||||
mobileViewportPixels: 768,
|
mobileViewportPixels: 768,
|
||||||
findCurrentNetworkChan,
|
findCurrentNetworkChan,
|
||||||
serverHash,
|
serverHash,
|
||||||
lastMessageId,
|
|
||||||
confirmExit,
|
confirmExit,
|
||||||
scrollIntoViewNicely,
|
scrollIntoViewNicely,
|
||||||
hasRoleInChannel,
|
hasRoleInChannel,
|
||||||
|
@ -21,6 +21,7 @@ Vue.filter("roundBadgeNumber", roundBadgeNumber);
|
|||||||
const vueApp = new Vue({
|
const vueApp = new Vue({
|
||||||
el: "#viewport",
|
el: "#viewport",
|
||||||
data: {
|
data: {
|
||||||
|
initialized: false,
|
||||||
connected: false,
|
connected: false,
|
||||||
appName: document.title,
|
appName: document.title,
|
||||||
activeChannel: null,
|
activeChannel: null,
|
||||||
|
Loading…
Reference in New Issue
Block a user