Răsfoiți Sursa

Some type improvements

JC Brand 11 luni în urmă
părinte
comite
29689c9c7d

+ 35 - 31
src/headless/plugins/muc/parsers.js

@@ -32,9 +32,9 @@ const { Strophe, sizzle, u } = converse.env;
 const { NS } = Strophe;
 
 /**
- * Parses a message stanza for XEP-0317 MEP notification data
- * @param { Element } stanza - The message stanza
- * @returns { Array } Returns an array of objects representing <activity> elements.
+ * Parses a message stanza for XEP-0316 MEP notification data
+ * @param {Element} stanza - The message stanza
+ * @returns {Array} Returns an array of objects representing <activity> elements.
  */
 export function getMEPActivities (stanza) {
     const items_el = sizzle(`items[node="${Strophe.NS.CONFINFO}"]`, stanza).pop();
@@ -46,7 +46,7 @@ export function getMEPActivities (stanza) {
     const selector = `item `+
         `conference-info[xmlns="${Strophe.NS.CONFINFO}"] `+
         `activity[xmlns="${Strophe.NS.ACTIVITY}"]`;
-    return sizzle(selector, items_el).map(el => {
+    return sizzle(selector, items_el).map(/** @param {Element} el */(el) => {
         const message = el.querySelector('text')?.textContent;
         if (message) {
             const references = getReferences(stanza);
@@ -66,9 +66,8 @@ export function getMEPActivities (stanza) {
  *
  * Note, this function doesn't check whether this is actually a MAM archived stanza.
  *
- * @private
- * @param { Element } stanza - The message stanza
- * @returns { Object }
+ * @param {Element} stanza - The message stanza
+ * @returns {Object}
  */
 function getJIDFromMUCUserData (stanza) {
     const item = sizzle(`x[xmlns="${Strophe.NS.MUC_USER}"] item`, stanza).pop();
@@ -76,7 +75,6 @@ function getJIDFromMUCUserData (stanza) {
 }
 
 /**
- * @private
  * @param {Element} stanza - The message stanza
  *  message stanza, if it was contained, otherwise it's the message stanza itself.
  * @returns {Object}
@@ -116,6 +114,10 @@ function getModerationAttributes (stanza) {
     return {};
 }
 
+/**
+ * @param {Element} stanza
+ * @param {MUC} chatbox
+ */
 function getOccupantID (stanza, chatbox) {
     if (chatbox.features.get(Strophe.NS.OCCUPANTID)) {
         return sizzle(`occupant-id[xmlns="${Strophe.NS.OCCUPANTID}"]`, stanza).pop()?.getAttribute('id');
@@ -311,32 +313,34 @@ export async function parseMUCMessage (stanza, chatbox) {
  * @property {string} [jid]
  * @property {string} [nick]
  *
- * @method muc_utils#parseMemberListIQ
- * @returns { MemberListItem[] }
+ * @param {Element} iq
+ * @returns {MemberListItem[]}
  */
 export function parseMemberListIQ (iq) {
-    return sizzle(`query[xmlns="${Strophe.NS.MUC_ADMIN}"] item`, iq).map(item => {
-        const data = {
-            'affiliation': item.getAttribute('affiliation')
-        };
-        const jid = item.getAttribute('jid');
-        if (u.isValidJID(jid)) {
-            data['jid'] = jid;
-        } else {
-            // XXX: Prosody sends nick for the jid attribute value
-            // Perhaps for anonymous room?
-            data['nick'] = jid;
-        }
-        const nick = item.getAttribute('nick');
-        if (nick) {
-            data['nick'] = nick;
-        }
-        const role = item.getAttribute('role');
-        if (role) {
-            data['role'] = nick;
+    return sizzle(`query[xmlns="${Strophe.NS.MUC_ADMIN}"] item`, iq).map(
+        /** @param {Element} item */ (item) => {
+            const data = {
+                'affiliation': item.getAttribute('affiliation'),
+            };
+            const jid = item.getAttribute('jid');
+            if (u.isValidJID(jid)) {
+                data['jid'] = jid;
+            } else {
+                // XXX: Prosody sends nick for the jid attribute value
+                // Perhaps for anonymous room?
+                data['nick'] = jid;
+            }
+            const nick = item.getAttribute('nick');
+            if (nick) {
+                data['nick'] = nick;
+            }
+            const role = item.getAttribute('role');
+            if (role) {
+                data['role'] = nick;
+            }
+            return data;
         }
-        return data;
-    });
+    );
 }
 
 /**

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

@@ -1,7 +1,7 @@
 /**
- * Parses a message stanza for XEP-0317 MEP notification data
- * @param { Element } stanza - The message stanza
- * @returns { Array } Returns an array of objects representing <activity> elements.
+ * Parses a message stanza for XEP-0316 MEP notification data
+ * @param {Element} stanza - The message stanza
+ * @returns {Array} Returns an array of objects representing <activity> elements.
  */
 export function getMEPActivities(stanza: Element): any[];
 /**
@@ -22,10 +22,10 @@ export function parseMUCMessage(stanza: Element, chatbox: MUC): Promise<MUCMessa
  * @property {string} [jid]
  * @property {string} [nick]
  *
- * @method muc_utils#parseMemberListIQ
- * @returns { MemberListItem[] }
+ * @param {Element} iq
+ * @returns {MemberListItem[]}
  */
-export function parseMemberListIQ(iq: any): MemberListItem[];
+export function parseMemberListIQ(iq: Element): MemberListItem[];
 /**
  * Parses a passed in MUC presence stanza and returns an object of attributes.
  * @method parseMUCPresence

+ 10 - 7
src/plugins/register/panel.js

@@ -343,7 +343,7 @@ class RegisterPanel extends CustomElement {
      * @param {HTMLElement} form - The HTML form that was submitted
      */
     submitRegistrationForm (form) {
-        const inputs = sizzle(':input:not([type=button]):not([type=submit])', form);
+        const /** @type {HTMLInputElement[]} */inputs = sizzle(':input:not([type=button]):not([type=submit])', form);
         const iq = $iq({'type': 'set', 'id': u.getUniqueId()})
                     .c("query", {xmlns:Strophe.NS.REGISTER});
 
@@ -357,7 +357,7 @@ class RegisterPanel extends CustomElement {
         }
 
         const connection = api.connection.get();
-        connection._addSysHandler((iq) => this._onRegisterIQ(iq), null, "iq", null, null);
+        connection._addSysHandler(/** @param {Element} iq */(iq) => this._onRegisterIQ(iq), null, "iq", null, null);
         connection.send(iq);
         this.setFields(iq.tree());
     }
@@ -371,14 +371,17 @@ class RegisterPanel extends CustomElement {
         const query = stanza.querySelector('query');
         const xform = sizzle(`x[xmlns="${Strophe.NS.XFORM}"]`, query);
         if (xform.length > 0) {
-            this._setFieldsFromXForm(xform.pop());
+            this.setFieldsFromXForm(xform.pop());
         } else {
-            this._setFieldsFromLegacy(query);
+            this.setFieldsFromLegacy(query);
         }
     }
 
-    _setFieldsFromLegacy (query) {
-        [].forEach.call(query.children, field => {
+    /**
+     * @param {Element} query
+     */
+    setFieldsFromLegacy (query) {
+        [].forEach.call(query.children, /** @param {Element} field */(field) => {
             if (field.tagName.toLowerCase() === 'instructions') {
                 this.instructions = Strophe.getText(field);
                 return;
@@ -396,7 +399,7 @@ class RegisterPanel extends CustomElement {
     /**
      * @param {Element} xform
      */
-    _setFieldsFromXForm (xform) {
+    setFieldsFromXForm (xform) {
         this.title = xform.querySelector('title')?.textContent ?? '';
         this.instructions = xform.querySelector('instructions')?.textContent ?? '';
         xform.querySelectorAll('field').forEach(field => {