Let sendMessage
return the message model, not just the text
This commit is contained in:
parent
afa2543492
commit
1eb2364336
@ -2016,7 +2016,7 @@
|
||||
});
|
||||
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
|
||||
|
||||
expect(_converse.api.trigger).toHaveBeenCalledWith('messageSend', text);
|
||||
expect(_converse.api.trigger).toHaveBeenCalledWith('messageSend', jasmine.any(_converse.Message));
|
||||
const chat_content = view.el.querySelector('.chat-content');
|
||||
expect(chat_content.querySelectorAll('.chat-msg').length).toBe(1);
|
||||
|
||||
|
@ -885,11 +885,9 @@ converse.plugins.add('converse-chatview', {
|
||||
async onFormSubmitted (ev) {
|
||||
ev.preventDefault();
|
||||
const textarea = this.el.querySelector('.chat-textarea');
|
||||
const message = textarea.value.trim();
|
||||
if (_converse.message_limit && message.length > _converse.message_limit) {
|
||||
return;
|
||||
}
|
||||
if (!message.replace(/\s/g, '').length) {
|
||||
const message_text = textarea.value.trim();
|
||||
if (_converse.message_limit && message_text.length > _converse.message_limit ||
|
||||
!message_text.replace(/\s/g, '').length) {
|
||||
return;
|
||||
}
|
||||
if (!_converse.connection.authenticated) {
|
||||
@ -907,18 +905,21 @@ converse.plugins.add('converse-chatview', {
|
||||
}
|
||||
u.addClass('disabled', textarea);
|
||||
textarea.setAttribute('disabled', 'disabled');
|
||||
if (this.parseMessageForCommands(message) ||
|
||||
await this.model.sendMessage(message, spoiler_hint)) {
|
||||
|
||||
const is_command = this.parseMessageForCommands(message_text);
|
||||
const message = is_command ? null : await this.model.sendMessage(message_text, spoiler_hint);
|
||||
if (is_command || message) {
|
||||
hint_el.value = '';
|
||||
textarea.value = '';
|
||||
u.removeClass('correcting', textarea);
|
||||
textarea.style.height = 'auto'; // Fixes weirdness
|
||||
}
|
||||
if (message) {
|
||||
/**
|
||||
* Triggered just before an HTML5 message notification will be sent out.
|
||||
* Triggered whenever a message is sent by the user
|
||||
* @event _converse#messageSend
|
||||
* @type { _converse.Message }
|
||||
* @example _converse.api.listen.on('messageSend', data => { ... });
|
||||
* @example _converse.api.listen.on('messageSend', message => { ... });
|
||||
*/
|
||||
_converse.api.trigger('messageSend', message);
|
||||
}
|
||||
|
@ -192,15 +192,17 @@ converse.plugins.add('converse-omemo', {
|
||||
const attrs = this.getOutgoingMessageAttributes(text, spoiler_hint);
|
||||
attrs['is_encrypted'] = true;
|
||||
attrs['plaintext'] = attrs.message;
|
||||
let message, stanza;
|
||||
try {
|
||||
const devices = await _converse.getBundlesAndBuildSessions(this);
|
||||
const stanza = await _converse.createOMEMOMessageStanza(this, this.messages.create(attrs), devices);
|
||||
_converse.api.send(stanza);
|
||||
message = this.messages.create(attrs);
|
||||
stanza = await _converse.createOMEMOMessageStanza(this, message, devices);
|
||||
} catch (e) {
|
||||
this.handleMessageSendError(e);
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
return true;
|
||||
_converse.api.send(stanza);
|
||||
return message;
|
||||
} else {
|
||||
return this.__super__.sendMessage.apply(this, arguments);
|
||||
}
|
||||
|
@ -705,13 +705,12 @@ converse.plugins.add('converse-chatboxes', {
|
||||
},
|
||||
|
||||
/**
|
||||
* Responsible for sending off a text message inside an ongoing
|
||||
* chat conversation.
|
||||
*
|
||||
* Responsible for sending off a text message inside an ongoing chat conversation.
|
||||
* @method _converse.ChatBox#sendMessage
|
||||
* @memberOf _converse.ChatBox
|
||||
* @param {String} text - The chat message text
|
||||
* @param {String} spoiler_hint - An optional hint, if the message being sent is a spoiler
|
||||
* @param { String } text - The chat message text
|
||||
* @param { String } spoiler_hint - An optional hint, if the message being sent is a spoiler
|
||||
* @returns { _converse.Message }
|
||||
* @example
|
||||
* const chat = _converse.api.chats.get('buddy1@example.com');
|
||||
* chat.sendMessage('hello world');
|
||||
@ -735,7 +734,7 @@ converse.plugins.add('converse-chatboxes', {
|
||||
message = this.messages.create(attrs);
|
||||
}
|
||||
_converse.api.send(this.createMessageStanza(message));
|
||||
return true;
|
||||
return message;
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user