فهرست منبع

Make sure presence stanza is sent out after roster update

specifically also when localstorage is populated
JC Brand 11 سال پیش
والد
کامیت
d53caf115a
2فایلهای تغییر یافته به همراه13 افزوده شده و 13 حذف شده
  1. 1 1
      CHANGES.rst
  2. 12 12
      converse.js

+ 1 - 1
CHANGES.rst

@@ -4,7 +4,7 @@ Changelog
 0.6.6 (2013-10-08)
 ------------------
 
-* Bugfix: Presence stanza sent out before roster has been initialized [jcbrand]
+* Bugfix: Presence stanza must be sent out only after roster has been initialized [jcbrand]
 
 0.6.5 (2013-10-08)
 ------------------

+ 12 - 12
converse.js

@@ -127,6 +127,7 @@
         // Module-level variables
         // ----------------------
         this.callback = callback || function () {};
+        this.initial_presence_sent = 0;
         this.msg_counter = 0;
 
         // Module-level functions
@@ -2190,17 +2191,6 @@
             },
 
             rosterHandler: function (items) {
-                if ((items.length === 0) || (items.length === _.where(items, {subscription:'none'}).length)) {
-                    // The presence stanza is sent out once all
-                    // roster contacts have been added and rendered.
-                    // See RosterView's render method.
-                    //
-                    // If there aren't any roster contacts, we still
-                    // want to send a presence stanza, so we do it here.
-                    converse.xmppstatus.sendPresence();
-                    return true;
-                }
-
                 this.cleanCache(items);
                 _.each(items, function (item, index, items) {
                     if (this.isSelf(item.jid)) { return; }
@@ -2227,6 +2217,17 @@
                         }
                     }
                 }, this);
+
+                if (!converse.initial_presence_sent) {
+                    /* Once we've sent out our initial presence stanza, we'll
+                     * start receiving presence stanzas from our contacts.
+                     * We therefore only want to do this after our roster has
+                     * been set up (otherwise we can't meaningfully process
+                     * incoming presence stanzas).
+                     */
+                    converse.initial_presence_sent = 1;
+                    converse.xmppstatus.sendPresence();
+                }
             },
 
             handleIncomingSubscription: function (jid) {
@@ -2454,7 +2455,6 @@
                             // can show the roster.
                             this.$el.show();
                         }
-                        converse.xmppstatus.sendPresence();
                     }
                 }
                 // Hide the headings if there are no contacts under them