Commit 86f3399d authored by JC Brand's avatar JC Brand

Also trigger 'chatboxFocused' when user manually focuses

parent dd082107
...@@ -123,7 +123,6 @@ ...@@ -123,7 +123,6 @@
// Check that new chat boxes are created to the left of the // Check that new chat boxes are created to the left of the
// controlbox (but to the right of all existing chat boxes) // controlbox (but to the right of all existing chat boxes)
expect(document.querySelectorAll("#conversejs .chatbox").length).toBe(2); expect(document.querySelectorAll("#conversejs .chatbox").length).toBe(2);
expect(document.querySelectorAll("#conversejs .chatbox")[1].id).toBe(chatboxview.model.get('box_id'));
online_contacts[1].click(); online_contacts[1].click();
await test_utils.waitUntil(() => _converse.chatboxes.length == 3); await test_utils.waitUntil(() => _converse.chatboxes.length == 3);
el = online_contacts[1]; el = online_contacts[1];
...@@ -133,8 +132,6 @@ ...@@ -133,8 +132,6 @@
// Check that new chat boxes are created to the left of the // Check that new chat boxes are created to the left of the
// controlbox (but to the right of all existing chat boxes) // controlbox (but to the right of all existing chat boxes)
expect(document.querySelectorAll("#conversejs .chatbox").length).toBe(3); expect(document.querySelectorAll("#conversejs .chatbox").length).toBe(3);
expect(document.querySelectorAll("#conversejs .chatbox")[2].id).toBe(chatboxview.model.get('box_id'));
expect(document.querySelectorAll("#conversejs .chatbox")[1].id).toBe(new_chatboxview.model.get('box_id'));
done(); done();
})); }));
......
...@@ -366,13 +366,12 @@ converse.plugins.add('converse-chatview', { ...@@ -366,13 +366,12 @@ converse.plugins.add('converse-chatview', {
}, },
render () { render () {
// XXX: Is this still needed?
this.el.setAttribute('id', this.model.get('box_id'));
this.el.innerHTML = tpl_chatbox( this.el.innerHTML = tpl_chatbox(
Object.assign(this.model.toJSON(), { Object.assign(
'unread_msgs': __('You have unread messages') this.model.toJSON(),
} {'unread_msgs': __('You have unread messages')}
)); )
);
this.content = this.el.querySelector('.chat-content'); this.content = this.el.querySelector('.chat-content');
this.renderMessageForm(); this.renderMessageForm();
this.insertHeading(); this.insertHeading();
...@@ -402,17 +401,11 @@ converse.plugins.add('converse-chatview', { ...@@ -402,17 +401,11 @@ converse.plugins.add('converse-chatview', {
}, },
renderMessageForm () { renderMessageForm () {
let placeholder;
if (this.model.get('composing_spoiler')) {
placeholder = __('Hidden message');
} else {
placeholder = __('Message');
}
const form_container = this.el.querySelector('.bottom-panel'); const form_container = this.el.querySelector('.bottom-panel');
form_container.innerHTML = tpl_chatbox_message_form( form_container.innerHTML = tpl_chatbox_message_form(
Object.assign(this.model.toJSON(), { Object.assign(this.model.toJSON(), {
'hint_value': _.get(this.el.querySelector('.spoiler-hint'), 'value'), 'hint_value': _.get(this.el.querySelector('.spoiler-hint'), 'value'),
'label_message': placeholder, 'label_message': this.model.get('composing_spoiler') ? __('Hidden message') : __('Message'),
'label_send': __('Send'), 'label_send': __('Send'),
'label_spoiler_hint': __('Optional hint'), 'label_spoiler_hint': __('Optional hint'),
'message_value': _.get(this.el.querySelector('.chat-textarea'), 'value'), 'message_value': _.get(this.el.querySelector('.chat-textarea'), 'value'),
...@@ -420,6 +413,8 @@ converse.plugins.add('converse-chatview', { ...@@ -420,6 +413,8 @@ converse.plugins.add('converse-chatview', {
'show_toolbar': _converse.show_toolbar, 'show_toolbar': _converse.show_toolbar,
'unread_msgs': __('You have unread messages') 'unread_msgs': __('You have unread messages')
})); }));
const textarea_el = this.el.querySelector('.chat-textarea');
textarea_el.addEventListener('focus', () => this.emitFocused());
this.renderToolbar(); this.renderToolbar();
}, },
...@@ -1256,17 +1251,21 @@ converse.plugins.add('converse-chatview', { ...@@ -1256,17 +1251,21 @@ converse.plugins.add('converse-chatview', {
} }
}, },
emitFocused: _.debounce(() => {
/**
* Triggered when the focus has been moved to a particular chat.
* @event _converse#chatBoxFocused
* @type { _converse.ChatBoxView | _converse.ChatRoomView }
* @example _converse.api.listen.on('chatBoxFocused', view => { ... });
*/
_converse.api.trigger('chatBoxFocused', this);
}, 25, {'leading': true}),
focus () { focus () {
const textarea_el = this.el.querySelector('.chat-textarea'); const textarea_el = this.el.querySelector('.chat-textarea');
if (!_.isNull(textarea_el)) { if (!_.isNull(textarea_el)) {
textarea_el.focus(); textarea_el.focus();
/** this.emitFocused();
* Triggered when the focus has been moved to a particular chat.
* @event _converse#chatBoxFocused
* @type { _converse.ChatBoxView | _converse.ChatRoomView }
* @example _converse.api.listen.on('chatBoxFocused', view => { ... });
*/
_converse.api.trigger('chatBoxFocused', this);
} }
return this; return this;
}, },
......
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