loleaflet/src/control/Toolbar.js |   53 ++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 31 deletions(-)

New commits:
commit 3dcb6b042fbd96e58d2809add3b131c1db5b9a82
Author:     Muhammet Kara <muhammet.k...@collabora.com>
AuthorDate: Mon Jun 29 14:24:32 2020 +0300
Commit:     Muhammet Kara <muhammet.k...@collabora.com>
CommitDate: Mon Jun 29 21:42:08 2020 +0200

    Welcome: Use localStorage instead of cookies
    
    Change-Id: I0ab431f065dbe8d76d1e7ff18023be744c590dc8
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97400
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Reviewed-by: Muhammet Kara <muhammet.k...@collabora.com>

diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 7f24d3a55..354175074 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;
                }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to