Skip to content

Commit 34c4b2a

Browse files
committed
Prevent empty messages from being created
1 parent 804c78d commit 34c4b2a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/headless/converse-chat.js

+15
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ converse.plugins.add('converse-chat', {
8686
},
8787

8888
async initialize () {
89+
if (!this.checkValidity()) { return; }
8990
this.initialized = u.getResolveablePromise();
9091
if (this.get('type') === 'chat') {
9192
ModelWithContact.prototype.initialize.apply(this, arguments);
@@ -127,6 +128,20 @@ converse.plugins.add('converse-chat', {
127128
}
128129
},
129130

131+
checkValidity () {
132+
if (Object.keys(this.attributes).length === 3) {
133+
// XXX: This is an empty message with only the 3 default values.
134+
// This seems to happen when saving a newly created message
135+
// fails for some reason.
136+
// TODO: This is likely fixable by setting `wait` when
137+
// creating messages. See the wait-for-messages branch.
138+
this.validationError = "Empty message";
139+
this.safeDestroy();
140+
return false;
141+
}
142+
return true;
143+
},
144+
130145
safeDestroy () {
131146
try {
132147
this.destroy()

src/headless/converse-muc.js

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ converse.plugins.add('converse-muc', {
234234
_converse.ChatRoomMessage = _converse.Message.extend({
235235

236236
initialize () {
237+
if (!this.checkValidity()) { return; }
237238
if (this.get('file')) {
238239
this.on('change:put', this.uploadFile, this);
239240
}

0 commit comments

Comments
 (0)