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
......
...@@ -708,10 +708,10 @@ ...@@ -708,10 +708,10 @@
} }
if (state === _converse.COMPOSING) { if (state === _converse.COMPOSING) {
this.chat_state_timeout = window.setTimeout( 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) { } else if (state === _converse.PAUSED) {
this.chat_state_timeout = window.setTimeout( 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) { if (!no_save && this.model.get('chat_state') !== state) {
this.model.set('chat_state', state); this.model.set('chat_state', state);
......
...@@ -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();
_converse.api.waitUntil('rosterViewInitialized') if (this.model.get('connected')) {
.then(this.insertRoster.bind(this)) _converse.api.waitUntil('rosterViewInitialized')
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); .then(this.insertRoster.bind(this))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
}, },
render () { render () {
......
...@@ -242,29 +242,31 @@ ...@@ -242,29 +242,31 @@
// 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(() => {
minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0, const $minimized = _.get(_converse.minimized_chats, '$el'),
new_id = newchat ? newchat.model.get('id') : null; 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), const boxes_width = _.reduce(
(memo, view) => memo + this.getChatBoxWidth(view), this.xget(new_id),
newchat ? newchat.$el.outerWidth(true) : 0); (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 ((minimized_width + boxes_width) > $('body').outerWidth(true)) {
if (oldest_chat) { const oldest_chat = this.getOldestMaximizedChat([new_id]);
// We hide the chat immediately, because waiting if (oldest_chat) {
// for the event to fire (and letting the // We hide the chat immediately, because waiting
// ChatBoxView hide it then) causes race // for the event to fire (and letting the
// conditions. // ChatBoxView hide it then) causes race
const view = this.get(oldest_chat.get('id')); // conditions.
if (view) { const view = this.get(oldest_chat.get('id'));
view.hide(); if (view) {
view.hide();
}
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,28 +131,32 @@ ...@@ -131,28 +131,32 @@
}); });
const updateVCardForChatBox = function (chatbox) { const updateVCardForChatBox = function (chatbox) {
if (!_converse.use_vcards) { return; } if (!_converse.use_vcards || chatbox.model.get('type') === 'headline') {
const jid = chatbox.model.get('jid'), return;
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
);
}
);
} }
_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); _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