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 @@
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",
......
......@@ -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
......
......@@ -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();
if (this.model.get('connected')) {
_converse.api.waitUntil('rosterViewInitialized')
.then(this.insertRoster.bind(this))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
},
render () {
......
......@@ -242,7 +242,8 @@
// fullscreen. In this case we don't trim.
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,
new_id = newchat ? newchat.model.get('id') : null;
......@@ -265,6 +266,7 @@
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) {
......
......@@ -131,7 +131,10 @@
});
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'),
contact = _converse.roster.get(jid);
if ((contact) && (!contact.get('vcard_updated'))) {
......@@ -153,6 +156,7 @@
}
);
}
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
};
_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