whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/2] Commit 5605545: fix typo
Date Tue, 12 Jan 2016 19:22:27 GMT
Commit 56055459711a54be8fad3e964a66ed5fd3af4074:
    fix typo


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
asf.version                                                  | + -
lib/whimsy/asf/rack.rb                                       | ++ -
www/secmail/models/mailbox.rb                                | +++++++++++++ -
www/secmail/views/actions/check-mail.json.rb                 | +++++ --
www/secmail/views/index.js.rb                                | +++++++++++ -
www/secmail/views/index.json.rb                              | ++ -----------
------------------------------------------------------------
86 changes: 57 additions, 29 deletions.
------------------------------------------------------------


diff --git a/asf.version b/asf.version
index c09f75a..36e6a20 100644
--- a/asf.version
+++ b/asf.version
@@ -1 +1 @@
-0.0.71
+0.0.72
diff --git a/lib/whimsy/asf/rack.rb b/lib/whimsy/asf/rack.rb
index 362bdba..733faf0 100644
--- a/lib/whimsy/asf/rack.rb
+++ b/lib/whimsy/asf/rack.rb
@@ -114,7 +114,8 @@ def initialize(app, frequency=100, minutes=15)
           # Phusion Passenger < 4.0.33
           require 'phusion_passenger/rack/out_of_band_gc'
         end
-        @passenger = PhusionPassenger::Rack::OutOfBandGc.new(app.count)
+
+        @passenger = PhusionPassenger::Rack::OutOfBandGc.new(app, count)
       end
 
       Thread.kill(@@background) if @@background
diff --git a/www/secmail/models/mailbox.rb b/www/secmail/models/mailbox.rb
index afae959..21660f6 100644
--- a/www/secmail/models/mailbox.rb
+++ b/www/secmail/models/mailbox.rb
@@ -140,7 +140,7 @@ def dir
   end
 
   #
-  # return headers
+  # return headers (server view)
   #
   def headers
     messages = YAML.load_file(yaml_file) rescue {}
@@ -151,6 +151,30 @@ def headers
   end
 
   #
+  # return headers (client view)
+  #
+  def client_headers
+    # fetch a list of headers for all messages in the maibox with attachments
+    headers = self.headers.to_a.select do |id, message|
+      message[:attachments]
+    end
+
+    # extract relevant fields from the headers
+    headers.map! do |id, message|
+      {
+        time: message[:time],
+        href: "#{message[:source]}/#{id}/",
+        from: message[:from],
+        subject: message['Subject'],
+        status: message[:status]
+      }
+    end
+
+    # return messages sorted in reverse chronological order
+    headers.sort_by {|message| message[:time]}.reverse
+  end
+
+  #
   # common header logic for messages and attachments
   #
   def self.headers(part)
diff --git a/www/secmail/views/actions/check-mail.json.rb b/www/secmail/views/actions/check-mail.json.rb
index 625d557..853afa1 100644
--- a/www/secmail/views/actions/check-mail.json.rb
+++ b/www/secmail/views/actions/check-mail.json.rb
@@ -1,4 +1,7 @@
 Mailbox.fetch @mbox
-Mailbox.new(@mbox).parse
 
-{success: true}
+mbox = Mailbox.new(@mbox)
+
+mbox.parse
+
+{messages: mbox.client_headers}
diff --git a/www/secmail/views/index.js.rb b/www/secmail/views/index.js.rb
index b683ce1..e1cd53b 100644
--- a/www/secmail/views/index.js.rb
+++ b/www/secmail/views/index.js.rb
@@ -92,19 +92,38 @@ def fetch_month(&block)
       @nextmbox = response.mbox
 
       # add messages to list
-      @messages = @messages.concat(*response.messages)
+      self.merge response.messages
 
       # select oldest message
       self.selectRow Status.selected || @messages.last unless @selected
 
       # if block provided, call it
-      block() if block
+      block() if block and block.is_a? Function
     }.catch {|error|
       console.log error
       alert error
     }
   end
 
+  # merge new messages into the list
+  def merge(messages)
+    messages.each do |new_message|
+      index = @messages.find_index do |old_message| 
+        old_message.time+old_message.hash <= new_message.time+new_message.hash
+      end
+
+      if index == -1
+        @messages << new_message
+      elsif @messages[index].hash == new_message.hash
+        @messages[index] = @new_message
+      else
+        @messages.splice index, 0, new_message
+      end
+    end
+
+    self.forceUpdate() unless messages.empty?
+  end
+
   # update @selected, given either a DOM event or a message
   def selectRow(object)
     if not object
diff --git a/www/secmail/views/index.json.rb b/www/secmail/views/index.json.rb
index 5482bb3..82c6ed5 100644
--- a/www/secmail/views/index.json.rb
+++ b/www/secmail/views/index.json.rb
@@ -4,28 +4,9 @@
 
 # if found, process it
 if index
-  # fetch a list of headers for all messages in the maibox with attachments
-  headers = Mailbox.new(@mbox).headers.to_a.select do |id, message|
-    message[:attachments]
-  end
-
-  # extract relevant fields from the headers
-  headers.map! do |id, message|
-    {
-      time: message[:time],
-      href: "#{message[:source]}/#{id}/",
-      from: message[:from],
-      subject: message['Subject'],
-      status: message[:status]
-    }
-  end
-
-  # select previous mailbox
-  mbox = available[index-1].untaint
-
-  # return mailbox name and messages
+  # return previous mailbox name and headers for the messages in the mbox
   {
-    mbox: (File.basename(mbox, '.yml') if index > 0),
-    messages: headers.sort_by {|message| message[:time]}.reverse
+    mbox: (File.basename(available[index-1].untaint, '.yml') if index > 0),
+    messages: Mailbox.new(@mbox).client_headers
   }
 end

Mime
View raw message