whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: agenda session recovery
Date Thu, 03 Nov 2016 14:34:43 GMT
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  12c1f91   agenda session recovery
12c1f91 is described below

commit 12c1f91833b191fc8f6b8f78ea808b05d0fb8b61
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Thu Nov 3 10:34:04 2016 -0400

    agenda session recovery
---
 www/board/agenda/daemon/session.rb         | 12 ++++++++++--
 www/board/agenda/daemon/wss.rb             |  4 ++++
 www/board/agenda/views/models/events.js.rb | 17 ++++++++++++++---
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/www/board/agenda/daemon/session.rb b/www/board/agenda/daemon/session.rb
index 4fbb8f3..842ac39 100644
--- a/www/board/agenda/daemon/session.rb
+++ b/www/board/agenda/daemon/session.rb
@@ -36,7 +36,7 @@ class Session
 
     # if not found, try refreshing data from disk and try again
     if not session
-      self.load 
+      Session.load 
       session = @@users[id].sort_by {|session| session[:mtime]}.last
       session = nil if session and session[:mtime] < Time.now - DAY
     end
@@ -59,7 +59,15 @@ class Session
 
   # retrieve session for a given secret
   def self.[](secret)
-    @@sessions[secret]
+    session = @@sessions[secret]
+
+    # if not found, try refreshing data from disk and try again
+    if not session
+      Session.load
+      session = @@sessions[secret]
+    end
+
+    session
   end
 
   # load sessions from disk
diff --git a/www/board/agenda/daemon/wss.rb b/www/board/agenda/daemon/wss.rb
index acef407..02ff1d6 100755
--- a/www/board/agenda/daemon/wss.rb
+++ b/www/board/agenda/daemon/wss.rb
@@ -135,6 +135,10 @@ EM.run do
           restart_process if headers['restart']
           Channel.add ws, session[:id]
           ws.send JSON.dump(session.merge type: 'login')
+        else
+          msg = ''
+          ws.send JSON.dump(type: 'unauthorized', session: headers['session'])
+          EM.add_timer(1) {ws.close}
         end
       end
 
diff --git a/www/board/agenda/views/models/events.js.rb b/www/board/agenda/views/models/events.js.rb
index 770d816..009a4c7 100644
--- a/www/board/agenda/views/models/events.js.rb
+++ b/www/board/agenda/views/models/events.js.rb
@@ -96,8 +96,10 @@ class Events
         options = {credentials: 'include'}
         request = Request.new("../session.json", options)
         fetch(request).then do |response|
-          Server.session = response.session
-          self.master()
+          response.json().then do |json|
+            Server.session = json.session
+            self.master()
+          end
         end
       end
 
@@ -163,7 +165,16 @@ class Events
     message = JSON.parse(data)
     self.log message
 
-    if @@subscriptions[message.type]
+    if message.type == :unauthorized
+      options = {credentials: 'include'}
+      request = Request.new("../session.json", options)
+      fetch(request).then do |response|
+        response.json().then do |json|
+          console.log json
+          Server.session = json.session
+        end
+      end
+    elsif @@subscriptions[message.type]
       @@subscriptions[message.type].each {|sub| sub(message)}
     end
 

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

Mime
View raw message