소스 검색

roster: Move roster push and rosterX handlers to core.

There's nothing about them that's view specific.
JC Brand 8 년 전
부모
커밋
f09d01c930
3개의 변경된 파일40개의 추가작업 그리고 36개의 파일을 삭제
  1. 0 1
      src/converse-controlbox.js
  2. 40 0
      src/converse-core.js
  3. 0 35
      src/converse-rosterview.js

+ 0 - 1
src/converse-controlbox.js

@@ -79,7 +79,6 @@
             _tearDown: function () {
                 this.__super__._tearDown.apply(this, arguments);
                 if (this.rosterview) {
-                    this.rosterview.unregisterHandlers();
                     // Removes roster groups
                     this.rosterview.model.off().reset();
                     this.rosterview.each(function (groupview) {

+ 40 - 0
src/converse-core.js

@@ -727,6 +727,7 @@
             }
             // First set up chat boxes, before populating the roster, so that
             // the controlbox is properly set up and ready for the rosterview.
+            _converse.roster.onConnected();
             _converse.chatboxes.onConnected();
             _converse.populateRoster();
             _converse.registerPresenceHandler();
@@ -976,6 +977,45 @@
                 }
             },
 
+            onConnected: function () {
+                /* Called as soon as the connection has been established
+                 * (either after initial login, or after reconnection).
+                 *
+                 * Use the opportunity to register stanza handlers.
+                 */
+                this.registerRosterHandler();
+                this.registerRosterXHandler();
+            },
+
+            registerRosterHandler: function () {
+                /* Register a handler for roster IQ "set" stanzas, which update
+                 * roster contacts.
+                 */
+                _converse.connection.addHandler(
+                    _converse.roster.onRosterPush.bind(_converse.roster),
+                    Strophe.NS.ROSTER, 'iq', "set"
+                );
+            },
+
+            registerRosterXHandler: function () {
+                /* Register a handler for RosterX message stanzas, which are
+                 * used to suggest roster contacts to a user.
+                 */
+                var t = 0;
+                _converse.connection.addHandler(
+                    function (msg) {
+                        window.setTimeout(
+                            function () {
+                                _converse.connection.flush();
+                                _converse.roster.subscribeToSuggestedItems.bind(_converse.roster)(msg);
+                            }, t);
+                        t += $(msg).find('item').length*250;
+                        return true;
+                    },
+                    Strophe.NS.ROSTERX, 'message', null
+                );
+            },
+
             fetchRosterContacts: function () {
                 /* Fetches the roster contacts, first by trying the
                  * sessionStorage cache, and if that's empty, then by querying

+ 0 - 35
src/converse-rosterview.js

@@ -43,7 +43,6 @@
             //
             // New functions which don't exist yet can also be added.
             afterReconnected: function () {
-                this.rosterview.registerRosterXHandler();
                 this.__super__.afterReconnected.apply(this, arguments);
             },
 
@@ -271,8 +270,6 @@
                 id: 'converse-roster',
 
                 initialize: function () {
-                    this.roster_handler_ref = this.registerRosterHandler();
-                    this.rosterx_handler_ref = this.registerRosterXHandler();
                     _converse.roster.on("add", this.onContactAdd, this);
                     _converse.roster.on('change', this.onContactChange, this);
                     _converse.roster.on("destroy", this.update, this);
@@ -326,13 +323,6 @@
                     }
                 }, 100),
 
-                unregisterHandlers: function () {
-                    _converse.connection.deleteHandler(this.roster_handler_ref);
-                    delete this.roster_handler_ref;
-                    _converse.connection.deleteHandler(this.rosterx_handler_ref);
-                    delete this.rosterx_handler_ref;
-                },
-
                 update: _.debounce(function () {
                     if (_.isNull(this.roster.parentElement)) {
                         this.$el.append(this.$roster.show());
@@ -385,31 +375,6 @@
                     return this;
                 },
 
-                registerRosterHandler: function () {
-                    _converse.connection.addHandler(
-                        _converse.roster.onRosterPush.bind(_converse.roster),
-                        Strophe.NS.ROSTER, 'iq', "set"
-                    );
-                },
-
-                registerRosterXHandler: function () {
-                    var t = 0;
-                    _converse.connection.addHandler(
-                        function (msg) {
-                            window.setTimeout(
-                                function () {
-                                    _converse.connection.flush();
-                                    _converse.roster.subscribeToSuggestedItems.bind(_converse.roster)(msg);
-                                },
-                                t
-                            );
-                            t += $(msg).find('item').length*250;
-                            return true;
-                        },
-                        Strophe.NS.ROSTERX, 'message', null
-                    );
-                },
-
                 onGroupAdd: function (group) {
                     var view = new _converse.RosterGroupView({model: group});
                     this.add(group.get('name'), view.render());