From 6b5646f70b1c14eadeb9778f93e078338f45f3f4 Mon Sep 17 00:00:00 2001
From: Patrick J Cherry <patrick@bytemark.co.uk>
Date: Tue, 8 May 2012 14:21:45 +0100
Subject: Changed destroy! to destroy everywhere to ensure Histories are
 deleted correctly.  Added test.

---
 lib/mauve/alert_changed.rb  | 2 +-
 lib/mauve/notifiers/xmpp.rb | 2 +-
 lib/mauve/web_interface.rb  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

(limited to 'lib/mauve')

diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb
index 0e0d257..2e3ac7d 100644
--- a/lib/mauve/alert_changed.rb
+++ b/lib/mauve/alert_changed.rb
@@ -71,7 +71,7 @@ module Mauve
     def remind
       unless alert.is_a?(Alert)
         logger.info "#{self.inspect} lost alert #{alert_id}.  Killing self."
-        destroy!
+        destroy
         return false
       end
       
diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index 323f89d..dc44f1c 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -677,7 +677,7 @@ EOF
               next
             end
 
-            if alert.destroy!
+            if alert.destroy
               msg << "#{alert.to_s} destroyed"
             else
               msg << "#{alert.to_s}: destruction failed."
diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb
index 9a46403..b5c0442 100644
--- a/lib/mauve/web_interface.rb
+++ b/lib/mauve/web_interface.rb
@@ -409,7 +409,7 @@ EOF
     
     post '/alert/:id/destroy' do
       alert = Alert.get(params[:id])
-      alert.destroy!
+      alert.destroy
       flash['notice'] = "Successfully destroyed alert #{alert.alert_id} from source #{alert.source}."
       redirect "/"
     end
-- 
cgit v1.2.3


From 90d4fe602abc04e7665735a1466e2df174dcb476 Mon Sep 17 00:00:00 2001
From: Patrick J Cherry <patrick@bytemark.co.uk>
Date: Tue, 8 May 2012 14:22:45 +0100
Subject: Added dummy xmpp method to PeopleList to make sure that it doesn't
 cause the XMPP stuff to barf.

---
 lib/mauve/people_list.rb | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'lib/mauve')

diff --git a/lib/mauve/people_list.rb b/lib/mauve/people_list.rb
index 8178635..7124241 100644
--- a/lib/mauve/people_list.rb
+++ b/lib/mauve/people_list.rb
@@ -25,6 +25,11 @@ module Mauve
 
     alias username label
 
+    #
+    # A dummy XMPP method.
+    #
+    def xmpp; nil ; end
+
     # Append an Array or String to a list
     #
     # @param [Array or String] arr
-- 
cgit v1.2.3


From bebac3756dd535bf754752a34ab8061098d7b91d Mon Sep 17 00:00:00 2001
From: Patrick J Cherry <patrick@bytemark.co.uk>
Date: Wed, 9 May 2012 16:38:17 +0100
Subject: Remnoved destroy command and replaced with clear.

---
 lib/mauve/notifiers/xmpp.rb | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

(limited to 'lib/mauve')

diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index dc44f1c..f2c5503 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -474,8 +474,10 @@ module Mauve
               do_parse_show(msg)
             when /ack/i
               do_parse_ack(msg)
+            when /clear/i
+              do_parse_clear(msg)
             when /destroy\s?/i
-              do_parse_destroy(msg)
+              "Sorry -- destroy has been disabled.  Try \"clear\" instead."
             else
               File.executable?('/usr/games/fortune') ? `/usr/games/fortune -s -n 60`.chomp : "I'd love to stay and chat, but I'm really quite busy"
           end          
@@ -577,7 +579,7 @@ EOF
 
         def do_parse_ack(msg)
           return "Sorry -- I don't understand your acknowledge command." unless
