MUC: don't send out chat hints before join or after leave

This commit is contained in:
JC Brand 2017-02-17 22:17:19 +01:00
parent f83043e5ab
commit fe6cb93a63

View File

@ -344,6 +344,7 @@
this.model.messages.on('add', this.onMessageAdded, this); this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('show', this.show, this); this.model.on('show', this.show, this);
this.model.on('destroy', this.hide, this); this.model.on('destroy', this.hide, this);
this.model.on('change:connection_status', this.afterConnected, this);
this.model.on('change:chat_state', this.sendChatState, this); this.model.on('change:chat_state', this.sendChatState, this);
this.model.on('change:affiliation', this.renderHeading, this); this.model.on('change:affiliation', this.renderHeading, this);
this.model.on('change:name', this.renderHeading, this); this.model.on('change:name', this.renderHeading, this);
@ -397,8 +398,7 @@
}, },
generateHeadingHTML: function () { generateHeadingHTML: function () {
/* Pure function which returns the heading HTML to be /* Returns the heading HTML to be rendered.
* rendered.
*/ */
return _converse.templates.chatroom_head( return _converse.templates.chatroom_head(
_.extend(this.model.toJSON(), { _.extend(this.model.toJSON(), {
@ -408,8 +408,7 @@
}, },
renderHeading: function () { renderHeading: function () {
/* Render the heading UI of the chat room. /* Render the heading UI of the chat room. */
*/
this.el.querySelector('.chat-head-chatroom').innerHTML = this.generateHeadingHTML(); this.el.querySelector('.chat-head-chatroom').innerHTML = this.generateHeadingHTML();
}, },
@ -433,6 +432,27 @@
return this; return this;
}, },
afterShown: function () {
/* Override from converse-chatview, specifically to avoid
* the 'active' chat state from being sent out prematurely.
*
* This is instead done in `afterConnected` below.
*/
if (_converse.connection.connected) {
// Without a connection, we haven't yet initialized
// localstorage
this.model.save();
}
},
afterConnected: function () {
if (this.model.get('connection_status') === Strophe.Status.CONNECTED) {
this.setChatState(_converse.ACTIVE);
this.scrollDown();
this.focus();
}
},
getExtraMessageClasses: function (attrs) { getExtraMessageClasses: function (attrs) {
var extra_classes = _converse.ChatBoxView.prototype var extra_classes = _converse.ChatBoxView.prototype
.getExtraMessageClasses.apply(this, arguments); .getExtraMessageClasses.apply(this, arguments);
@ -790,6 +810,9 @@
* as taken from the 'chat_state' attribute of the chat box. * as taken from the 'chat_state' attribute of the chat box.
* See XEP-0085 Chat State Notifications. * See XEP-0085 Chat State Notifications.
*/ */
if (this.model.get('connection_status') !== Strophe.Status.CONNECTED) {
return;
}
var chat_state = this.model.get('chat_state'); var chat_state = this.model.get('chat_state');
if (chat_state === _converse.GONE) { if (chat_state === _converse.GONE) {
// <gone/> is not applicable within MUC context // <gone/> is not applicable within MUC context