فهرست منبع

Various bug and timing fixes due to the previous refactoring

JC Brand 8 سال پیش
والد
کامیت
3b8c2d1b00
6فایلهای تغییر یافته به همراه84 افزوده شده و 61 حذف شده
  1. 19 8
      spec/chatbox.js
  2. 2 2
      src/converse-chatboxes.js
  3. 2 2
      src/converse-chatview.js
  4. 10 7
      src/converse-controlbox.js
  5. 26 21
      src/converse-minimize.js
  6. 25 21
      src/converse-vcard.js

+ 19 - 8
spec/chatbox.js

@@ -1755,31 +1755,42 @@
                         test_utils.openContactsPanel(_converse);
                         test_utils.waitUntil(function () {
                             return _converse.rosterview.$el.find('dt').length;
-                        }, 300).then(function () {
+                        }, 500).then(function () {
                             // Make the timeouts shorter so that we can test
                             _converse.TIMEOUTS.PAUSED = 200;
                             _converse.TIMEOUTS.INACTIVE = 200;
                             contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
                             test_utils.openChatBoxFor(_converse, contact_jid);
                             view = _converse.chatboxviews.get(contact_jid);
+                            return test_utils.waitUntil(function () {
+                                return view.model.get('chat_state') === 'active';
+                            }, 500);
+                        }).then(function () {
+                            console.log('chat_state set to active');
+                            view = _converse.chatboxviews.get(contact_jid);
                             expect(view.model.get('chat_state')).toBe('active');
                             view.keyPressed({
                                 target: view.$el.find('textarea.chat-textarea'),
                                 keyCode: 1
                             });
+                            return test_utils.waitUntil(function () {
+                                return view.model.get('chat_state') === 'composing';
+                            }, 500);
+                        }).then(function () {
+                            console.log('chat_state set to composing');
+                            view = _converse.chatboxviews.get(contact_jid);
                             expect(view.model.get('chat_state')).toBe('composing');
                             spyOn(_converse.connection, 'send');
                             return test_utils.waitUntil(function () {
-                                if (view.model.get('chat_state') === 'paused') {
-                                    return true;
-                                }
-                                return false;
-                            }, 300);
+                                return view.model.get('chat_state') === 'paused';
+                            }, 500);
                         }).then(function () {
+                            console.log('chat_state set to paused');
                             return test_utils.waitUntil(function () {
                                 return view.model.get('chat_state') === 'inactive';
-                            }, 300);
+                            }, 500);
                         }).then(function () {
+                            console.log('chat_state set to inactive');
                             expect(_converse.connection.send).toHaveBeenCalled();
                             var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
                                 return call.args[0] instanceof Strophe.Builder;
@@ -1799,7 +1810,7 @@
                             expect($stanza.children().get(1).tagName).toBe('no-store');
                             expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
                             done();
-                        });
+                        }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
                     }));
 
                     it("is sent when the user a minimizes a chat box",

+ 2 - 2
src/converse-chatboxes.js

@@ -325,8 +325,8 @@
             });
 
             _converse.api.listen.on('beforeTearDown', () => {
-                this.chatboxes.remove(); // Don't call off(), events won't get re-registered upon reconnect.
-                delete this.chatboxes.browserStorage;
+                _converse.chatboxes.remove(); // Don't call off(), events won't get re-registered upon reconnect.
+                delete _converse.chatboxes.browserStorage;
             });
             // END: Event handlers
 

+ 2 - 2
src/converse-chatview.js

@@ -708,10 +708,10 @@
                     }
                     if (state === _converse.COMPOSING) {
                         this.chat_state_timeout = window.setTimeout(
-                                this.setChatState.bind(this), _converse.TIMEOUTS.PAUSED, _converse.PAUSED);
+                            this.setChatState.bind(this), _converse.TIMEOUTS.PAUSED, _converse.PAUSED);
                     } else if (state === _converse.PAUSED) {
                         this.chat_state_timeout = window.setTimeout(
-                                this.setChatState.bind(this), _converse.TIMEOUTS.INACTIVE, _converse.INACTIVE);
+                            this.setChatState.bind(this), _converse.TIMEOUTS.INACTIVE, _converse.INACTIVE);
                     }
                     if (!no_save && this.model.get('chat_state') !== state) {
                         this.model.set('chat_state', state);

+ 10 - 7
src/converse-controlbox.js

@@ -93,8 +93,9 @@
                     this.__super__.onChatBoxesFetched.apply(this, arguments);
                     const { _converse } = this.__super__;
                     if (!_.includes(_.map(collection, 'id'), 'controlbox')) {
-                        _converse.addControlBox({'connected': true});
+                        _converse.addControlBox();
                     }
+                    this.get('controlbox').save({connected:true});
                 },
             },
 
@@ -184,13 +185,13 @@
 
             const LABEL_CONTACTS = __('Contacts');
 
