Procházet zdrojové kódy

Move JSDoc typedef type definitions to types.ts

JC Brand před 7 měsíci
rodič
revize
3e508b007e
31 změnil soubory, kde provedl 292 přidání a 527 odebrání
  1. 3 4
      src/headless/plugins/chat/model.js
  2. 2 56
      src/headless/plugins/chat/parsers.js
  3. 52 0
      src/headless/plugins/chat/types.ts
  4. 1 1
      src/headless/plugins/chat/utils.js
  5. 11 11
      src/headless/plugins/muc/muc.js
  6. 13 8
      src/headless/plugins/muc/occupant.js
  7. 1 15
      src/headless/plugins/muc/parsers.js
  8. 14 0
      src/headless/plugins/muc/types.ts
  9. 4 4
      src/headless/shared/model-with-messages.js
  10. 1 0
      src/headless/shared/parsers.js
  11. 11 0
      src/headless/shared/types.ts
  12. 14 14
      src/headless/types/plugins/chat/model.d.ts
  13. 3 248
      src/headless/types/plugins/chat/parsers.d.ts
  14. 52 0
      src/headless/types/plugins/chat/types.d.ts
  15. 1 1
      src/headless/types/plugins/chat/utils.d.ts
  16. 19 19
      src/headless/types/plugins/muc/muc.d.ts
  17. 13 17
      src/headless/types/plugins/muc/occupant.d.ts
  18. 1 51
      src/headless/types/plugins/muc/parsers.d.ts
  19. 14 0
      src/headless/types/plugins/muc/types.d.ts
  20. 9 9
      src/headless/types/shared/chatbox.d.ts
  21. 11 11
      src/headless/types/shared/model-with-messages.d.ts
  22. 2 4
      src/headless/types/shared/parsers.d.ts
  23. 9 0
      src/headless/types/shared/types.d.ts
  24. 4 12
      src/plugins/modal/api.js
  25. 7 0
      src/plugins/modal/types.ts
  26. 2 3
      src/plugins/notifications/utils.js
  27. 2 2
      src/plugins/omemo/utils.js
  28. 5 34
      src/types/plugins/modal/api.d.ts
  29. 8 0
      src/types/plugins/modal/types.d.ts
  30. 1 1
      src/types/plugins/notifications/utils.d.ts
  31. 2 2
      src/types/plugins/omemo/utils.d.ts

+ 3 - 4
src/headless/plugins/chat/model.js

