refactor: move session messages

isekai-main
Barış Soner Uşaklı 3 years ago
parent 3d2398ac4c
commit 666fe209f0

@ -212,39 +212,6 @@ app.cacheBuster = null;
});
};
app.handleInvalidSession = function () {
socket.disconnect();
app.logout(false);
require(['bootbox'], function (bootbox) {
bootbox.alert({
title: '[[error:invalid-session]]',
message: '[[error:invalid-session-text]]',
closeButton: false,
callback: function () {
window.location.reload();
},
});
});
};
app.handleSessionMismatch = () => {
if (app.flags._login || app.flags._logout) {
return;
}
socket.disconnect();
require(['bootbox'], function (bootbox) {
bootbox.alert({
title: '[[error:session-mismatch]]',
message: '[[error:session-mismatch-text]]',
closeButton: false,
callback: function () {
window.location.reload();
},
});
});
};
app.enterRoom = function (room, callback) {
callback = callback || function () { };
if (socket && app.user.uid && app.currentRoom !== room) {

@ -1,6 +1,6 @@
'use strict';
define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, translator, storage) {
define('messages', ['bootbox', 'translator', 'storage', 'alerts'], function (bootbox, translator, storage, alerts) {
const messages = {};
let showWelcomeMessage;
@ -81,7 +81,7 @@ define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, tran
registerMessage = params.register;
if (showWelcomeMessage) {
app.alert({
alerts.alert({
type: 'success',
title: '[[global:welcome_back]] ' + app.user.username + '!',
message: '[[global:you_have_successfully_logged_in]]',
@ -96,5 +96,27 @@ define('messages', ['bootbox', 'translator', 'storage'], function (bootbox, tran
}
}
messages.showInvalidSession = function () {
bootbox.alert({
title: '[[error:invalid-session]]',
message: '[[error:invalid-session-text]]',
closeButton: false,
callback: function () {
window.location.reload();
},
});
};
messages.showSessionMismatch = function () {
bootbox.alert({
title: '[[error:session-mismatch]]',
message: '[[error:session-mismatch-text]]',
closeButton: false,
callback: function () {
window.location.reload();
},
});
};
return messages;
});

@ -80,11 +80,11 @@ socket = window.socket;
socket.on('checkSession', function (uid) {
if (parseInt(uid, 10) !== parseInt(app.user.uid, 10)) {
app.handleSessionMismatch();
handleSessionMismatch();
}
});
socket.on('event:invalid_session', () => {
app.handleInvalidSession();
handleInvalidSession();
});
socket.on('setHostname', function (hostname) {
@ -126,6 +126,25 @@ socket = window.socket;
});
}
function handleInvalidSession() {
socket.disconnect();
app.logout(false);
require(['messages'], function (messages) {
messages.showInvalidSession();
});
}
function handleSessionMismatch() {
if (app.flags._login || app.flags._logout) {
return;
}
socket.disconnect();
require(['messages'], function (messages) {
messages.showSessionMismatch();
});
}
function onConnect() {
if (!reconnecting) {
hooks.fire('action:connected');

Loading…
Cancel
Save