Browse Source

Don't log error stanza

JC Brand 4 months ago
parent
commit
b876d0235b

+ 11 - 9
src/headless/plugins/muc/affiliations/utils.js

@@ -13,32 +13,34 @@ import converse from '../../../shared/api/public.js';
 import log from '../../../log.js';
 import { parseMemberListIQ } from '../parsers.js';
 
-const { Strophe, $iq, u } = converse.env;
+const { Strophe, $iq, u, stx } = converse.env;
 
 /**
  * Sends an IQ stanza to the server, asking it for the relevant affiliation list .
  * Returns an array of {@link MemberListItem} objects, representing occupants
  * that have the given affiliation.
  * See: https://xmpp.org/extensions/xep-0045.html#modifymember
- * @typedef {("admin"|"owner"|"member")} NonOutcastAffiliation
- * @param {NonOutcastAffiliation} affiliation
+ * @param {import('../types').NonOutcastAffiliation} affiliation
  * @param {string} muc_jid - The JID of the MUC for which the affiliation list should be fetched
  * @returns {Promise<MemberListItem[]|Error>}
  */
 export async function getAffiliationList (affiliation, muc_jid) {
-    const { __ } = _converse;
-    const iq = $iq({ 'to': muc_jid, 'type': 'get' })
-        .c('query', { xmlns: Strophe.NS.MUC_ADMIN })
-        .c('item', { 'affiliation': affiliation });
+    const iq = stx`
+        <iq xmlns="jabber:client" to="${muc_jid}" type="get">
+            <query xmlns="${Strophe.NS.MUC_ADMIN}">
+                <item affiliation="${affiliation}"/>
+            </query>
+        </iq>`;
+
     const result = await api.sendIQ(iq, null, false);
     if (result === null) {
-        const err_msg = __('Error: timeout while fetching %1s list for MUC %2s', affiliation, muc_jid);
+        const err_msg = `Error: timeout while fetching ${affiliation} list for MUC ${muc_jid}`;
         const err = new Error(err_msg);
         log.warn(err_msg);
         return err;
     }
     if (u.isErrorStanza(result)) {
-        const err_msg = __('Error: not allowed to fetch %1s list for MUC %2s', affiliation, muc_jid);
+        const err_msg = `Error: not allowed to fetch ${affiliation} list for MUC ${muc_jid}`;
         const err = new Error(err_msg);
         log.warn(err_msg);
         log.warn(result);

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

@@ -48,7 +48,7 @@ class MUC extends ModelWithVCard(ModelWithMessages(ColorAwareModel(ChatBoxBase))
      * @typedef {import('../../shared/message.js').default} BaseMessage
      * @typedef {import('./message.js').default} MUCMessage
      * @typedef {import('./occupant.js').default} MUCOccupant
-     * @typedef {import('./affiliations/utils.js').NonOutcastAffiliation} NonOutcastAffiliation
+     * @typedef {import('./types').NonOutcastAffiliation} NonOutcastAffiliation
      * @typedef {import('./types').MemberListItem} MemberListItem
      * @typedef {import('../../shared/types').MessageAttributes} MessageAttributes
      * @typedef {import('./types').MUCMessageAttributes} MUCMessageAttributes

+ 0 - 2
src/headless/plugins/muc/occupants.js

@@ -71,7 +71,6 @@ class MUCOccupants extends Collection {
         const muc_jid = this.chatroom.get('jid');
         const aff_lists = await Promise.all(affiliations.map(a => getAffiliationList(a, muc_jid)));
 
-
         const new_members = aff_lists.reduce(
             /**
              * @param {MemberListItem[]} acc
@@ -80,7 +79,6 @@ class MUCOccupants extends Collection {
              */
             (acc, val) => {
                 if (val instanceof Error) {
-                    log.error(val);
                     return acc;
                 }
                 return [...val, ...acc];

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

@@ -70,6 +70,9 @@ export type MUCMessageAttributes = MessageAttributes & ExtraMUCAttributes;
 export type MUCAffiliation = 'owner'|'admin'|'member'|'outcast'|'none';
 export type MUCRole = 'moderator'|'participant'|'visitor'|'none';
 
+
+ export type NonOutcastAffiliation = 'admin' | 'owner' | 'member';
+
 /**
  * Either the JID or the nickname (or both) will be available.
  */

+ 2 - 10
src/headless/types/plugins/muc/affiliations/utils.d.ts

@@ -3,12 +3,11 @@
  * Returns an array of {@link MemberListItem} objects, representing occupants
  * that have the given affiliation.
  * See: https://xmpp.org/extensions/xep-0045.html#modifymember
- * @typedef {("admin"|"owner"|"member")} NonOutcastAffiliation
- * @param {NonOutcastAffiliation} affiliation
+ * @param {import('../types').NonOutcastAffiliation} affiliation
  * @param {string} muc_jid - The JID of the MUC for which the affiliation list should be fetched
  * @returns {Promise<MemberListItem[]|Error>}
  */
-export function getAffiliationList(affiliation: NonOutcastAffiliation, muc_jid: string): Promise<MemberListItem[] | Error>;
+export function getAffiliationList(affiliation: import("../types").NonOutcastAffiliation, muc_jid: string): Promise<MemberListItem[] | Error>;
 /**
  * Send IQ stanzas to the server to modify affiliations for users in this groupchat.
  * See: https://xmpp.org/extensions/xep-0045.html#modifymember
@@ -63,13 +62,6 @@ export function setAffiliation(affiliation: AFFILIATIONS[number], muc_jids: stri
  * @returns {array}
  */
 export function computeAffiliationsDelta(exclude_existing: boolean, remove_absentees: boolean, new_list: any[], old_list: any[]): any[];
-/**
- * Sends an IQ stanza to the server, asking it for the relevant affiliation list .
- * Returns an array of {@link MemberListItem} objects, representing occupants
- * that have the given affiliation.
- * See: https://xmpp.org/extensions/xep-0045.html#modifymember
- */
-export type NonOutcastAffiliation = ("admin" | "owner" | "member");
 export type MemberListItem = any;
 export type User = any;
 export type Model = import("@converse/skeletor").Model;

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

@@ -274,7 +274,7 @@ declare class MUC extends MUC_base {
      * @typedef {import('../../shared/message.js').default} BaseMessage
      * @typedef {import('./message.js').default} MUCMessage
      * @typedef {import('./occupant.js').default} MUCOccupant
-     * @typedef {import('./affiliations/utils.js').NonOutcastAffiliation} NonOutcastAffiliation
+     * @typedef {import('./types').NonOutcastAffiliation} NonOutcastAffiliation
      * @typedef {import('./types').MemberListItem} MemberListItem
      * @typedef {import('../../shared/types').MessageAttributes} MessageAttributes
      * @typedef {import('./types').MUCMessageAttributes} MUCMessageAttributes

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

@@ -41,6 +41,7 @@ type ExtraMUCAttributes = {
 export type MUCMessageAttributes = MessageAttributes & ExtraMUCAttributes;
 export type MUCAffiliation = 'owner' | 'admin' | 'member' | 'outcast' | 'none';
 export type MUCRole = 'moderator' | 'participant' | 'visitor' | 'none';
+export type NonOutcastAffiliation = 'admin' | 'owner' | 'member';
 /**
  * Either the JID or the nickname (or both) will be available.
  */