This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  4c43f25   serviceworker bootstrap w/ session
4c43f25 is described below

commit 4c43f2583b1c24dc7d8207433e8b61d7a46838bc
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Mon Oct 17 15:21:09 2016 -0400

    serviceworker bootstrap w/ session
---
 www/board/agenda/routes.rb                 |  7 +++++++
 www/board/agenda/views/models/events.js.rb | 11 ++++++++++-
 www/board/agenda/views/sw.js.rb            | 12 ++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index e77d738..b84795e 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -31,6 +31,12 @@ get '/missing' do
   status 302
 end
 
+get '/session.json' do
+  _json do
+    {session: Session.user(env.user)}
+  end
+end
+
 # for debugging purposes
 get '/env' do
   content_type 'text/plain'
@@ -120,6 +126,7 @@ get %r{/(\d\d\d\d-\d\d-\d\d)/(.*)} do |date, path|
     @page[:parsed] = [@page[:parsed].first]
     @page[:digest] = nil
     @page[:etag] = nil
+    @server[:session] = nil
     _html :bootstrap
   else
     _html :main
diff --git a/www/board/agenda/views/models/events.js.rb 
b/www/board/agenda/views/models/events.js.rb
index f2c82ac..770d816 100644
--- a/www/board/agenda/views/models/events.js.rb
+++ b/www/board/agenda/views/models/events.js.rb
@@ -90,7 +90,16 @@ class Events
       localStorage.setItem("#{@@prefix}-master", @@master = @@timestamp)
       @@ondeck = localStorage.removeItem("#{@@prefix}-ondeck")
 
-      self.master()
+      if Server.session
+        self.master()
+      else
+        options = {credentials: 'include'}
+        request = Request.new("../session.json", options)
+        fetch(request).then do |response|
+          Server.session = response.session
+          self.master()
+        end
+      end
 
     elsif 
       @@ondeck == nil and @@master != @@timestamp and
diff --git a/www/board/agenda/views/sw.js.rb b/www/board/agenda/views/sw.js.rb
index 7100d65..6580dbc 100644
--- a/www/board/agenda/views/sw.js.rb
+++ b/www/board/agenda/views/sw.js.rb
@@ -6,12 +6,24 @@
 #      agenda.json, as well as update the cache.
 # 
 
+# install immediately
+self.addEventListener :install do
+  return self.skipWaiting()
+end
+
+# take over responsibility for existing clients
+self.addEventListener :activate do
+  return self.clients.claim();
+end
+
+# respond with bootstrap fetch patch
 self.addEventListener :fetch do |event|
   scope = self.registration.scope
   url = event.request.url
   url = url.slice(scope.length) if url.start_with? scope
 
   if url =~ %r{^\d\d\d\d-\d\d-\d\d/} and event.request.method == 'GET'
+    return if url.end_with? '/bootstrap.html'
     event.respondWith(
       caches.open('board/agenda').then do |cache|
         date =  url.split('/')[0]

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Reply via email to