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: resync reporter drafts after waking up from sleep
Date Wed, 14 Aug 2019 01:06:54 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 022854d  resync reporter drafts after waking up from sleep
022854d is described below

commit 022854d17ed66c7a63cc00aab3d864e878ae0098
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Tue Aug 13 21:06:19 2019 -0400

    resync reporter drafts after waking up from sleep
---
 www/board/agenda/models/reporter.rb          | 13 +++++++++++--
 www/board/agenda/routes.rb                   | 11 ++++++++---
 www/board/agenda/views/models/events.js.rb   |  6 +++---
 www/board/agenda/views/models/reporter.js.rb | 10 ++++++----
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/www/board/agenda/models/reporter.rb b/www/board/agenda/models/reporter.rb
index 35a5c88..a6e6189 100644
--- a/www/board/agenda/models/reporter.rb
+++ b/www/board/agenda/models/reporter.rb
@@ -8,6 +8,8 @@
 
 class Reporter
   @@partial = true
+  @@agenda = nil
+  @@digest = nil
 
   def self.drafts(env, update=nil)
     changed = false
@@ -77,7 +79,7 @@ class Reporter
 
     if changed
       digest = Digest::MD5.hexdigest(JSON.dump(results[:drafts]))
-      Events.post type: 'reporter', digest: digest
+      Events.post type: 'reporter', agenda: agenda_file, digest: digest
     end
 
     # filter drafts based on user visibility
@@ -89,8 +91,15 @@ class Reporter
       end
     end
 
-    results[:digest] = Digest::MD5.hexdigest(JSON.dump(results[:drafts]))
+    @@digest = Digest::MD5.hexdigest(JSON.dump(results[:drafts]))
+    @@agenda = agenda_file
+    results[:digest] = @@digest
 
     results
   end
+
+  # return digest information
+  def self.digest
+    {agenda: @@agenda, digest: @@digest}
+  end
 end
diff --git a/www/board/agenda/routes.rb b/www/board/agenda/routes.rb
index 3b99499..9fd21d8 100755
--- a/www/board/agenda/routes.rb
+++ b/www/board/agenda/routes.rb
@@ -164,9 +164,14 @@ end
 get %r{/(\d\d\d\d-\d\d-\d\d)/digest\.json} do |date|
   agenda = "board_agenda_#{date.gsub('-','_')}.txt"
   _json(
-    file: agenda,
-    digest: Agenda[agenda][:digest],
-    etag: Agenda.uptodate(agenda) ? Agenda[agenda][:etag] : nil
+    {
+      agenda: {
+        file: agenda,
+        digest: Agenda[agenda][:digest],
+        etag: Agenda.uptodate(agenda) ? Agenda[agenda][:etag] : nil
+      },
+      reporter: Reporter.digest
+    }
   )
 end
 
diff --git a/www/board/agenda/views/models/events.js.rb b/www/board/agenda/views/models/events.js.rb
index 1843e89..8397f03 100644
--- a/www/board/agenda/views/models/events.js.rb
+++ b/www/board/agenda/views/models/events.js.rb
@@ -151,12 +151,12 @@ class Events
       self.log 'WebSocket connection established'
 
       if check_for_updates
-        # see if the agenda changed
+        # see if the agenda or reporter data changed
         fetch('digest.json', credentials: 'include').then do |response|
           if response.ok
             response.json().then do |json|
-              json.type = :agenda
-              Events.broadcast json
+              Events.broadcast json.agenda.merge(type: agenda)
+              Events.broadcast json.reporter.merge(type: reporter)
             end
           end
         end
diff --git a/www/board/agenda/views/models/reporter.js.rb b/www/board/agenda/views/models/reporter.js.rb
index dd8792e..e334522 100644
--- a/www/board/agenda/views/models/reporter.js.rb
+++ b/www/board/agenda/views/models/reporter.js.rb
@@ -11,11 +11,13 @@ class Reporter
 
   # if digest has changed (or nothing was previously fetched) get list
   # of forgotten reports from the server
-  def self.fetch(digest)
+  def self.fetch(agenda, digest)
     if not @@forgotten or @@forgotten.digest != digest
       @@forgotten ||= {}
-      JSONStorage.fetch 'reporter' do |forgotten|
-        @@forgotten = forgotten
+      if not agenda or agenda == Agenda.file
+        JSONStorage.fetch 'reporter' do |forgotten|
+          @@forgotten = forgotten
+        end
       end
     end
   end
@@ -38,5 +40,5 @@ class Reporter
 end
 
 Events.subscribe :reporter do |message|
-  Reporter.fetch(message.digest)
+  Reporter.fetch(message.agenda, message.digest)
 end


Mime
View raw message