Skip to content

Commit

Permalink
Prevent empty messages from being created
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Feb 27, 2020
1 parent 804c78d commit 34c4b2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/headless/converse-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ converse.plugins.add('converse-chat', {
},

async initialize () {
if (!this.checkValidity()) { return; }
this.initialized = u.getResolveablePromise();
if (this.get('type') === 'chat') {
ModelWithContact.prototype.initialize.apply(this, arguments);
Expand Down Expand Up @@ -127,6 +128,20 @@ converse.plugins.add('converse-chat', {
}
},

checkValidity () {
if (Object.keys(this.attributes).length === 3) {
// XXX: This is an empty message with only the 3 default values.
// This seems to happen when saving a newly created message
// fails for some reason.
// TODO: This is likely fixable by setting `wait` when
// creating messages. See the wait-for-messages branch.
this.validationError = "Empty message";
this.safeDestroy();
return false;
}
return true;
},

safeDestroy () {
try {
this.destroy()
Expand Down
1 change: 1 addition & 0 deletions src/headless/converse-muc.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ converse.plugins.add('converse-muc', {
_converse.ChatRoomMessage = _converse.Message.extend({

initialize () {
if (!this.checkValidity()) { return; }
if (this.get('file')) {
this.on('change:put', this.uploadFile, this);
}
Expand Down

0 comments on commit 34c4b2a

Please sign in to comment.