浏览代码

Also handle `'normal'` messages from roster contacts

JC Brand 2 年之前
父节点
当前提交
a76393f216

+ 4 - 4
src/headless/plugins/chat/message.js

@@ -7,7 +7,8 @@ import { getOpenPromise } from '@converse/openpromise';
 const { Strophe, sizzle, u } = converse.env;
 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
  * @mixin
  * @namespace _converse.Message
  * @namespace _converse.Message
  * @memberOf _converse
  * @memberOf _converse
@@ -47,9 +48,8 @@ const MessageMixin = {
         this.initialized.resolve();
         this.initialized.resolve();
     },
     },
 
 
-
     setContact () {
     setContact () {
-        if (this.get('type') === 'chat') {
+        if (['chat', 'normal'].includes(this.get('type'))) {
             ModelWithContact.prototype.initialize.apply(this, arguments);
             ModelWithContact.prototype.initialize.apply(this, arguments);
             this.setRosterContact(Strophe.getBareJidFromJid(this.get('from')));
             this.setRosterContact(Strophe.getBareJidFromJid(this.get('from')));
         }
         }
@@ -164,7 +164,7 @@ const MessageMixin = {
         if (this.get('is_encrypted')) {
         if (this.get('is_encrypted')) {
             const { __ } = _converse;
             const { __ } = _converse;
             return this.get('plaintext') || this.get('body') || __('Undecryptable OMEMO message');
             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');
             return this.get('body');
         } else {
         } else {
             return this.get('message');
             return this.get('message');

+ 1 - 1
src/headless/plugins/chat/parsers.js

@@ -178,7 +178,7 @@ export async function parseMessage (stanza) {
             'thread': stanza.querySelector('thread')?.textContent,
             'thread': stanza.querySelector('thread')?.textContent,
             'time': delay ? dayjs(delay.getAttribute('stamp')).toISOString() : now,
             'time': delay ? dayjs(delay.getAttribute('stamp')).toISOString() : now,
             'to': stanza.getAttribute('to'),
             'to': stanza.getAttribute('to'),
-            'type': stanza.getAttribute('type')
+            'type': stanza.getAttribute('type') || 'normal'
         },
         },
         getErrorAttributes(stanza),
         getErrorAttributes(stanza),
         getOutOfBandAttributes(stanza),
         getOutOfBandAttributes(stanza),

+ 10 - 31
src/headless/plugins/chat/utils.js

@@ -1,9 +1,9 @@
 import { _converse, api, converse } from '@converse/headless/core.js';
 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 { parseMessage } from './parsers.js';
 import log from '@converse/headless/log.js';
 import log from '@converse/headless/log.js';
 
 
-const { Strophe, sizzle, u } = converse.env;
+const { Strophe, u } = converse.env;
 
 
 export function openChat (jid) {
 export function openChat (jid) {
     if (!u.isValidJID(jid)) {
     if (!u.isValidJID(jid)) {
@@ -60,43 +60,22 @@ export function autoJoinChats () {
 export function registerMessageHandlers () {
 export function registerMessageHandlers () {
     _converse.connection.addHandler(
     _converse.connection.addHandler(
         stanza => {
         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;
                 return true;
             }
             }
-            _converse.handleMessageStanza(stanza);
-            return true;
+            return _converse.handleMessageStanza(stanza) || true;
         },
         },
         null,
         null,
         'message',
         'message',
-        'chat'
     );
     );
 
 
     _converse.connection.addHandler(
     _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,
         null,
         'message',
         'message',
         'error'
         'error'

+ 1 - 1
src/shared/chat/message.js

@@ -124,7 +124,7 @@ export default class Message extends CustomElement {
     shouldShowAvatar () {
     shouldShowAvatar () {
         return api.settings.get('show_message_avatar') &&
         return api.settings.get('show_message_avatar') &&
             !this.model.isMeCommand() &&
             !this.model.isMeCommand() &&
-            ['chat', 'groupchat'].includes(this.model.get('type'));
+            ['chat', 'groupchat', 'normal'].includes(this.model.get('type'));
     }
     }
 
 
     onUnfurlAnimationEnd () {
     onUnfurlAnimationEnd () {