Bugfix. Don't remove model, simply remove view

Otherwise the model gets removed mid-creation, which causes the
`url required` error from Backbone.
This commit is contained in:
JC Brand 2018-05-07 12:57:05 +02:00
parent 7e94f3c691
commit 776f49d5c3
3 changed files with 19 additions and 8 deletions

View File

@ -115,10 +115,7 @@
},
isOnlyChatStateNotification () {
return this.get('chat_state') &&
!this.get('oob_url') &&
!this.get('file') &&
!this.get('message');
return u.isOnlyChatStateNotification(this);
},
getDisplayName () {
@ -451,7 +448,12 @@
/* Create a Backbone.Message object inside this chat box
* based on the identified message stanza.
*/
return this.messages.create(this.getMessageAttributesFromStanza.apply(this, arguments));
const attrs = this.getMessageAttributesFromStanza.apply(this, arguments)
if (u.isOnlyChatStateNotification(attrs)) {
return;
} else {
return this.messages.create(attrs);
}
},
newMessageWillBeHidden () {

View File

@ -160,9 +160,6 @@
},
renderChatStateNotification () {
if (this.model.get('delayed')) {
return this.model.destroy();
}
let text;
const from = this.model.get('from'),
name = this.model.getDisplayName();

View File

@ -13,6 +13,7 @@
"sizzle",
"es6-promise",
"lodash.noconflict",
"backbone",
"strophe",
"uri",
"tpl!audio",
@ -46,6 +47,7 @@
sizzle,
Promise,
_,
Backbone,
Strophe,
URI,
tpl_audio,
@ -488,6 +490,16 @@
}
};
u.isOnlyChatStateNotification = function (attrs) {
if (attrs instanceof Backbone.Model) {
attrs = attrs.attributes;
}
return attrs['chat_state'] &&
!attrs['oob_url'] &&
!attrs['file'] &&
!attrs['message'];
};
u.isOTRMessage = function (message) {
var body = message.querySelector('body'),
text = (!_.isNull(body) ? body.textContent: undefined);