@@ -21,7 +21,7 @@ class ChatBox extends ModelWithMessages(ModelWithContact(ColorAwareModel(ChatBox
     /**
      * @typedef {import('./message.js').default} Message
      * @typedef {import('../muc/muc.js').default} MUC
-     * @typedef {import('./parsers').MessageAttributes} MessageAttributes
+     * @typedef {import('./types.ts').MessageAttributes} MessageAttributes
      * @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError
      */
 
@@ -68,10 +68,9 @@ class ChatBox extends ModelWithMessages(ModelWithContact(ColorAwareModel(ChatBox
 
 
     /**
-     * @param {Promise<MessageAttributes|StanzaParseError>} attrs_promise
+     * @param {MessageAttributes|StanzaParseError} attrs_or_error
      */
-    async onMessage (attrs_promise) {
-        const attrs_or_error = await attrs_promise;
+    async onMessage (attrs_or_error) {
         if (u.isErrorObject(attrs_or_error)) {
             const { stanza, message } = /** @type {StanzaParseError} */(attrs_or_error);
             if (stanza) log.error(stanza);

+ 2 - 56
src/headless/plugins/chat/parsers.js

@@ -32,64 +32,10 @@ import {
 
 const { Strophe, sizzle } = converse.env;
 
-/**
- * The object which {@link parseMessage} returns
- * @typedef {Object} MessageAttributes
- * @property {('me'|'them')} sender - Whether the message was sent by the current user or someone else
- * @property {Array<Object>} references - A list of objects representing XEP-0372 references
- * @property {Boolean} editable - Is this message editable via XEP-0308?
- * @property {Boolean} is_archived -  Is this message from a XEP-0313 MAM archive?
- * @property {Boolean} is_carbon - Is this message a XEP-0280 Carbon?
- * @property {Boolean} is_delayed - Was delivery of this message was delayed as per XEP-0203?
- * @property {Boolean} is_encrypted -  Is this message XEP-0384  encrypted?
- * @property {Boolean} is_error - Whether an error was received for this message
- * @property {Boolean} is_headline - Is this a "headline" message?
- * @property {Boolean} is_markable - Can this message be marked with a XEP-0333 chat marker?
- * @property {Boolean} is_marker - Is this message a XEP-0333 Chat Marker?
- * @property {Boolean} is_only_emojis - Does the message body contain only emojis?
- * @property {Boolean} is_spoiler - Is this a XEP-0382 spoiler message?
- * @property {Boolean} is_tombstone - Is this a XEP-0424 tombstone?
- * @property {Boolean} is_unstyled - Whether XEP-0393 styling hints should be ignored
- * @property {Boolean} is_valid_receipt_request - Does this message request a XEP-0184 receipt (and is not from us or a carbon or archived message)
- * @property {Object} encrypted -  XEP-0384 encryption payload attributes
- * @property {String} body - The contents of the <body> tag of the message stanza
- * @property {String} chat_state - The XEP-0085 chat state notification contained in this message
- * @property {String} contact_jid - The JID of the other person or entity
- * @property {String} edited - An ISO8601 string recording the time that the message was edited per XEP-0308
- * @property {String} error - The error name
- * @property {String} error_condition - The defined error condition
- * @property {String} error_text - The error text received from the server
- * @property {String} error_type - The type of error received from the server
- * @property {String} from - The sender JID
- * @property {String} fullname - The full name of the sender
- * @property {String} marker - The XEP-0333 Chat Marker value
- * @property {String} marker_id - The `id` attribute of a XEP-0333 chat marker
- * @property {String} msgid - The root `id` attribute of the stanza
- * @property {String} nick - The roster nickname of the sender
- * @property {String} oob_desc - The description of the XEP-0066 out of band data
- * @property {String} oob_url - The URL of the XEP-0066 out of band data
- * @property {String} origin_id - The XEP-0359 Origin ID
- * @property {String} plaintext - The decrypted text of this message, in case it was encrypted.
- * @property {String} receipt_id - The `id` attribute of a XEP-0184 <receipt> element
- * @property {String} received - An ISO8601 string recording the time that the message was received
- * @property {String} replace_id - The `id` attribute of a XEP-0308 <replace> element
- * @property {String} retracted - An ISO8601 string recording the time that the message was retracted
- * @property {String} retracted_id - The `id` attribute of a XEP-424 <retracted> element
- * @property {String} spoiler_hint  The XEP-0382 spoiler hint
- * @property {String} stanza_id - The XEP-0359 Stanza ID. Note: the key is actualy `stanza_id ${by_jid}` and there can be multiple.
- * @property {String} subject - The <subject> element value
- * @property {String} thread - The <thread> element value
- * @property {String} time - The time (in ISO8601 format), either given by the XEP-0203 <delay> element, or of receipt.
- * @property {String} to - The recipient JID
- * @property {String} type - The type of message
- */
-
-
 /**
  * Parses a passed in message stanza and returns an object of attributes.
- * @method st#parseMessage
- * @param { Element } stanza - The message stanza
- * @returns { Promise<MessageAttributes|StanzaParseError> }
+ * @param {Element} stanza - The message stanza
+ * @returns {Promise<import('./types.ts').MessageAttributes|StanzaParseError>}
  */
 export async function parseMessage (stanza) {
     throwErrorIfInvalidForward(stanza);

+ 52 - 0
src/headless/plugins/chat/types.ts

@@ -0,0 +1,52 @@
+import {EncryptionAttrs} from "../../shared/types";
+
+export type MessageAttributes = EncryptionAttrs & {
+    body: string; // The contents of the <body> tag of the message stanza
+    chat_state: string; // The XEP-0085 chat state notification contained in this message
+    contact_jid: string; // The JID of the other person or entity
+    editable: boolean; // Is this message editable via XEP-0308?
+    edited: string; // An ISO8601 string recording the time that the message was edited per XEP-0308
+    error: string; // The error name
+    error_condition: string; // The defined error condition
+    error_text: string; // The error text received from the server
+    error_type: string; // The type of error received from the server
+    from: string; // The sender JID
+    message?: string; // Used with info and error messages
+    fullname: string; // The full name of the sender
+    is_archived: boolean; //  Is this message from a XEP-0313 MAM archive?
+    is_carbon: boolean; // Is this message a XEP-0280 Carbon?
+    is_delayed: boolean; // Was delivery of this message was delayed as per XEP-0203?
+    is_encrypted: boolean; //  Is this message XEP-0384  encrypted?
+    is_error: boolean; // Whether an error was received for this message
+    is_headline: boolean; // Is this a "headline" message?
+    is_markable: boolean; // Can this message be marked with a XEP-0333 chat marker?
+    is_marker: boolean; // Is this message a XEP-0333 Chat Marker?
+    is_only_emojis: boolean; // Does the message body contain only emojis?
+    is_spoiler: boolean; // Is this a XEP-0382 spoiler message?
+    is_tombstone: boolean; // Is this a XEP-0424 tombstone?
+    is_unstyled: boolean; // Whether XEP-0393 styling hints should be ignored
+    is_valid_receipt_request: boolean; // Does this message request a XEP-0184 receipt (and is not from us or a carbon or archived message)
+    marker: string; // The XEP-0333 Chat Marker value
+    marker_id: string; // The `id` attribute of a XEP-0333 chat marker
+    msgid: string; // The root `id` attribute of the stanza
+    nick: string; // The roster nickname of the sender
+    ogp_for_id?: string; // Used for Open Graph Metadata support for unfurls
+    oob_desc: string; // The description of the XEP-0066 out of band data
+    oob_url: string; // The URL of the XEP-0066 out of band data
+    origin_id: string; // The XEP-0359 Origin ID
+    plaintext: string; // The decrypted text of this message, in case it was encrypted.
+    receipt_id: string; // The `id` attribute of a XEP-0184 <receipt> element
+    received: string; // An ISO8601 string recording the time that the message was received
+    references: Array<Object>; // A list of objects representing XEP-0372 references
+    replace_id: string; // The `id` attribute of a XEP-0308 <replace> element
+    retracted: string; // An ISO8601 string recording the time that the message was retracted
+    retracted_id: string; // The `id` attribute of a XEP-424 <retracted> element
+    sender: 'me' | 'them'; // Whether the message was sent by the current user or someone else
+    spoiler_hint: string; //  The XEP-0382 spoiler hint
+    stanza_id: string; // The XEP-0359 Stanza ID. Note: the key is actualy `stanza_id ${by_jid}` and there can be multiple.
+    subject: string; // The <subject> element value
+    thread: string; // The <thread> element value
+    time: string; // The time (in ISO8601 format), either given by the XEP-0203 <delay> element, or of receipt.
+    to: string; // The recipient JID
+    type: string; // The type of message
+};

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

@@ -1,7 +1,7 @@
 /**
  * @module:headless-plugins-chat-utils
  * @typedef {import('./model.js').default} ChatBox
- * @typedef {import('./parsers').MessageAttributes} MessageAttributes
+ * @typedef {import('./types.ts').MessageAttributes} MessageAttributes
  * @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError
  * @typedef {import('strophe.js').Builder} Builder
  */

+ 11 - 11
src/headless/plugins/muc/muc.js

@@ -48,8 +48,8 @@ class MUC extends ModelWithMessages(ColorAwareModel(ChatBoxBase)) {
      * @typedef {import('./occupant.js').default} MUCOccupant
      * @typedef {import('./affiliations/utils.js').NonOutcastAffiliation} NonOutcastAffiliation
      * @typedef {import('./parsers').MemberListItem} MemberListItem
-     * @typedef {module:plugin-chat-parsers.MessageAttributes} MessageAttributes
-     * @typedef {import('./parsers').MUCMessageAttributes} MUCMessageAttributes
+     * @typedef {import('../chat/types.ts').MessageAttributes} MessageAttributes
+     * @typedef {import('./types.ts').MUCMessageAttributes} MUCMessageAttributes
      * @typedef {module:shared.converse.UserMessage} UserMessage
      * @typedef {import('strophe.js').Builder} Builder
      * @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError
@@ -483,7 +483,6 @@ class MUC extends ModelWithMessages(ColorAwareModel(ChatBoxBase)) {
     async handleErrorMessageStanza (stanza) {
         const { __ } = _converse;
 
-
         const attrs_or_error = await parseMUCMessage(stanza, this);
         if (u.isErrorObject(attrs_or_error)) {
             const { stanza, message } = /** @type {StanzaParseError} */(attrs_or_error);
@@ -2243,7 +2242,6 @@ class MUC extends ModelWithMessages(ColorAwareModel(ChatBoxBase)) {
         return false;
     }
 
-
     /**
      * @param {MessageAttributes} attrs
      * @returns {boolean}
@@ -2273,7 +2271,7 @@ class MUC extends ModelWithMessages(ColorAwareModel(ChatBoxBase)) {
     /**
      * Given {@link MessageAttributes} look for XEP-0316 Room Notifications and create info
      * messages for them.
-     * @param {MessageAttributes} attrs
+     * @param {MUCMessageAttributes} attrs
      * @returns {boolean}
      */
     handleMEPNotification (attrs) {
@@ -2309,13 +2307,15 @@ class MUC extends ModelWithMessages(ColorAwareModel(ChatBoxBase)) {
      * Handler for all MUC messages sent to this groupchat. This method
      * shouldn't be called directly, instead {@link MUC#queueMessage}
      * should be called.
-     * @param {Promise<MessageAttributes>} promise - A promise which resolves to the message attributes.
+     * @param {MUCMessageAttributes|StanzaParseError} attrs_or_error - A promise which resolves to the message attributes.
      */
-    async onMessage (promise) {
-        const attrs = await promise;
-        if (isErrorObject(attrs)) {
-            return log.error(attrs.message);
-        } else if (attrs.type === 'error' && !(await this.shouldShowErrorMessage(attrs))) {
+    async onMessage (attrs_or_error) {
+        if (isErrorObject(attrs_or_error)) {
+            return log.error(/** @type {Error} */(attrs_or_error).message);
+        }
+
+        const attrs = /** @type {MUCMessageAttributes} */(attrs_or_error);
+        if (attrs.type === 'error' && !(await this.shouldShowErrorMessage(attrs))) {
             return;
         }
 

+ 13 - 8
src/headless/plugins/muc/occupant.js

@@ -6,7 +6,7 @@ import ColorAwareModel from '../../shared/color.js';
 import ModelWithMessages from '../../shared/model-with-messages.js';
 import { AFFILIATIONS, ROLES } from './constants.js';
 import MUCMessages from './messages.js';
-import u, { isErrorObject } from '../../utils/index.js';
+import u from '../../utils/index.js';
 import { shouldCreateGroupchatMessage } from './utils';
 
 /**
@@ -14,7 +14,8 @@ import { shouldCreateGroupchatMessage } from './utils';
  */
 class MUCOccupant extends ModelWithMessages(ColorAwareModel(Model)) {
     /**
-     * @typedef {module:plugin-chat-parsers.MessageAttributes} MessageAttributes
+     * @typedef {import('../chat/types.ts').MessageAttributes} MessageAttributes
+     * @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError
      */
 
     constructor(attributes, options) {
@@ -64,13 +65,17 @@ class MUCOccupant extends ModelWithMessages(ColorAwareModel(Model)) {
     /**
      * Handler for all MUC private messages sent to this occupant.
      * This method houldn't be called directly, instead {@link MUC#queueMessage} should be called.
-     * @param {Promise<MessageAttributes>} promise
+     * @param {MessageAttributes|StanzaParseError} attrs_or_error
      */
-    async onMessage(promise) {
-        const attrs = await promise;
-        if (isErrorObject(attrs)) {
-            return log.error(attrs.message);
-        } else if (attrs.type === 'error') {
+    async onMessage(attrs_or_error) {
+        if (u.isErrorObject(attrs_or_error)) {
+            const { stanza, message } = /** @type {StanzaParseError} */(attrs_or_error);
+            if (stanza) log.error(stanza);
+            return log.error(message);
+        }
+
+        const attrs = /** @type {MessageAttributes} */(attrs_or_error);
+        if (attrs.type === 'error' && !(await this.shouldShowErrorMessage(attrs))) {
             return;
         }
 

+ 1 - 15
src/headless/plugins/muc/parsers.js

@@ -1,6 +1,7 @@
 /**
  * @module:plugin-muc-parsers
  * @typedef {import('../muc/muc.js').default} MUC
+ * @typedef {import('./types.ts').MUCMessageAttributes} MUCMessageAttributes
  */
 import dayjs from 'dayjs';
 import _converse from '../../shared/_converse.js';
@@ -30,21 +31,6 @@ import {
 const { Strophe, sizzle, u } = converse.env;
 const { NS } = Strophe;
 
-/**
- * @typedef {Object} ExtraMUCAttributes
- * @property {Array<Object>} activities - A list of objects representing XEP-0316 MEP notification data
- * @property {String} from_muc - The JID of the MUC from which this message was sent
- * @property {String} from_real_jid - The real JID of the sender, if available
- * @property {String} moderated - The type of XEP-0425 moderation (if any) that was applied
- * @property {String} moderated_by - The JID of the user that moderated this message
- * @property {String} moderated_id - The  XEP-0359 Stanza ID of the message that this one moderates
- * @property {String} moderation_reason - The reason provided why this message moderates another
- * @property {String} occupant_id - The XEP-0421 occupant ID
- *
- * The object which {@link parseMUCMessage} returns
- * @typedef {import('../chat/parsers').MessageAttributes & ExtraMUCAttributes} MUCMessageAttributes
- */
-
 /**
  * Parses a message stanza for XEP-0316 MEP notification data
  * @param {Element} stanza - The message stanza

+ 14 - 0
src/headless/plugins/muc/types.ts

@@ -0,0 +1,14 @@
+import { MessageAttributes } from '../chat/types';
+
+type ExtraMUCAttributes = {
+    activities: Array<Object>; // A list of objects representing XEP-0316 MEP notification data
+    from_muc: string; // The JID of the MUC from which this message was sent
+    from_real_jid: string; // The real JID of the sender, if available
+    moderated: string; // The type of XEP-0425 moderation (if any) that was applied
+    moderated_by: string; // The JID of the user that moderated this message
+    moderated_id: string; // The  XEP-0359 Stanza ID of the message that this one moderates
+    moderation_reason: string; // The reason provided why this message moderates another
+    occupant_id: string; // The XEP-0421 occupant ID
+};
+
+export type MUCMessageAttributes = MessageAttributes & ExtraMUCAttributes;

+ 4 - 4
src/headless/shared/model-with-messages.js

@@ -35,7 +35,7 @@ export default function ModelWithMessages(BaseModel) {
      * @typedef {import('../plugins/chat/model').default} ChatBox
      * @typedef {import('../plugins/muc/muc').default} MUC
      * @typedef {import('../plugins/muc/message').default} MUCMessage
-     * @typedef {import('../plugins/chat/parsers').MessageAttributes} MessageAttributes
+     * @typedef {import('../plugins/chat/types.ts').MessageAttributes} MessageAttributes
      * @typedef {import('../plugins/muc/parsers').MUCMessageAttributes} MUCMessageAttributes
      * @typedef {import('strophe.js').Builder} Builder
      */
@@ -155,9 +155,9 @@ export default function ModelWithMessages(BaseModel) {
         }
 
         /**
-         * @param {Promise<MessageAttributes>} _promise
+         * @param {MessageAttributes|Error} attrs_or_error
          */
-        async onMessage(_promise) {
+        async onMessage(attrs_or_error) {
             throw new NotImplementedError('onMessage is not implemented');
         }
 
@@ -248,7 +248,7 @@ export default function ModelWithMessages(BaseModel) {
 
         /**
          * Queue an incoming `chat` message stanza for processing.
-         * @param {Promise<MessageAttributes>} attrs - A promise which resolves to the message attributes
+         * @param {MessageAttributes} attrs - A promise which resolves to the message attributes
          */
         queueMessage(attrs) {
             this.msg_chain = (this.msg_chain || this.messages.fetched)

+ 1 - 0
src/headless/shared/parsers.js

@@ -63,6 +63,7 @@ export function getStanzaIDs (stanza, original_stanza) {
 
 /**
  * @param {Element} stanza
+ * @returns {import('./types').EncryptionAttrs}
  */
 export function getEncryptionAttributes (stanza) {
     const eme_tag = sizzle(`encryption[xmlns="${Strophe.NS.EME}"]`, stanza).pop();

+ 11 - 0
src/headless/shared/types.ts

@@ -7,3 +7,14 @@ import { Model } from '@converse/skeletor';
 type Constructor<T = {}> = new (...args: any[]) => T;
 
 export type ModelExtender = Constructor<Model>;
+
+type EncryptionPayloadAttrs = {
+    prekey?: boolean;
+    device_id: string;
+};
+
+export type EncryptionAttrs = {
+    encrypted?: EncryptionPayloadAttrs; //  XEP-0384 encryption payload attributes
+    is_encrypted: boolean;
+    encryption_namespace: string;
+};

+ 14 - 14
src/headless/types/plugins/chat/model.d.ts

@@ -17,13 +17,13 @@ declare const ChatBox_base: {
         messages: any;
         fetchMessages(): any;
         afterMessagesFetched(): void;
-        onMessage(_promise: Promise<import("./parsers").MessageAttributes>): Promise<void>;
-        getUpdatedMessageAttributes(message: import("./message.js").default, attrs: import("./parsers").MessageAttributes): object;
-        updateMessage(message: import("./message.js").default, attrs: import("./parsers").MessageAttributes): void;
-        handleCorrection(attrs: import("./parsers").MessageAttributes | import("../muc/parsers.js").MUCMessageAttributes): Promise<import("./message.js").default | void>;
-        queueMessage(attrs: Promise<import("./parsers").MessageAttributes>): any;
+        onMessage(attrs_or_error: import("./types.ts").MessageAttributes | Error): Promise<void>;
+        getUpdatedMessageAttributes(message: import("./message.js").default, attrs: import("./types.ts").MessageAttributes): object;
+        updateMessage(message: import("./message.js").default, attrs: import("./types.ts").MessageAttributes): void;
+        handleCorrection(attrs: import("./types.ts").MessageAttributes | import("../muc/types.js").MUCMessageAttributes): Promise<import("./message.js").default | void>;
+        queueMessage(attrs: import("./types.ts").MessageAttributes): any;
         msg_chain: any;
-        getOutgoingMessageAttributes(_attrs?: import("./parsers").MessageAttributes): Promise<import("./parsers").MessageAttributes>;
+        getOutgoingMessageAttributes(_attrs?: import("./types.ts").MessageAttributes): Promise<import("./types.ts").MessageAttributes>;
         sendMessage(attrs?: any): Promise<import("./message.js").default>;
         retractOwnMessage(message: import("./message.js").default): void;
         sendFiles(files: File[]): Promise<void>;
@@ -34,7 +34,7 @@ declare const ChatBox_base: {
         onMessageUploadChanged(message: import("./message.js").default): Promise<void>;
         onScrolledChanged(): void;
         pruneHistoryWhenScrolledDown(): void;
-        shouldShowErrorMessage(attrs: import("./parsers").MessageAttributes): Promise<boolean>;
+        shouldShowErrorMessage(attrs: import("./types.ts").MessageAttributes): Promise<boolean>;
         clearMessages(): Promise<void>;
         editEarlierMessage(): void;
         editLaterMessage(): any;
@@ -57,8 +57,8 @@ declare const ChatBox_base: {
         handleErrorMessageStanza(stanza: Element): Promise<void>;
         incrementUnreadMsgsCounter(message: import("./message.js").default): void;
         clearUnreadMsgCounter(): void;
-        handleRetraction(attrs: import("./parsers").MessageAttributes): Promise<boolean>;
-        handleReceipt(attrs: import("./parsers").MessageAttributes): boolean;
+        handleRetraction(attrs: import("./types.ts").MessageAttributes): Promise<boolean>;
+        handleReceipt(attrs: import("./types.ts").MessageAttributes): boolean;
         createMessageStanza(message: import("./message.js").default): Promise<any>;
         pruneHistory(): void;
         debouncedPruneHistory: import("lodash").DebouncedFunc<() => void>;
@@ -273,7 +273,7 @@ declare class ChatBox extends ChatBox_base {
     /**
      * @typedef {import('./message.js').default} Message
      * @typedef {import('../muc/muc.js').default} MUC
-     * @typedef {import('./parsers').MessageAttributes} MessageAttributes
+     * @typedef {import('./types.ts').MessageAttributes} MessageAttributes
      * @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError
      */
     defaults(): {
@@ -289,9 +289,9 @@ declare class ChatBox extends ChatBox_base {
     initialized: any;
     presence: any;
     /**
-     * @param {Promise<MessageAttributes|StanzaParseError>} attrs_promise
+     * @param {MessageAttributes|StanzaParseError} attrs_or_error
      */
-    onMessage(attrs_promise: Promise<import("./parsers").MessageAttributes | import("../../shared/parsers").StanzaParseError>): Promise<void>;
+    onMessage(attrs_or_error: import("./types.ts").MessageAttributes | import("../../shared/parsers").StanzaParseError): Promise<void>;
     onPresenceChanged(item: any): void;
     close(): Promise<void>;
     /**
@@ -306,12 +306,12 @@ declare class ChatBox extends ChatBox_base {
     /**
      * @param {MessageAttributes} attrs
      */
-    handleChatMarker(attrs: import("./parsers").MessageAttributes): boolean;
+    handleChatMarker(attrs: import("./types.ts").MessageAttributes): boolean;
     /**
      * @param {MessageAttributes} [attrs]
      * @return {Promise<MessageAttributes>}
      */
-    getOutgoingMessageAttributes(attrs?: import("./parsers").MessageAttributes): Promise<import("./parsers").MessageAttributes>;
+    getOutgoingMessageAttributes(attrs?: import("./types.ts").MessageAttributes): Promise<import("./types.ts").MessageAttributes>;
     canPostMessages(): boolean;
 }
 import ChatBoxBase from '../../shared/chatbox.js';

+ 3 - 248
src/headless/types/plugins/chat/parsers.d.ts

@@ -1,253 +1,8 @@
-/**
- * The object which {@link parseMessage} returns
- * @typedef {Object} MessageAttributes
- * @property {('me'|'them')} sender - Whether the message was sent by the current user or someone else
- * @property {Array<Object>} references - A list of objects representing XEP-0372 references
- * @property {Boolean} editable - Is this message editable via XEP-0308?
- * @property {Boolean} is_archived -  Is this message from a XEP-0313 MAM archive?
- * @property {Boolean} is_carbon - Is this message a XEP-0280 Carbon?
- * @property {Boolean} is_delayed - Was delivery of this message was delayed as per XEP-0203?
- * @property {Boolean} is_encrypted -  Is this message XEP-0384  encrypted?
- * @property {Boolean} is_error - Whether an error was received for this message
- * @property {Boolean} is_headline - Is this a "headline" message?
- * @property {Boolean} is_markable - Can this message be marked with a XEP-0333 chat marker?
- * @property {Boolean} is_marker - Is this message a XEP-0333 Chat Marker?
- * @property {Boolean} is_only_emojis - Does the message body contain only emojis?
- * @property {Boolean} is_spoiler - Is this a XEP-0382 spoiler message?
- * @property {Boolean} is_tombstone - Is this a XEP-0424 tombstone?
- * @property {Boolean} is_unstyled - Whether XEP-0393 styling hints should be ignored
- * @property {Boolean} is_valid_receipt_request - Does this message request a XEP-0184 receipt (and is not from us or a carbon or archived message)
- * @property {Object} encrypted -  XEP-0384 encryption payload attributes
- * @property {String} body - The contents of the <body> tag of the message stanza
- * @property {String} chat_state - The XEP-0085 chat state notification contained in this message
- * @property {String} contact_jid - The JID of the other person or entity
- * @property {String} edited - An ISO8601 string recording the time that the message was edited per XEP-0308
- * @property {String} error - The error name
- * @property {String} error_condition - The defined error condition
- * @property {String} error_text - The error text received from the server
- * @property {String} error_type - The type of error received from the server
- * @property {String} from - The sender JID
- * @property {String} fullname - The full name of the sender
- * @property {String} marker - The XEP-0333 Chat Marker value
- * @property {String} marker_id - The `id` attribute of a XEP-0333 chat marker
- * @property {String} msgid - The root `id` attribute of the stanza
- * @property {String} nick - The roster nickname of the sender
- * @property {String} oob_desc - The description of the XEP-0066 out of band data
- * @property {String} oob_url - The URL of the XEP-0066 out of band data
- * @property {String} origin_id - The XEP-0359 Origin ID
- * @property {String} plaintext - The decrypted text of this message, in case it was encrypted.
- * @property {String} receipt_id - The `id` attribute of a XEP-0184 <receipt> element
- * @property {String} received - An ISO8601 string recording the time that the message was received
- * @property {String} replace_id - The `id` attribute of a XEP-0308 <replace> element
- * @property {String} retracted - An ISO8601 string recording the time that the message was retracted
- * @property {String} retracted_id - The `id` attribute of a XEP-424 <retracted> element
- * @property {String} spoiler_hint  The XEP-0382 spoiler hint
- * @property {String} stanza_id - The XEP-0359 Stanza ID. Note: the key is actualy `stanza_id ${by_jid}` and there can be multiple.
- * @property {String} subject - The <subject> element value
- * @property {String} thread - The <thread> element value
- * @property {String} time - The time (in ISO8601 format), either given by the XEP-0203 <delay> element, or of receipt.
- * @property {String} to - The recipient JID
- * @property {String} type - The type of message
- */
 /**
  * Parses a passed in message stanza and returns an object of attributes.
- * @method st#parseMessage
- * @param { Element } stanza - The message stanza
- * @returns { Promise<MessageAttributes|StanzaParseError> }
- */
-export function parseMessage(stanza: Element): Promise<MessageAttributes | StanzaParseError>;
-/**
- * The object which {@link parseMessage} returns
+ * @param {Element} stanza - The message stanza
+ * @returns {Promise<import('./types.ts').MessageAttributes|StanzaParseError>}
  */
-export type MessageAttributes = {
-    /**
-     * - Whether the message was sent by the current user or someone else
-     */
-    sender: ("me" | "them");
-    /**
-     * - A list of objects representing XEP-0372 references
-     */
-    references: Array<any>;
-    /**
-     * - Is this message editable via XEP-0308?
-     */
-    editable: boolean;
-    /**
-     * -  Is this message from a XEP-0313 MAM archive?
-     */
-    is_archived: boolean;
-    /**
-     * - Is this message a XEP-0280 Carbon?
-     */
-    is_carbon: boolean;
-    /**
-     * - Was delivery of this message was delayed as per XEP-0203?
-     */
-    is_delayed: boolean;
-    /**
-     * -  Is this message XEP-0384  encrypted?
-     */
-    is_encrypted: boolean;
-    /**
-     * - Whether an error was received for this message
-     */
-    is_error: boolean;
-    /**
-     * - Is this a "headline" message?
-     */
-    is_headline: boolean;
-    /**
-     * - Can this message be marked with a XEP-0333 chat marker?
-     */
-    is_markable: boolean;
-    /**
-     * - Is this message a XEP-0333 Chat Marker?
-     */
-    is_marker: boolean;
-    /**
-     * - Does the message body contain only emojis?
-     */
-    is_only_emojis: boolean;
-    /**
-     * - Is this a XEP-0382 spoiler message?
-     */
-    is_spoiler: boolean;
-    /**
-     * - Is this a XEP-0424 tombstone?
-     */
-    is_tombstone: boolean;
-    /**
-     * - Whether XEP-0393 styling hints should be ignored
-     */
-    is_unstyled: boolean;
-    /**
-     * - Does this message request a XEP-0184 receipt (and is not from us or a carbon or archived message)
-     */
-    is_valid_receipt_request: boolean;
-    /**
-     * -  XEP-0384 encryption payload attributes
-     */
-    encrypted: any;
-    /**
-     * - The contents of the <body> tag of the message stanza
-     */
-    body: string;
-    /**
-     * - The XEP-0085 chat state notification contained in this message
-     */
-    chat_state: string;
-    /**
-     * - The JID of the other person or entity
-     */
-    contact_jid: string;
-    /**
-     * - An ISO8601 string recording the time that the message was edited per XEP-0308
-     */
-    edited: string;
-    /**
-     * - The error name
-     */
-    error: string;
-    /**
-     * - The defined error condition
-     */
-    error_condition: string;
-    /**
-     * - The error text received from the server
-     */
-    error_text: string;
-    /**
-     * - The type of error received from the server
-     */
-    error_type: string;
-    /**
-     * - The sender JID
-     */
-    from: string;
-    /**
-     * - The full name of the sender
-     */
-    fullname: string;
-    /**
-     * - The XEP-0333 Chat Marker value
-     */
-    marker: string;
-    /**
-     * - The `id` attribute of a XEP-0333 chat marker
-     */
-    marker_id: string;
-    /**
-     * - The root `id` attribute of the stanza
-     */
-    msgid: string;
-    /**
-     * - The roster nickname of the sender
-     */
-    nick: string;
-    /**
-     * - The description of the XEP-0066 out of band data
-     */
-    oob_desc: string;
-    /**
-     * - The URL of the XEP-0066 out of band data
-     */
-    oob_url: string;
-    /**
-     * - The XEP-0359 Origin ID
-     */
-    origin_id: string;
-    /**
-     * - The decrypted text of this message, in case it was encrypted.
-     */
-    plaintext: string;
-    /**
-     * - The `id` attribute of a XEP-0184 <receipt> element
-     */
-    receipt_id: string;
-    /**
-     * - An ISO8601 string recording the time that the message was received
-     */
-    received: string;
-    /**
-     * - The `id` attribute of a XEP-0308 <replace> element
-     */
-    replace_id: string;
-    /**
-     * - An ISO8601 string recording the time that the message was retracted
-     */
-    retracted: string;
-    /**
-     * - The `id` attribute of a XEP-424 <retracted> element
-     */
-    retracted_id: string;
-    /**
-     * The XEP-0382 spoiler hint
-     */
-    spoiler_hint: string;
-    /**
-     * - The XEP-0359 Stanza ID. Note: the key is actualy `stanza_id ${by_jid}` and there can be multiple.
-     */
-    stanza_id: string;
-    /**
-     * - The <subject> element value
-     */
-    subject: string;
-    /**
-     * - The <thread> element value
-     */
-    thread: string;
-    /**
-     * - The time (in ISO8601 format), either given by the XEP-0203 <delay> element, or of receipt.
-     */
-    time: string;
-    /**
-     * - The recipient JID
-     */
-    to: string;
-    /**
-     * - The type of message
-     */
-    type: string;
-};
+export function parseMessage(stanza: Element): Promise<import("./types.ts").MessageAttributes | StanzaParseError>;
 import { StanzaParseError } from '../../shared/parsers';
 //# sourceMappingURL=parsers.d.ts.map

+ 52 - 0
src/headless/types/plugins/chat/types.d.ts

@@ -0,0 +1,52 @@
+import { EncryptionAttrs } from "../../shared/types";
+export type MessageAttributes = EncryptionAttrs & {
+    body: string;
+    chat_state: string;
+    contact_jid: string;
+    editable: boolean;
+    edited: string;
+    error: string;
+    error_condition: string;
+    error_text: string;
+    error_type: string;
+    from: string;
+    message?: string;
+    fullname: string;
+    is_archived: boolean;
+    is_carbon: boolean;
+    is_delayed: boolean;
+    is_encrypted: boolean;
+    is_error: boolean;
+    is_headline: boolean;
+    is_markable: boolean;
+    is_marker: boolean;
+    is_only_emojis: boolean;
+    is_spoiler: boolean;
+    is_tombstone: boolean;
+    is_unstyled: boolean;
+    is_valid_receipt_request: boolean;
+    marker: string;
+    marker_id: string;
+    msgid: string;
+    nick: string;
+    ogp_for_id?: string;
+    oob_desc: string;
+    oob_url: string;
+    origin_id: string;
+    plaintext: string;
+    receipt_id: string;
+    received: string;
+    references: Array<Object>;
+    replace_id: string;
+    retracted: string;
+    retracted_id: string;
+    sender: 'me' | 'them';
+    spoiler_hint: string;
+    stanza_id: string;
+    subject: string;
+    thread: string;
+    time: string;
+    to: string;
+    type: string;
+};
+//# sourceMappingURL=types.d.ts.map

+ 1 - 1
src/headless/types/plugins/chat/utils.d.ts

@@ -19,7 +19,7 @@ export function handleMessageStanza(stanza: Element | Builder): Promise<true | v
  */
 export function enableCarbons(): Promise<void>;
 export type ChatBox = import("./model.js").default;
-export type MessageAttributes = import("./parsers").MessageAttributes;
+export type MessageAttributes = import("./types.ts").MessageAttributes;
 export type StanzaParseError = import("../../shared/parsers").StanzaParseError;
 export type Builder = import("strophe.js").Builder;
 import { Model } from '@converse/skeletor';

+ 19 - 19
src/headless/types/plugins/muc/muc.d.ts

@@ -17,13 +17,13 @@ declare const MUC_base: {
         messages: any;
         fetchMessages(): any;
         afterMessagesFetched(): void;
-        onMessage(_promise: Promise<import("../chat/parsers").MessageAttributes>): Promise<void>;
-        getUpdatedMessageAttributes(message: import("../chat/message.js").default, attrs: import("../chat/parsers").MessageAttributes): object;
-        updateMessage(message: import("../chat/message.js").default, attrs: import("../chat/parsers").MessageAttributes): void;
-        handleCorrection(attrs: import("../chat/parsers").MessageAttributes | import("./parsers.js").MUCMessageAttributes): Promise<import("../chat/message.js").default | void>;
-        queueMessage(attrs: Promise<import("../chat/parsers").MessageAttributes>): any;
+        onMessage(attrs_or_error: import("../chat/types.ts").MessageAttributes | Error): Promise<void>;
+        getUpdatedMessageAttributes(message: import("../chat/message.js").default, attrs: import("../chat/types.ts").MessageAttributes): object;
+        updateMessage(message: import("../chat/message.js").default, attrs: import("../chat/types.ts").MessageAttributes): void;
+        handleCorrection(attrs: import("../chat/types.ts").MessageAttributes | import("./types.ts").MUCMessageAttributes): Promise<import("../chat/message.js").default | void>;
+        queueMessage(attrs: import("../chat/types.ts").MessageAttributes): any;
         msg_chain: any;
-        getOutgoingMessageAttributes(_attrs?: import("../chat/parsers").MessageAttributes): Promise<import("../chat/parsers").MessageAttributes>;
+        getOutgoingMessageAttributes(_attrs?: import("../chat/types.ts").MessageAttributes): Promise<import("../chat/types.ts").MessageAttributes>;
         sendMessage(attrs?: any): Promise<import("../chat/message.js").default>;
         retractOwnMessage(message: import("../chat/message.js").default): void;
         sendFiles(files: File[]): Promise<void>;
@@ -34,7 +34,7 @@ declare const MUC_base: {
         onMessageUploadChanged(message: import("../chat/message.js").default): Promise<void>;
         onScrolledChanged(): void;
         pruneHistoryWhenScrolledDown(): void;
-        shouldShowErrorMessage(attrs: import("../chat/parsers").MessageAttributes): Promise<boolean>;
+        shouldShowErrorMessage(attrs: import("../chat/types.ts").MessageAttributes): Promise<boolean>;
         clearMessages(): Promise<void>;
         editEarlierMessage(): void;
         editLaterMessage(): any;
@@ -57,8 +57,8 @@ declare const MUC_base: {
         handleErrorMessageStanza(stanza: Element): Promise<void>;
         incrementUnreadMsgsCounter(message: import("../chat/message.js").default): void;
         clearUnreadMsgCounter(): void;
-        handleRetraction(attrs: import("../chat/parsers").MessageAttributes): Promise<boolean>;
-        handleReceipt(attrs: import("../chat/parsers").MessageAttributes): boolean;
+        handleRetraction(attrs: import("../chat/types.ts").MessageAttributes): Promise<boolean>;
+        handleReceipt(attrs: import("../chat/types.ts").MessageAttributes): boolean;
         createMessageStanza(message: import("../chat/message.js").default): Promise<any>;
         pruneHistory(): void;
         debouncedPruneHistory: import("lodash").DebouncedFunc<() => void>;
@@ -207,8 +207,8 @@ declare class MUC extends MUC_base {
      * @typedef {import('./occupant.js').default} MUCOccupant
      * @typedef {import('./affiliations/utils.js').NonOutcastAffiliation} NonOutcastAffiliation
      * @typedef {import('./parsers').MemberListItem} MemberListItem
-     * @typedef {module:plugin-chat-parsers.MessageAttributes} MessageAttributes
-     * @typedef {import('./parsers').MUCMessageAttributes} MUCMessageAttributes
+     * @typedef {import('../chat/types.ts').MessageAttributes} MessageAttributes
+     * @typedef {import('./types.ts').MUCMessageAttributes} MUCMessageAttributes
      * @typedef {module:shared.converse.UserMessage} UserMessage
      * @typedef {import('strophe.js').Builder} Builder
      * @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError
@@ -430,7 +430,7 @@ declare class MUC extends MUC_base {
     /**
      * @param {MessageAttributes} [attrs] - A map of attributes to be saved on the message
      */
-    getOutgoingMessageAttributes(attrs?: any): Promise<any>;
+    getOutgoingMessageAttributes(attrs?: import("../chat/types.ts").MessageAttributes): Promise<import("../chat/types.ts").MessageAttributes>;
     /**
      * Utility method to construct the JID for the current user as occupant of the groupchat.
      * @returns {string} - The groupchat JID with the user's nickname added at the end.
@@ -664,7 +664,7 @@ declare class MUC extends MUC_base {
      * @param {MUCMessageAttributes} attrs
      * @return {object}
      */
-    getUpdatedMessageAttributes(message: import("./message.js").default, attrs: import("./parsers.js").MUCMessageAttributes): object;
+    getUpdatedMessageAttributes(message: import("./message.js").default, attrs: import("./types.ts").MUCMessageAttributes): object;
     /**
      * Send a MUC-0410 MUC Self-Ping stanza to room to determine
      * whether we're still joined.
@@ -727,19 +727,19 @@ declare class MUC extends MUC_base {
      * @param {MessageAttributes} attrs
      * @returns {boolean}
      */
-    handleMUCPrivateMessage(attrs: any): boolean;
+    handleMUCPrivateMessage(attrs: import("../chat/types.ts").MessageAttributes): boolean;
     /**
      * @param {MessageAttributes} attrs
      * @returns {boolean}
      */
-    handleMetadataFastening(attrs: any): boolean;
+    handleMetadataFastening(attrs: import("../chat/types.ts").MessageAttributes): boolean;
     /**
      * Given {@link MessageAttributes} look for XEP-0316 Room Notifications and create info
      * messages for them.
-     * @param {MessageAttributes} attrs
+     * @param {MUCMessageAttributes} attrs
      * @returns {boolean}
      */
-    handleMEPNotification(attrs: any): boolean;
+    handleMEPNotification(attrs: import("./types.ts").MUCMessageAttributes): boolean;
     /**
      * Returns an already cached message (if it exists) based on the
      * passed in attributes map.
@@ -752,9 +752,9 @@ declare class MUC extends MUC_base {
      * Handler for all MUC messages sent to this groupchat. This method
      * shouldn't be called directly, instead {@link MUC#queueMessage}
      * should be called.
-     * @param {Promise<MessageAttributes>} promise - A promise which resolves to the message attributes.
+     * @param {MUCMessageAttributes|StanzaParseError} attrs_or_error - A promise which resolves to the message attributes.
      */
-    onMessage(promise: Promise<any>): Promise<void>;
+    onMessage(attrs_or_error: import("./types.ts").MUCMessageAttributes | import("../../shared/parsers.js").StanzaParseError): Promise<void>;
     /**
      * @param {Element} pres
      */

+ 13 - 17
src/headless/types/plugins/muc/occupant.d.ts

@@ -17,13 +17,13 @@ declare const MUCOccupant_base: {
         messages: any;
         fetchMessages(): any;
         afterMessagesFetched(): void;
-        onMessage(_promise: Promise<import("../chat/parsers").MessageAttributes>): Promise<void>;
-        getUpdatedMessageAttributes(message: import("../chat").Message, attrs: import("../chat/parsers").MessageAttributes): object;
-        updateMessage(message: import("../chat").Message, attrs: import("../chat/parsers").MessageAttributes): void;
-        handleCorrection(attrs: import("../chat/parsers").MessageAttributes | import("./parsers").MUCMessageAttributes): Promise<import("../chat").Message | void>;
-        queueMessage(attrs: Promise<import("../chat/parsers").MessageAttributes>): any;
+        onMessage(attrs_or_error: import("../chat/types.ts").MessageAttributes | Error): Promise<void>;
+        getUpdatedMessageAttributes(message: import("../chat").Message, attrs: import("../chat/types.ts").MessageAttributes): object;
+        updateMessage(message: import("../chat").Message, attrs: import("../chat/types.ts").MessageAttributes): void;
+        handleCorrection(attrs: import("../chat/types.ts").MessageAttributes | import("./types").MUCMessageAttributes): Promise<import("../chat").Message | void>;
+        queueMessage(attrs: import("../chat/types.ts").MessageAttributes): any;
         msg_chain: any;
-        getOutgoingMessageAttributes(_attrs?: import("../chat/parsers").MessageAttributes): Promise<import("../chat/parsers").MessageAttributes>;
+        getOutgoingMessageAttributes(_attrs?: import("../chat/types.ts").MessageAttributes): Promise<import("../chat/types.ts").MessageAttributes>;
         sendMessage(attrs?: any): Promise<import("../chat").Message>;
         retractOwnMessage(message: import("../chat").Message): void;
         sendFiles(files: File[]): Promise<void>;
@@ -34,7 +34,7 @@ declare const MUCOccupant_base: {
         onMessageUploadChanged(message: import("../chat").Message): Promise<void>;
         onScrolledChanged(): void;
         pruneHistoryWhenScrolledDown(): void;
-        shouldShowErrorMessage(attrs: import("../chat/parsers").MessageAttributes): Promise<boolean>;
+        shouldShowErrorMessage(attrs: import("../chat/types.ts").MessageAttributes): Promise<boolean>;
         clearMessages(): Promise<void>;
         editEarlierMessage(): void;
         editLaterMessage(): any;
@@ -57,8 +57,8 @@ declare const MUCOccupant_base: {
         handleErrorMessageStanza(stanza: Element): Promise<void>;
         incrementUnreadMsgsCounter(message: import("../chat").Message): void;
         clearUnreadMsgCounter(): void;
-        handleRetraction(attrs: import("../chat/parsers").MessageAttributes): Promise<boolean>;
-        handleReceipt(attrs: import("../chat/parsers").MessageAttributes): boolean;
+        handleRetraction(attrs: import("../chat/types.ts").MessageAttributes): Promise<boolean>;
+        handleReceipt(attrs: import("../chat/types.ts").MessageAttributes): boolean;
         createMessageStanza(message: import("../chat").Message): Promise<any>;
         pruneHistory(): void;
         debouncedPruneHistory: import("lodash").DebouncedFunc<() => void>;
@@ -201,7 +201,8 @@ declare const MUCOccupant_base: {
  */
 declare class MUCOccupant extends MUCOccupant_base {
     /**
-     * @typedef {module:plugin-chat-parsers.MessageAttributes} MessageAttributes
+     * @typedef {import('../chat/types.ts').MessageAttributes} MessageAttributes
+     * @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError
      */
     constructor(attributes: any, options: any);
     vcard: any;
@@ -218,9 +219,9 @@ declare class MUCOccupant extends MUCOccupant_base {
     /**
      * Handler for all MUC private messages sent to this occupant.
      * This method houldn't be called directly, instead {@link MUC#queueMessage} should be called.
-     * @param {Promise<MessageAttributes>} promise
+     * @param {MessageAttributes|StanzaParseError} attrs_or_error
      */
-    onMessage(promise: Promise<any>): Promise<void>;
+    onMessage(attrs_or_error: import("../chat/types.ts").MessageAttributes | import("../../shared/parsers").StanzaParseError): Promise<void>;
     /**
      * Return roles which may be assigned to this occupant
      * @returns {typeof ROLES} - An array of assignable roles
@@ -234,11 +235,6 @@ declare class MUCOccupant extends MUCOccupant_base {
     isMember(): boolean;
     isModerator(): boolean;
     isSelf(): any;
-    /**
-     * @param {MessageAttributes} [attrs]
-     * @return {Promise<MessageAttributes>}
-     */
-    getOutgoingMessageAttributes(attrs?: any): Promise<any>;
 }
 import { Model } from '@converse/skeletor';
 import MUCMessages from './messages.js';

+ 1 - 51
src/headless/types/plugins/muc/parsers.d.ts

@@ -1,17 +1,3 @@
-/**
- * @typedef {Object} ExtraMUCAttributes
- * @property {Array<Object>} activities - A list of objects representing XEP-0316 MEP notification data
- * @property {String} from_muc - The JID of the MUC from which this message was sent
- * @property {String} from_real_jid - The real JID of the sender, if available
- * @property {String} moderated - The type of XEP-0425 moderation (if any) that was applied
- * @property {String} moderated_by - The JID of the user that moderated this message
- * @property {String} moderated_id - The  XEP-0359 Stanza ID of the message that this one moderates
- * @property {String} moderation_reason - The reason provided why this message moderates another
- * @property {String} occupant_id - The XEP-0421 occupant ID
- *
- * The object which {@link parseMUCMessage} returns
- * @typedef {import('../chat/parsers').MessageAttributes & ExtraMUCAttributes} MUCMessageAttributes
- */
 /**
  * Parses a message stanza for XEP-0316 MEP notification data
  * @param {Element} stanza - The message stanza
@@ -79,43 +65,6 @@ export function parseMUCPresence(stanza: Element, chatbox: MUC): {
     jid?: string;
     is_me?: boolean;
 };
-export type ExtraMUCAttributes = {
-    /**
-     * - A list of objects representing XEP-0316 MEP notification data
-     */
-    activities: Array<any>;
-    /**
-     * - The JID of the MUC from which this message was sent
-     */
-    from_muc: string;
-    /**
-     * - The real JID of the sender, if available
-     */
-    from_real_jid: string;
-    /**
-     * - The type of XEP-0425 moderation (if any) that was applied
-     */
-    moderated: string;
-    /**
-     * - The JID of the user that moderated this message
-     */
-    moderated_by: string;
-    /**
-     * - The  XEP-0359 Stanza ID of the message that this one moderates
-     */
-    moderated_id: string;
-    /**
-     * - The reason provided why this message moderates another
-     */
-    moderation_reason: string;
-    /**
-     * - The XEP-0421 occupant ID
-     *
-     * The object which {@link parseMUCMessage} returns
-     */
-    occupant_id: string;
-};
-export type MUCMessageAttributes = import("../chat/parsers").MessageAttributes & ExtraMUCAttributes;
 /**
  * Either the JID or the nickname (or both) will be available.
  */
@@ -126,5 +75,6 @@ export type MemberListItem = {
     nick?: string;
 };
 export type MUC = import("../muc/muc.js").default;
+export type MUCMessageAttributes = import("./types.ts").MUCMessageAttributes;
 import { StanzaParseError } from '../../shared/parsers';
 //# sourceMappingURL=parsers.d.ts.map

+ 14 - 0
src/headless/types/plugins/muc/types.d.ts

@@ -0,0 +1,14 @@
+import { MessageAttributes } from '../chat/types';
+type ExtraMUCAttributes = {
+    activities: Array<Object>;
+    from_muc: string;
+    from_real_jid: string;
+    moderated: string;
+    moderated_by: string;
+    moderated_id: string;
+    moderation_reason: string;
+    occupant_id: string;
+};
+export type MUCMessageAttributes = MessageAttributes & ExtraMUCAttributes;
+export {};
+//# sourceMappingURL=types.d.ts.map

+ 9 - 9
src/headless/types/shared/chatbox.d.ts

@@ -16,13 +16,13 @@ declare const ChatBoxBase_base: {
         messages: any;
         fetchMessages(): any;
         afterMessagesFetched(): void;
-        onMessage(_promise: Promise<import("../plugins/chat/parsers.js").MessageAttributes>): Promise<void>;
-        getUpdatedMessageAttributes(message: import("../index.js").Message, attrs: import("../plugins/chat/parsers.js").MessageAttributes): object;
-        updateMessage(message: import("../index.js").Message, attrs: import("../plugins/chat/parsers.js").MessageAttributes): void;
-        handleCorrection(attrs: import("../plugins/chat/parsers.js").MessageAttributes | import("../plugins/muc/parsers.js").MUCMessageAttributes): Promise<import("../index.js").Message | void>;
-        queueMessage(attrs: Promise<import("../plugins/chat/parsers.js").MessageAttributes>): any;
+        onMessage(attrs_or_error: import("../plugins/chat/types.js").MessageAttributes | Error): Promise<void>;
+        getUpdatedMessageAttributes(message: import("../index.js").Message, attrs: import("../plugins/chat/types.js").MessageAttributes): object;
+        updateMessage(message: import("../index.js").Message, attrs: import("../plugins/chat/types.js").MessageAttributes): void;
+        handleCorrection(attrs: import("../plugins/chat/types.js").MessageAttributes | import("../plugins/muc/types.js").MUCMessageAttributes): Promise<import("../index.js").Message | void>;
+        queueMessage(attrs: import("../plugins/chat/types.js").MessageAttributes): any;
         msg_chain: any;
-        getOutgoingMessageAttributes(_attrs?: import("../plugins/chat/parsers.js").MessageAttributes): Promise<import("../plugins/chat/parsers.js").MessageAttributes>;
+        getOutgoingMessageAttributes(_attrs?: import("../plugins/chat/types.js").MessageAttributes): Promise<import("../plugins/chat/types.js").MessageAttributes>;
         sendMessage(attrs?: any): Promise<import("../index.js").Message>;
         retractOwnMessage(message: import("../index.js").Message): void;
         sendFiles(files: File[]): Promise<void>;
@@ -33,7 +33,7 @@ declare const ChatBoxBase_base: {
         onMessageUploadChanged(message: import("../index.js").Message): Promise<void>;
         onScrolledChanged(): void;
         pruneHistoryWhenScrolledDown(): void;
-        shouldShowErrorMessage(attrs: import("../plugins/chat/parsers.js").MessageAttributes): Promise<boolean>;
+        shouldShowErrorMessage(attrs: import("../plugins/chat/types.js").MessageAttributes): Promise<boolean>;
         clearMessages(): Promise<void>;
         editEarlierMessage(): void;
         editLaterMessage(): any;
@@ -56,8 +56,8 @@ declare const ChatBoxBase_base: {
         handleErrorMessageStanza(stanza: Element): Promise<void>;
         incrementUnreadMsgsCounter(message: import("../index.js").Message): void;
         clearUnreadMsgCounter(): void;
-        handleRetraction(attrs: import("../plugins/chat/parsers.js").MessageAttributes): Promise<boolean>;
-        handleReceipt(attrs: import("../plugins/chat/parsers.js").MessageAttributes): boolean;
+        handleRetraction(attrs: import("../plugins/chat/types.js").MessageAttributes): Promise<boolean>;
+        handleReceipt(attrs: import("../plugins/chat/types.js").MessageAttributes): boolean;
         createMessageStanza(message: import("../index.js").Message): Promise<any>;
         pruneHistory(): void;
         debouncedPruneHistory: import("lodash").DebouncedFunc<() => void>;

+ 11 - 11
src/headless/types/shared/model-with-messages.d.ts

@@ -38,20 +38,20 @@ export default function ModelWithMessages<T extends import("./types").ModelExten
         fetchMessages(): any;
         afterMessagesFetched(): void;
         /**
-         * @param {Promise<MessageAttributes>} _promise
+         * @param {MessageAttributes|Error} attrs_or_error
          */
-        onMessage(_promise: Promise<import("../plugins/chat/parsers").MessageAttributes>): Promise<void>;
+        onMessage(attrs_or_error: import("../plugins/chat/types.ts").MessageAttributes | Error): Promise<void>;
         /**
          * @param {Message} message
          * @param {MessageAttributes} attrs
          * @returns {object}
          */
-        getUpdatedMessageAttributes(message: import("../plugins/chat/message").default, attrs: import("../plugins/chat/parsers").MessageAttributes): object;
+        getUpdatedMessageAttributes(message: import("../plugins/chat/message").default, attrs: import("../plugins/chat/types.ts").MessageAttributes): object;
         /**
          * @param {Message} message
          * @param {MessageAttributes} attrs
          */
-        updateMessage(message: import("../plugins/chat/message").default, attrs: import("../plugins/chat/parsers").MessageAttributes): void;
+        updateMessage(message: import("../plugins/chat/message").default, attrs: import("../plugins/chat/types.ts").MessageAttributes): void;
         /**
          * Determines whether the given attributes of an incoming message
          * represent a XEP-0308 correction and, if so, handles it appropriately.
@@ -60,18 +60,18 @@ export default function ModelWithMessages<T extends import("./types").ModelExten
          * @returns {Promise<Message|void>} Returns the corrected
          *  message or `undefined` if not applicable.
          */
-        handleCorrection(attrs: import("../plugins/chat/parsers").MessageAttributes | import("../plugins/muc/parsers").MUCMessageAttributes): Promise<import("../plugins/chat/message").default | void>;
+        handleCorrection(attrs: import("../plugins/chat/types.ts").MessageAttributes | import("../plugins/muc/types.js").MUCMessageAttributes): Promise<import("../plugins/chat/message").default | void>;
         /**
          * Queue an incoming `chat` message stanza for processing.
-         * @param {Promise<MessageAttributes>} attrs - A promise which resolves to the message attributes
+         * @param {MessageAttributes} attrs - A promise which resolves to the message attributes
          */
-        queueMessage(attrs: Promise<import("../plugins/chat/parsers").MessageAttributes>): any;
+        queueMessage(attrs: import("../plugins/chat/types.ts").MessageAttributes): any;
         msg_chain: any;
         /**
          * @param {MessageAttributes} [_attrs]
          * @return {Promise<MessageAttributes>}
          */
-        getOutgoingMessageAttributes(_attrs?: import("../plugins/chat/parsers").MessageAttributes): Promise<import("../plugins/chat/parsers").MessageAttributes>;
+        getOutgoingMessageAttributes(_attrs?: import("../plugins/chat/types.ts").MessageAttributes): Promise<import("../plugins/chat/types.ts").MessageAttributes>;
         /**
          * Responsible for sending off a text message inside an ongoing chat conversation.
          * @param {Object} [attrs] - A map of attributes to be saved on the message
@@ -125,7 +125,7 @@ export default function ModelWithMessages<T extends import("./types").ModelExten
          * @param {MessageAttributes} attrs
          * @returns {Promise<boolean>}
          */
-        shouldShowErrorMessage(attrs: import("../plugins/chat/parsers").MessageAttributes): Promise<boolean>;
+        shouldShowErrorMessage(attrs: import("../plugins/chat/types.ts").MessageAttributes): Promise<boolean>;
         clearMessages(): Promise<void>;
         editEarlierMessage(): void;
         editLaterMessage(): any;
@@ -203,11 +203,11 @@ export default function ModelWithMessages<T extends import("./types").ModelExten
          * @returns {Promise<Boolean>} Returns `true` or `false` depending on
          *  whether a message was retracted or not.
          */
-        handleRetraction(attrs: import("../plugins/chat/parsers").MessageAttributes): Promise<boolean>;
+        handleRetraction(attrs: import("../plugins/chat/types.ts").MessageAttributes): Promise<boolean>;
         /**
          * @param {MessageAttributes} attrs
          */
-        handleReceipt(attrs: import("../plugins/chat/parsers").MessageAttributes): boolean;
+        handleReceipt(attrs: import("../plugins/chat/types.ts").MessageAttributes): boolean;
         /**
          * Given a {@link Message} return the XML stanza that represents it.
          * @method ChatBox#createMessageStanza

+ 2 - 4
src/headless/types/shared/parsers.d.ts

@@ -9,11 +9,9 @@
 export function getStanzaIDs(stanza: Element, original_stanza: Element): any;
 /**
  * @param {Element} stanza
+ * @returns {import('./types').EncryptionAttrs}
  */
-export function getEncryptionAttributes(stanza: Element): {
-    is_encrypted: boolean;
-    encryption_namespace: string;
-};
+export function getEncryptionAttributes(stanza: Element): import("./types").EncryptionAttrs;
 /**
  * @param {Element} stanza - The message stanza
  * @param {Element} original_stanza - The original stanza, that contains the

+ 9 - 0
src/headless/types/shared/types.d.ts

@@ -1,5 +1,14 @@
 import { Model } from '@converse/skeletor';
 type Constructor<T = {}> = new (...args: any[]) => T;
 export type ModelExtender = Constructor<Model>;
+type EncryptionPayloadAttrs = {
+    prekey?: boolean;
+    device_id: string;
+};
+export type EncryptionAttrs = {
+    encrypted?: EncryptionPayloadAttrs;
+    is_encrypted: boolean;
+    encryption_namespace: string;
+};
 export {};
 //# sourceMappingURL=types.d.ts.map

+ 4 - 12
src/plugins/modal/api.js

@@ -81,22 +81,14 @@ const modal_api = {
             modals_map = {};
         }
     },
-    /**
-     * @typedef Field
-     * @property { String } Field.label - The form label for the input field.
-     * @property { String } Field.name - The name for the input field.
-     * @property { String } [Field.challenge] - A challenge value that must be provided by the user.
-     * @property { String } [Field.placeholder] - The placeholder for the input field.
-     * @property { Boolean} [Field.required] - Whether the field is required or not
-     */
 
     /**
      * Show a confirm modal to the user.
      * @method _converse.api.confirm
-     * @param { String } title - The header text for the confirmation dialog
-     * @param { (Array<String>|String) } messages - The text to show to the user
-     * @param { Array<Field> } fields - An object representing a fields presented to the user.
-     * @returns { Promise<Array|false> } A promise which resolves with an array of
+     * @param {String} title - The header text for the confirmation dialog
+     * @param {(Array<String>|String)} messages - The text to show to the user
+     * @param {Array<import('./types.ts').Field>} fields - An object representing a field presented to the user.
+     * @returns {Promise<Array|false>} A promise which resolves with an array of
      *  filled in fields or `false` if the confirm dialog was closed or canceled.
      */
     async confirm (title, messages=[], fields=[]) {

+ 7 - 0
src/plugins/modal/types.ts

@@ -0,0 +1,7 @@
+export type Field = {
+    label: string; // The form label for the input field.
+    name: string; // The name for the input field.
+    challenge?: string; // A challenge value that must be provided by the user.
+    placeholder?: string; // The placeholder for the input field.
+    required?: boolean; // Whether the field is required or not
+}

+ 2 - 3
src/plugins/notifications/utils.js

@@ -1,5 +1,5 @@
 /**
- * @typedef {module:headless-plugins-muc-muc.MUCMessageAttributes} MUCMessageAttributes
+ * @typedef {import('@converse/headless/plugins/muc/types').MUCMessageAttributes} MUCMessageAttributes
  * @typedef {module:headless-plugins-muc-muc.MUCMessageData} MUCMessageData
  * @typedef {module:headless-plugins-chat-utils.MessageData} MessageData
  * @typedef {import('@converse/headless').RosterContact} RosterContact
@@ -201,8 +201,7 @@ function showChatStateNotification (contact) {
 
 /**
  * Shows an HTML5 Notification with the passed in message
- * @private
- * @param { MessageData|MUCMessageData } data
+ * @param {MessageData|MUCMessageData} data
  */
 function showMessageNotification (data) {
     const { attrs } = data;

+ 2 - 2
src/plugins/omemo/utils.js

@@ -1,7 +1,7 @@
 /**
  * @typedef {module:plugins-omemo-index.WindowWithLibsignal} WindowWithLibsignal
- * @typedef {module:plugin-chat-parsers.MessageAttributes} MessageAttributes
- * @typedef {module:plugin-muc-parsers.MUCMessageAttributes} MUCMessageAttributes
+ * @typedef {import('@converse/headless/plugins/chat/types.ts').MessageAttributes} MessageAttributes
+ * @typedef {import('@converse/headless/plugins/muc/types').MUCMessageAttributes} MUCMessageAttributes
  * @typedef {import('@converse/headless').ChatBox} ChatBox
  */
 import { html } from 'lit';

+ 5 - 34
src/types/plugins/modal/api.d.ts

@@ -32,45 +32,16 @@ declare namespace modal_api {
          */
         function removeAll(): void;
     }
-    /**
-     * @typedef Field
-     * @property { String } Field.label - The form label for the input field.
-     * @property { String } Field.name - The name for the input field.
-     * @property { String } [Field.challenge] - A challenge value that must be provided by the user.
-     * @property { String } [Field.placeholder] - The placeholder for the input field.
-     * @property { Boolean} [Field.required] - Whether the field is required or not
-     */
     /**
      * Show a confirm modal to the user.
      * @method _converse.api.confirm
-     * @param { String } title - The header text for the confirmation dialog
-     * @param { (Array<String>|String) } messages - The text to show to the user
-     * @param { Array<Field> } fields - An object representing a fields presented to the user.
-     * @returns { Promise<Array|false> } A promise which resolves with an array of
+     * @param {String} title - The header text for the confirmation dialog
+     * @param {(Array<String>|String)} messages - The text to show to the user
+     * @param {Array<import('./types.ts').Field>} fields - An object representing a field presented to the user.
+     * @returns {Promise<Array|false>} A promise which resolves with an array of
      *  filled in fields or `false` if the confirm dialog was closed or canceled.
      */
-    function confirm(title: string, messages?: (Array<string> | string), fields?: Array<{
-        /**
-         * - The form label for the input field.
-         */
-        label: string;
-        /**
-         * - The name for the input field.
-         */
-        name: string;
-        /**
-         * - A challenge value that must be provided by the user.
-         */
-        challenge?: string;
-        /**
-         * - The placeholder for the input field.
-         */
-        placeholder?: string;
-        /**
-         * - Whether the field is required or not
-         */
-        required?: boolean;
-    }>): Promise<any[] | false>;
+    function confirm(title: string, messages?: (Array<string> | string), fields?: Array<import("./types.ts").Field>): Promise<any[] | false>;
     /**
      * Show a prompt modal to the user.
      * @method _converse.api.prompt

+ 8 - 0
src/types/plugins/modal/types.d.ts

@@ -0,0 +1,8 @@
+export type Field = {
+    label: string;
+    name: string;
+    challenge?: string;
+    placeholder?: string;
+    required?: boolean;
+};
+//# sourceMappingURL=types.d.ts.map

+ 1 - 1
src/types/plugins/notifications/utils.d.ts

@@ -32,7 +32,7 @@ export type navigator = Navigator & {
     clearAppBadge: Function;
     setAppBadge: Function;
 };
-export type MUCMessageAttributes = any;
+export type MUCMessageAttributes = import("@converse/headless/plugins/muc/types").MUCMessageAttributes;
 export type MUCMessageData = any;
 export type MessageData = any;
 export type RosterContact = import("@converse/headless").RosterContact;

+ 2 - 2
src/types/plugins/omemo/utils.d.ts

@@ -56,8 +56,8 @@ export namespace omemo {
     export { formatFingerprint };
 }
 export type WindowWithLibsignal = any;
-export type MessageAttributes = any;
-export type MUCMessageAttributes = any;
+export type MessageAttributes = import("@converse/headless/plugins/chat/types.ts").MessageAttributes;
+export type MUCMessageAttributes = import("@converse/headless/plugins/muc/types").MUCMessageAttributes;
 export type ChatBox = import("@converse/headless").ChatBox;
 import { IQError } from 'shared/errors.js';
 import { UserFacingError } from 'shared/errors.js';