|
@@ -13,7 +13,7 @@ import { isNewMessage } from '../plugins/chat/utils.js';
|
|
import _converse from './_converse.js';
|
|
import _converse from './_converse.js';
|
|
import { MethodNotImplementedError } from './errors.js';
|
|
import { MethodNotImplementedError } from './errors.js';
|
|
import { sendMarker, sendReceiptStanza, sendRetractionMessage } from './actions.js';
|
|
import { sendMarker, sendReceiptStanza, sendRetractionMessage } from './actions.js';
|
|
-import {parseMessage} from '../plugins/chat/parsers';
|
|
|
|
|
|
+import { parseMessage } from '../plugins/chat/parsers';
|
|
|
|
|
|
const { Strophe, $msg, u } = converse.env;
|
|
const { Strophe, $msg, u } = converse.env;
|
|
|
|
|
|
@@ -274,6 +274,8 @@ export default function ModelWithMessages(BaseModel) {
|
|
* chat.sendMessage({'body': 'hello world'});
|
|
* chat.sendMessage({'body': 'hello world'});
|
|
*/
|
|
*/
|
|
async sendMessage(attrs) {
|
|
async sendMessage(attrs) {
|
|
|
|
+ await converse.emojis?.initialized_promise;
|
|
|
|
+
|
|
if (!this.canPostMessages()) {
|
|
if (!this.canPostMessages()) {
|
|
log.warn('sendMessage was called but canPostMessages is false');
|
|
log.warn('sendMessage was called but canPostMessages is false');
|
|
return;
|
|
return;
|
|
@@ -748,11 +750,48 @@ export default function ModelWithMessages(BaseModel) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param {Message} message
|
|
|
|
+ * @param {MessageAttributes} attrs
|
|
|
|
+ */
|
|
|
|
+ async getErrorAttributesForMessage(message, attrs) {
|
|
|
|
+ const { __ } = _converse;
|
|
|
|
+ const new_attrs = {
|
|
|
|
+ editable: false,
|
|
|
|
+ error: attrs.error,
|
|
|
|
+ error_condition: attrs.error_condition,
|
|
|
|
+ error_text: attrs.error_text,
|
|
|
|
+ error_type: attrs.error_type,
|
|
|
|
+ is_error: true,
|
|
|
|
+ };
|
|
|
|
+ if (attrs.msgid === message.get('retraction_id')) {
|
|
|
|
+ // The error message refers to a retraction
|
|
|
|
+ new_attrs.retraction_id = undefined;
|
|
|
|
+ if (!attrs.error) {
|
|
|
|
+ if (attrs.error_condition === 'forbidden') {
|
|
|
|
+ new_attrs.error = __("You're not allowed to retract your message.");
|
|
|
|
+ } else {
|
|
|
|
+ new_attrs.error = __('Sorry, an error occurred while trying to retract your message.');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (!attrs.error) {
|
|
|
|
+ if (attrs.error_condition === 'forbidden') {
|
|
|
|
+ new_attrs.error = __("You're not allowed to send a message.");
|
|
|
|
+ } else {
|
|
|
|
+ new_attrs.error = __('Sorry, an error occurred while trying to send your message.');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * *Hook* which allows plugins to add application-specific attributes
|
|
|
|
+ * @event _converse#getErrorAttributesForMessage
|
|
|
|
+ */
|
|
|
|
+ return await api.hook('getErrorAttributesForMessage', attrs, new_attrs);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param {Element} stanza
|
|
* @param {Element} stanza
|
|
*/
|
|
*/
|
|
async handleErrorMessageStanza(stanza) {
|
|
async handleErrorMessageStanza(stanza) {
|
|
- const { __ } = _converse;
|
|
|
|
const attrs_or_error = await parseMessage(stanza);
|
|
const attrs_or_error = await parseMessage(stanza);
|
|
if (u.isErrorObject(attrs_or_error)) {
|
|
if (u.isErrorObject(attrs_or_error)) {
|
|
const { stanza, message } = /** @type {StanzaParseError} */ (attrs_or_error);
|
|
const { stanza, message } = /** @type {StanzaParseError} */ (attrs_or_error);
|
|
@@ -767,30 +806,7 @@ export default function ModelWithMessages(BaseModel) {
|
|
|
|
|
|
const message = this.getMessageReferencedByError(attrs);
|
|
const message = this.getMessageReferencedByError(attrs);
|
|
if (message) {
|
|
if (message) {
|
|
- const new_attrs = {
|
|
|
|
- 'error': attrs.error,
|
|
|
|
- 'error_condition': attrs.error_condition,
|
|
|
|
- 'error_text': attrs.error_text,
|
|
|
|
- 'error_type': attrs.error_type,
|
|
|
|
- 'editable': false,
|
|
|
|
- };
|
|
|
|
- if (attrs.msgid === message.get('retraction_id')) {
|
|
|
|
- // The error message refers to a retraction
|
|
|
|
- new_attrs.retraction_id = undefined;
|
|
|
|
- if (!attrs.error) {
|
|
|
|
- if (attrs.error_condition === 'forbidden') {
|
|
|
|
- new_attrs.error = __("You're not allowed to retract your message.");
|
|
|
|
- } else {
|
|
|
|
- new_attrs.error = __('Sorry, an error occurred while trying to retract your message.');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else if (!attrs.error) {
|
|
|
|
- if (attrs.error_condition === 'forbidden') {
|
|
|
|
- new_attrs.error = __("You're not allowed to send a message.");
|
|
|
|
- } else {
|
|
|
|
- new_attrs.error = __('Sorry, an error occurred while trying to send your message.');
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ const new_attrs = await this.getErrorAttributesForMessage(message, attrs);
|
|
message.save(new_attrs);
|
|
message.save(new_attrs);
|
|
} else {
|
|
} else {
|
|
this.createMessage(attrs);
|
|
this.createMessage(attrs);
|