Commit 3b8c2d1b authored by JC Brand's avatar JC Brand

Various bug and timing fixes due to the previous refactoring

parent 694eabfc
...@@ -1755,31 +1755,42 @@ ...@@ -1755,31 +1755,42 @@
test_utils.openContactsPanel(_converse); test_utils.openContactsPanel(_converse);
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return _converse.rosterview.$el.find('dt').length; return _converse.rosterview.$el.find('dt').length;
}, 300).then(function () { }, 500).then(function () {
// Make the timeouts shorter so that we can test // Make the timeouts shorter so that we can test
_converse.TIMEOUTS.PAUSED = 200; _converse.TIMEOUTS.PAUSED = 200;
_converse.TIMEOUTS.INACTIVE = 200; _converse.TIMEOUTS.INACTIVE = 200;
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid); test_utils.openChatBoxFor(_converse, contact_jid);
view = _converse.chatboxviews.get(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'); expect(view.model.get('chat_state')).toBe('active');
view.keyPressed({ view.keyPressed({
target: view.$el.find('textarea.chat-textarea'), target: view.$el.find('textarea.chat-textarea'),
keyCode: 1 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'); expect(view.model.get('chat_state')).toBe('composing');
spyOn(_converse.connection, 'send'); spyOn(_converse.connection, 'send');
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
if (view.model.get('chat_state') === 'paused') { return view.model.get('chat_state') === 'paused';
return true; }, 500);
}
return false;
}, 300);
}).then(function () { }).then(function () {
console.log('chat_state set to paused');
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'inactive'; return view.model.get('chat_state') === 'inactive';
}, 300); }, 500);
}).then(function () { }).then(function () {
console.log('chat_state set to inactive');
expect(_converse.connection.send).toHaveBeenCalled(); expect(_converse.connection.send).toHaveBeenCalled();
var calls = _.filter(_converse.connection.send.calls.all(), function (call) { var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
return call.args[0] instanceof Strophe.Builder; return call.args[0] instanceof Strophe.Builder;
...@@ -1799,7 +1810,7 @@ ...@@ -1799,7 +1810,7 @@
expect($stanza.children().get(1).tagName).toBe('no-store'); expect($stanza.children().get(1).tagName).toBe('no-store');
expect($stanza.children().get(2).tagName).toBe('no-permanent-store'); expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
done(); done();
}); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
})); }));
it("is sent when the user a minimizes a chat box", it("is sent when the user a minimizes a chat box",
......
...@@ -325,8 +325,8 @@ ...@@ -325,8 +325,8 @@
}); });
_converse.api.listen.on('beforeTearDown', () => { _converse.api.listen.on('beforeTearDown', () => {
this.chatboxes.remove(); // Don't call off(), events won't get re-registered upon reconnect. _converse.chatboxes.remove(); // Don't call off(), events won't get re-registered upon reconnect.
delete this.chatboxes.browserStorage; delete _converse.chatboxes.browserStorage;
}); });
// END: Event handlers // END: Event handlers
......
...@@ -93,8 +93,9 @@ ...@@ -93,8 +93,9 @@
this.__super__.onChatBoxesFetched.apply(this, arguments); this.__super__.onChatBoxesFetched.apply(this, arguments);
const { _converse } = this.__super__; const { _converse } = this.__super__;
if (!_.includes(_.map(collection, 'id'), 'controlbox')) { if (!_.includes(_.map(collection, 'id'), 'controlbox')) {
_converse.addControlBox({'connected': true}); _converse.addControlBox();
} }
this.get('controlbox').save({connected:true});
}, },
}, },
...@@ -184,13 +185,13 @@ ...@@ -184,13 +185,13 @@
const LABEL_CONTACTS = __('Contacts'); const LABEL_CONTACTS = __('Contacts');
_converse.addControlBox = (settings) => { _converse.addControlBox = () => {
_converse.chatboxes.add(_.assign({ _converse.chatboxes.add({
id: 'controlbox', id: 'controlbox',
box_id: 'controlbox', box_id: 'controlbox',
type: 'controlbox', type: 'controlbox',
closed: !_converse.show_controlbox_by_default closed: !_converse.show_controlbox_by_default
}, settings)) })
}; };
_converse.ControlBoxView = _converse.ChatBoxView.extend({ _converse.ControlBoxView = _converse.ChatBoxView.extend({
...@@ -211,9 +212,11 @@ ...@@ -211,9 +212,11 @@
this.model.on('show', this.show, this); this.model.on('show', this.show, this);
this.model.on('change:closed', this.ensureClosedState, this); this.model.on('change:closed', this.ensureClosedState, this);
this.render(); this.render();
if (this.model.get('connected')) {
_converse.api.waitUntil('rosterViewInitialized') _converse.api.waitUntil('rosterViewInitialized')
.then(this.insertRoster.bind(this)) .then(this.insertRoster.bind(this))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); .catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
}, },
render () { render () {
......
...@@ -242,7 +242,8 @@ ...@@ -242,7 +242,8 @@
// fullscreen. In this case we don't trim. // fullscreen. In this case we don't trim.
return; return;
} }
const $minimized = _converse.minimized_chats.$el, _converse.api.waitUntil('chatBoxesInitialized').then(() => {
const $minimized = _.get(_converse.minimized_chats, '$el'),
minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0, minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
new_id = newchat ? newchat.model.get('id') : null; new_id = newchat ? newchat.model.get('id') : null;
...@@ -265,6 +266,7 @@ ...@@ -265,6 +266,7 @@
oldest_chat.minimize(); oldest_chat.minimize();
} }
} }
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}, },
getOldestMaximizedChat (exclude_ids) { getOldestMaximizedChat (exclude_ids) {
...@@ -303,6 +305,8 @@ ...@@ -303,6 +305,8 @@
no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width) 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({ _converse.MinimizedChatBoxView = Backbone.View.extend({
tagName: 'div', tagName: 'div',
className: 'chat-head', className: 'chat-head',
...@@ -490,6 +494,7 @@ ...@@ -490,6 +494,7 @@
_converse.minimized_chats = new _converse.MinimizedChats({ _converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes model: _converse.chatboxes
}); });
_converse.emit('minimizedChatsInitialized');
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
_converse.on('chatBoxOpened', function renderMinimizeButton (view) { _converse.on('chatBoxOpened', function renderMinimizeButton (view) {
......
...@@ -131,7 +131,10 @@ ...@@ -131,7 +131,10 @@
}); });
const updateVCardForChatBox = function (chatbox) { const updateVCardForChatBox = function (chatbox) {
if (!_converse.use_vcards) { return; } if (!_converse.use_vcards || chatbox.model.get('type') === 'headline') {
return;
}
_converse.api.waitUntil('rosterInitialized').then(() => {
const jid = chatbox.model.get('jid'), const jid = chatbox.model.get('jid'),
contact = _converse.roster.get(jid); contact = _converse.roster.get(jid);
if ((contact) && (!contact.get('vcard_updated'))) { if ((contact) && (!contact.get('vcard_updated'))) {
...@@ -153,6 +156,7 @@ ...@@ -153,6 +156,7 @@
} }
); );
} }
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}; };
_converse.on('chatBoxInitialized', updateVCardForChatBox); _converse.on('chatBoxInitialized', updateVCardForChatBox);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment