[Libreoffice-commits] online.git: Branch 'distro/collabora/co-4-2' - loleaflet/src
Muhammet Kara (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 29 14:20:30 UTC 2020
loleaflet/src/control/Toolbar.js | 53 ++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 31 deletions(-)
New commits:
commit d4841aef011f8bb6dd1e07989f9999bbb8a95347
Author: Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Mon Jun 29 14:24:32 2020 +0300
Commit: Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Mon Jun 29 16:20:11 2020 +0200
Welcome: Use localStorage instead of cookies
Change-Id: I0ab431f065dbe8d76d1e7ff18023be744c590dc8
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97380
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 6f76e0540..fe67909f0 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -415,13 +415,7 @@ L.Map.include({
},
beforeClose: function () {
if (!calledFromMenu) {
- var WSDVerCookie = 'WSDWelcomeVersion=' + map._socket.WSDServer.Version;
- // Cookie will not expire for a year, and it will not be sent to other domains
- var cookiePath = '/loleaflet';
- if (window.socketProxy)
- cookiePath = window.host + window.serviceRoot + cookiePath;
- WSDVerCookie += '; max-age=31536000; SameSite=Lax; path=' + cookiePath;
- document.cookie = WSDVerCookie;
+ localStorage.setItem('WSDWelcomeVersion', map._socket.WSDServer.Version);
}
map.focus();
map.enable(true);
@@ -449,41 +443,38 @@ L.Map.include({
map._showWelcomeDialogVex(data, calledFromMenu);
})
.fail(function() {
- // Welcome dialog disabled in loolwsd.xml or nonexistant for some other reason
- // Let's check back in a day (60 x 60 x 24 = 86400 seconds)
- var cookiePath = '/loleaflet';
- if (window.socketProxy)
- cookiePath = window.host + window.serviceRoot + cookiePath;
- var welcomeDisabledCookie = 'WSDWelcomeDisabled=true; max-age=86400; SameSite=Lax; path=' + cookiePath;
- document.cookie = welcomeDisabledCookie;
+ var currentDate = new Date();
+ localStorage.setItem('WSDWelcomeDisabled', 'true');
+ localStorage.setItem('WSDWelcomeDisabledDate', currentDate.toDateString());
if (calledFromMenu)
map._showWelcomeDialogVex(_('We are sorry, the information about the latest updates is not available.'));
});
},
- getCookie: function(name) {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = cookies[i].trim();
- if (cookie.indexOf(name) === 0) {
- return cookie;
- }
- }
-
- return '';
- },
-
shouldWelcome: function() {
if (!window.enableWelcomeMessage || L.Browser.cypressTest)
return false;
- var currentVerCookie = this.getCookie('WSDWelcomeVersion');
- var newVerCookie = 'WSDWelcomeVersion=' + this._socket.WSDServer.Version;
- var welcomeDisabledCookie = this.getCookie('WSDWelcomeDisabled');
- var isWelcomeDisabled = welcomeDisabledCookie === 'WSDWelcomeDisabled=true';
+ var storedVersion = localStorage.getItem('WSDWelcomeVersion');
+ var currentVersion = this._socket.WSDServer.Version;
+ var welcomeDisabledCookie = localStorage.getItem('WSDWelcomeDisabled');
+ var welcomeDisabledDate = localStorage.getItem('WSDWelcomeDisabledDate');
+ var isWelcomeDisabled = false;
+
+ if (welcomeDisabledCookie && welcomeDisabledDate) {
+ // Check if we are stil in the same day
+ var currentDate = new Date();
+ if (welcomeDisabledDate === currentDate.toDateString())
+ isWelcomeDisabled = true;
+ else {
+ //Values expired. Clear the local values
+ localStorage.removeItem('WSDWelcomeDisabled');
+ localStorage.removeItem('WSDWelcomeDisabledDate');
+ }
+ }
- if (currentVerCookie !== newVerCookie && !isWelcomeDisabled) {
+ if ((!storedVersion || storedVersion !== currentVersion) && !isWelcomeDisabled) {
return true;
}
More information about the Libreoffice-commits
mailing list