Also handle 'normal'
messages from roster contacts
This commit is contained in:
parent
739d79e90c
commit
a76393f216
|
@ -7,7 +7,8 @@ import { getOpenPromise } from '@converse/openpromise';
|
|||
const { Strophe, sizzle, u } = converse.env;
|
||||
|
||||
/**
|
||||
* Mixin which turns a `ModelWithContact` model into a non-MUC message. These can be either `chat` messages or `headline` messages.
|
||||
* Mixin which turns a `ModelWithContact` model into a non-MUC message.
|
||||
* These can be either `chat`, `normal` or `headline` messages.
|
||||
* @mixin
|
||||
* @namespace _converse.Message
|
||||
* @memberOf _converse
|
||||
|
@ -47,9 +48,8 @@ const MessageMixin = {
|
|||
this.initialized.resolve();
|
||||
},
|
||||
|
||||
|
||||
setContact () {
|
||||
if (this.get('type') === 'chat') {
|
||||
if (['chat', 'normal'].includes(this.get('type'))) {
|
||||
ModelWithContact.prototype.initialize.apply(this, arguments);
|
||||
this.setRosterContact(Strophe.getBareJidFromJid(this.get('from')));
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ const MessageMixin = {
|
|||
if (this.get('is_encrypted')) {
|
||||
const { __ } = _converse;
|
||||
return this.get('plaintext') || this.get('body') || __('Undecryptable OMEMO message');
|
||||
} else if (['groupchat', 'chat'].includes(this.get('type'))) {
|
||||
} else if (['groupchat', 'chat', 'normal'].includes(this.get('type'))) {
|
||||
return this.get('body');
|
||||
} else {
|
||||
return this.get('message');
|
||||
|
|
|
@ -178,7 +178,7 @@ export async function parseMessage (stanza) {
|
|||
'thread': stanza.querySelector('thread')?.textContent,
|
||||
'time': delay ? dayjs(delay.getAttribute('stamp')).toISOString() : now,
|
||||
'to': stanza.getAttribute('to'),
|
||||
'type': stanza.getAttribute('type')
|
||||
'type': stanza.getAttribute('type') || 'normal'
|
||||
},
|
||||
getErrorAttributes(stanza),
|
||||
getOutOfBandAttributes(stanza),
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { _converse, api, converse } from '@converse/headless/core.js';
|
||||
import { isServerMessage, } from '@converse/headless/shared/parsers';
|
||||
import { isArchived, isHeadline, isServerMessage, } from '@converse/headless/shared/parsers';
|
||||
import { parseMessage } from './parsers.js';
|
||||
import log from '@converse/headless/log.js';
|
||||
|
||||
const { Strophe, sizzle, u } = converse.env;
|
||||
const { Strophe, u } = converse.env;
|
||||
|
||||
export function openChat (jid) {
|
||||
if (!u.isValidJID(jid)) {
|
||||
|
@ -60,43 +60,22 @@ export function autoJoinChats () {
|
|||
export function registerMessageHandlers () {
|
||||
_converse.connection.addHandler(
|
||||
stanza => {
|
||||
if (sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).pop()) {
|
||||
// MAM messages are handled in converse-mam.
|
||||
// We shouldn't get MAM messages here because
|
||||
// they shouldn't have a `type` attribute.
|
||||
log.warn(`Received a MAM message with type "chat".`);
|
||||
if (
|
||||
['groupchat', 'error'].includes(stanza.getAttribute('type')) ||
|
||||
isHeadline(stanza) ||
|
||||
isServerMessage(stanza) ||
|
||||
isArchived(stanza)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
_converse.handleMessageStanza(stanza);
|
||||
return true;
|
||||
return _converse.handleMessageStanza(stanza) || true;
|
||||
},
|
||||
null,
|
||||
'message',
|
||||
'chat'
|
||||
);
|
||||
|
||||
_converse.connection.addHandler(
|
||||
stanza => {
|
||||
// Message receipts are usually without the `type` attribute. See #1353
|
||||
if (stanza.getAttribute('type') !== null) {
|
||||
// TODO: currently Strophe has no way to register a handler
|
||||
// for stanzas without a `type` attribute.
|
||||
// We could update it to accept null to mean no attribute,
|
||||
// but that would be a backward-incompatible change
|
||||
return true; // Gets handled above.
|
||||
}
|
||||
_converse.handleMessageStanza(stanza);
|
||||
return true;
|
||||
},
|
||||
Strophe.NS.RECEIPTS,
|
||||
'message'
|
||||
);
|
||||
|
||||
_converse.connection.addHandler(
|
||||
stanza => {
|
||||
handleErrorMessage(stanza);
|
||||
return true;
|
||||
},
|
||||
stanza => handleErrorMessage(stanza) || true,
|
||||
null,
|
||||
'message',
|
||||
'error'
|
||||
|
|
|
@ -124,7 +124,7 @@ export default class Message extends CustomElement {
|
|||
shouldShowAvatar () {
|
||||
return api.settings.get('show_message_avatar') &&
|
||||
!this.model.isMeCommand() &&
|
||||
['chat', 'groupchat'].includes(this.model.get('type'));
|
||||
['chat', 'groupchat', 'normal'].includes(this.model.get('type'));
|
||||
}
|
||||
|
||||
onUnfurlAnimationEnd () {
|
||||
|
|
Loading…
Reference in New Issue
Block a user