-            _converse.addControlBox = (settings) => {
-                _converse.chatboxes.add(_.assign({
+            _converse.addControlBox = () => {
+                _converse.chatboxes.add({
                     id: 'controlbox',
                     box_id: 'controlbox',
                     type: 'controlbox',
                     closed: !_converse.show_controlbox_by_default
-                }, settings))
+                })
             };
 
             _converse.ControlBoxView = _converse.ChatBoxView.extend({
@@ -211,9 +212,11 @@
                     this.model.on('show', this.show, this);
                     this.model.on('change:closed', this.ensureClosedState, this);
                     this.render();
-                    _converse.api.waitUntil('rosterViewInitialized')
-                        .then(this.insertRoster.bind(this))
-                        .catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
+                    if (this.model.get('connected')) {
+                        _converse.api.waitUntil('rosterViewInitialized')
+                            .then(this.insertRoster.bind(this))
+                            .catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
+                    }
                 },
 
                 render () {

+ 26 - 21
src/converse-minimize.js

@@ -242,29 +242,31 @@
                         // fullscreen. In this case we don't trim.
                         return;
                     }
-                    const $minimized = _converse.minimized_chats.$el,
-                        minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
-                        new_id = newchat ? newchat.model.get('id') : null;
-
-                    const boxes_width = _.reduce(
-                        this.xget(new_id),
-                        (memo, view) => memo + this.getChatBoxWidth(view),
-                        newchat ? newchat.$el.outerWidth(true) : 0);
-
-                    if ((minimized_width + boxes_width) > $('body').outerWidth(true)) {
-                        const oldest_chat = this.getOldestMaximizedChat([new_id]);
-                        if (oldest_chat) {
-                            // We hide the chat immediately, because waiting
-                            // for the event to fire (and letting the
-                            // ChatBoxView hide it then) causes race
-                            // conditions.
-                            const view = this.get(oldest_chat.get('id'));
-                            if (view) {
-                                view.hide();
+                    _converse.api.waitUntil('chatBoxesInitialized').then(() => {
+                        const $minimized = _.get(_converse.minimized_chats, '$el'),
+                            minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
+                            new_id = newchat ? newchat.model.get('id') : null;
+
+                        const boxes_width = _.reduce(
+                            this.xget(new_id),
+                            (memo, view) => memo + this.getChatBoxWidth(view),
+                            newchat ? newchat.$el.outerWidth(true) : 0);
+
+                        if ((minimized_width + boxes_width) > $('body').outerWidth(true)) {
+                            const oldest_chat = this.getOldestMaximizedChat([new_id]);
+                            if (oldest_chat) {
+                                // We hide the chat immediately, because waiting
+                                // for the event to fire (and letting the
+                                // ChatBoxView hide it then) causes race
+                                // conditions.
+                                const view = this.get(oldest_chat.get('id'));
+                                if (view) {
+                                    view.hide();
+                                }
+                                oldest_chat.minimize();
                             }
-                            oldest_chat.minimize();
                         }
-                    }
+                    }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
                 },
 
                 getOldestMaximizedChat (exclude_ids) {
@@ -303,6 +305,8 @@
                 no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width)
             });
 
+            _converse.api.promises.add('minimizedChatsInitialized');
+
             _converse.MinimizedChatBoxView = Backbone.View.extend({
                 tagName: 'div',
                 className: 'chat-head',
@@ -490,6 +494,7 @@
                 _converse.minimized_chats = new _converse.MinimizedChats({
                     model: _converse.chatboxes
                 });
+                _converse.emit('minimizedChatsInitialized');
             }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
 
             _converse.on('chatBoxOpened', function renderMinimizeButton (view) {

+ 25 - 21
src/converse-vcard.js

@@ -131,28 +131,32 @@
             });
 
             const updateVCardForChatBox = function (chatbox) {
-                if (!_converse.use_vcards) { return; }
-                const jid = chatbox.model.get('jid'),
-                    contact = _converse.roster.get(jid);
-                if ((contact) && (!contact.get('vcard_updated'))) {
-                    _converse.getVCard(
-                        jid,
-                        function (iq, jid, fullname, image, image_type, url) {
-                            chatbox.model.save({
-                                'fullname' : fullname || jid,
-                                'url': url,
-                                'image_type': image_type,
-                                'image': image
-                            });
-                        },
-                        function () {
-                            _converse.log(
-                                "updateVCardForChatBox: Error occured while fetching vcard",
-                                Strophe.LogLevel.ERROR
-                            );
-                        }
-                    );
+                if (!_converse.use_vcards || chatbox.model.get('type') === 'headline') {
+                    return;
                 }
+                _converse.api.waitUntil('rosterInitialized').then(() => {
+                    const jid = chatbox.model.get('jid'),
+                        contact = _converse.roster.get(jid);
+                    if ((contact) && (!contact.get('vcard_updated'))) {
+                        _converse.getVCard(
+                            jid,
+                            function (iq, jid, fullname, image, image_type, url) {
+                                chatbox.model.save({
+                                    'fullname' : fullname || jid,
+                                    'url': url,
+                                    'image_type': image_type,
+                                    'image': image
+                                });
+                            },
+                            function () {
+                                _converse.log(
+                                    "updateVCardForChatBox: Error occured while fetching vcard",
+                                    Strophe.LogLevel.ERROR
+                                );
+                            }
+                        );
+                    }
+                }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
             };
             _converse.on('chatBoxInitialized', updateVCardForChatBox);