-             msg.body =~ /ack(?:nowledge)?\s+([\d\D]+)\s+for\s+(\d+(?:\.\d+)?)\s+(work(?:ing)?|day(?:time)?|wall(?:-?clock)?)?\s*(day|hour|min(?:ute)?|sec(?:ond))s?(?:\s+because\s+(.*))?/i
+             msg.body =~ /ack(?:nowledge)?\s+([\d\D]+)\s+for\s+(\d+(?:\.\d+)?)\s+(work(?:ing)?|day(?:time)?|wall(?:-?clock)?)?\s*(day|hour|min(?:ute)?|sec(?:ond))s?(?:\s+(?:cos|cause|as|because)?\s*(.*))?/i
           
           alerts, n_hours, type_hours, dhms, note = [$1,$2, $3, $4, $5]
 
@@ -654,35 +656,50 @@ EOF
           return msg.join("\n")
         end
 
-        def do_parse_destroy(msg)
-          return "Sorry -- I don't understand your destroy command." unless
-             msg.body =~ /destroy\s+([\d\D]+)$/i
+        def do_parse_clear(msg)
+          return "Sorry -- I don't understand your clear command." unless
+             msg.body =~ /clear\s+([\d\D]+)(?:\s+(?:coz|cause|cos|because|as)?\s*(.*))?/i
 
           alerts = $1.split(/\D+/)
+          note   = $2
           
           username = get_username_for(msg.from)
 
           if is_muc?(Configuration.current.people[username].xmpp)
-            return "I'm sorry -- if you want to destroy alerts, please do it from a private chat"
+            return "I'm sorry -- if you want to clear alerts, please do it from a private chat"
           end
 
           msg = []
-          msg << "Results of your destruction:" if alerts.length > 1
+          msg << "Clearing results:" if alerts.length > 1
 
           alerts.each do |alert_id|
             alert = Alert.get(alert_id)
 
             if alert.nil?
-              msg << "#{alert_id}: alert not found"
+              msg << "#{alert_id}: alert not found."
               next
             end
 
-            if alert.destroy
-              msg << "#{alert.to_s} destroyed"
+            if alert.cleared?
+              msg << "#{alert_id}: alert already cleared."
+              next
+            end 
+
+            if alert.clear!
+              msg << "#{alert.to_s} cleared."
             else
-              msg << "#{alert.to_s}: destruction failed."
+              msg << "#{alert.to_s}: clearing failed."
             end
           end
+          
+          #
+          # Add the note.
+          #
+          unless note.to_s.empty?
+            note = Alert.remove_html(note)
+            h = History.new(:alerts => succeeded, :type => "note", :event => note.to_s, :user => username)
+            logger.debug h.errors unless h.save
+          end
 
           return msg.join("\n")
         end
-- 
cgit v1.2.3


From 196b337a02f959a431a4bb7c443ed116e4e291f3 Mon Sep 17 00:00:00 2001
From: Patrick J Cherry <patrick@bytemark.co.uk>
Date: Wed, 9 May 2012 17:04:39 +0100
Subject: DuringRunner#no_one_in now is only evaluated once per instance per
 people_list to prevent the calendar getting thrashed.

---
 lib/mauve/notification.rb | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

(limited to 'lib/mauve')

diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index 82da2e8..57d82d2 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -115,16 +115,23 @@ module Mauve
     
     protected
 
-    # Test to see if a people_list is empty.
+    # Test to see if a people_list is empty.  NB this is just evaluated at the
+    # time that the DuringRunner is set up with.
     #
     # @param [String] people_list People list to query
     # @return [Boolean]
     #
     def no_one_in(people_list)
       return true unless Configuration.current.people[people_list].respond_to?(:people)
+      
+      #
+      # Cache the results to prevent hitting the calendar too many times.
+      #
+      @no_one_in_cache ||= Hash.new
 
-      @test_time = @time if @test_time.nil?
-      return Configuration.current.people[people_list].people(@test_time).empty?
+      return @no_one_in_cache[people_list] if @no_one_in_cache.has_key?(people_list)
+
+      @no_one_in_cache[people_list] = Configuration.current.people[people_list].people(@time).empty?
     end
 
     # Returns true if the current hour is in the list of hours given.
@@ -347,6 +354,4 @@ module Mauve
 
   end
 
-  class NotificationDummy < Struct.new(:during, :every) ; end
-
 end
-- 
cgit v1.2.3