<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -226,11 +226,22 @@ module Jabber
     #
     # e.g.:
     #
-    #   jabber.presence_updates do |friend, old_presence, new_presence|
-    #     puts &quot;Received presence update from #{friend.to_s}: #{new_presence}&quot;
+    #   jabber.presence_updates do |friend, new_presence|
+    #     puts &quot;Received presence update from #{friend}: #{new_presence}&quot;
     #   end
     def presence_updates(&amp;block)
-      dequeue(:presence_updates, &amp;block)
+      updates = []
+      @presence_mutex.synchronize do
+        dequeue(:presence_updates) do |friend|
+          presence = @presence_updates[friend]
+          next unless presence
+          new_update = [friend, presence[0], presence[1]]
+          yield new_update if block_given?
+          updates &lt;&lt; new_update
+          @presence_updates.delete(friend)
+        end
+      end
+      return updates
     end
     
     # Returns true if there are unprocessed presence updates waiting in the
@@ -384,8 +395,21 @@ module Jabber
         end
       end
 
+      @presence_updates = {}
+      @presence_mutex = Mutex.new
       roster.add_presence_callback do |roster_item, old_presence, new_presence|
-        queue(:presence_updates) &lt;&lt; [roster_item, old_presence, new_presence]
+        simple_jid = roster_item.jid.strip.to_s
+        presence = case new_presence.type
+                   when nil: new_presence.show || :online
+                   when :unavailable: :unavailable
+                   else
+                     nil
+                   end
+
+        if presence &amp;&amp; @presence_updates[simple_jid] != presence
+          queue(:presence_updates) &lt;&lt; simple_jid
+          @presence_mutex.synchronize { @presence_updates[simple_jid] = [presence, new_presence.status] }
+        end
       end
     end
 </diff>
      <filename>lib/xmpp4r-simple.rb</filename>
    </modified>
    <modified>
      <diff>@@ -145,6 +145,7 @@ class JabberSimpleTest &lt; Test::Unit::TestCase
   def test_presence_updates_should_be_received
 
     @client2.add(@client1)
+    @client1.add(@client2)
 
     assert_before(60) { assert @client2.subscribed_to?(@jid1) }
     assert_before(60) { assert_equal 0, @client2.presence_updates.size }
@@ -158,9 +159,9 @@ class JabberSimpleTest &lt; Test::Unit::TestCase
     end
 
     new_status = new_statuses.first
-    assert_equal @jid1, new_status[0].jid.strip.to_s
-    assert_equal &quot;Doing something else.&quot;, new_status[2].status
-    assert_equal :away, new_status[2].show
+    assert_equal @jid1, new_status[0]
+    assert_equal &quot;Doing something else.&quot;, new_status[2]
+    assert_equal :away, new_status[1]
   end
 
   def test_disable_auto_accept_subscription_requests</diff>
      <filename>test/test_xmpp4r_simple.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>06d0da57cc18366e718bdebe38b87e3e1a05738d</id>
    </parent>
  </parents>
  <author>
    <name>romeda</name>
    <email>romeda@1e3c5029-9921-0410-9e82-436f4d538387</email>
  </author>
  <url>http://github.com/timshadel/xmpp4r-simple/commit/f5a898395be2006313e096fc3e846b78606a1d06</url>
  <id>f5a898395be2006313e096fc3e846b78606a1d06</id>
  <committed-date>2006-12-07T12:44:21-08:00</committed-date>
  <authored-date>2006-12-07T12:44:21-08:00</authored-date>
  <message>tests are finnicky, but this [hopefully] greatly reduces memory usage and improves status update performance.

git-svn-id: https://xmpp4r-simple.googlecode.com/svn/trunk@20 1e3c5029-9921-0410-9e82-436f4d538387</message>
  <tree>93d5dc34ae0cb4b2972ed0dc1e5e85553a07161c</tree>
  <committer>
    <name>romeda</name>
    <email>romeda@1e3c5029-9921-0410-9e82-436f4d538387</email>
  </committer>
</commit>
