Przeglądaj źródła

Changed the following:
- Pass an option object to addRosterItem which can contains information about
the object catched in the rosterHandler.
In this case I am marking the last item available in the roster of the
person for which this handler is triggered

ichim-david 12 lat temu
rodzic
commit
66d7b51535
1 zmienionych plików z 10 dodań i 4 usunięć
  1. 10 4
      converse.js

+ 10 - 4
converse.js

@@ -1349,8 +1349,9 @@
             return Backbone.Collection.prototype.get.call(this, id);
             return Backbone.Collection.prototype.get.call(this, id);
         },
         },
 
 
-        addRosterItem: function (jid, subscription, ask, name) {
+        addRosterItem: function (jid, subscription, ask, name, options) {
             var model = new xmppchat.RosterItem(jid, subscription, ask, name);
             var model = new xmppchat.RosterItem(jid, subscription, ask, name);
+            model.options = options || {};
             this.add(model);
             this.add(model);
         },
         },
             
             
@@ -1412,12 +1413,17 @@
         },
         },
 
 
         rosterHandler: function (items) {
         rosterHandler: function (items) {
-            var model, item;
-            for (var i=0; i<items.length; i++) {
+            var model, item, i, items_length = items.length,
+                last_item = items[items_length - 1],
+                options = {};
+            for (i=0; i<items_length; i+=1) {
                 item = items[i];
                 item = items[i];
                 model = this.getItem(item.jid);
                 model = this.getItem(item.jid);
                 if (!model) {
                 if (!model) {
-                    this.addRosterItem(item.jid, item.subscription, item.ask, item.name);
+                    if (item === last_item) {
+                        options.isLast = true;
+                    }
+                    this.addRosterItem(item.jid, item.subscription, item.ask, item.name, options);
                 } else {
                 } else {
                     // only modify model attributes if they are different from the
                     // only modify model attributes if they are different from the
                     // ones that were already set when the rosterItem was added
                     // ones that were already set when the rosterItem was added