JC Brand пре 1 година
родитељ
комит
d4dfc3785b

+ 1 - 1
src/headless/index.js

@@ -36,7 +36,7 @@ export { RosterContact, RosterContacts, Presence, Presences } from './plugins/ro
 
 import './plugins/smacks/index.js'; // XEP-0198 Stream Management
 export { XMPPStatus } from './plugins/status/index.js';
-import './plugins/vcard/index.js'; // XEP-0054 VCard-temp
+export { VCard, VCards } from './plugins/vcard/index.js'; // XEP-0054 VCard-temp
 /* END: Removable components */
 
 import log from './log.js';

+ 13 - 0
src/headless/plugins/chat/model-with-contact.js

@@ -3,11 +3,24 @@ import { Model } from '@converse/skeletor';
 import { getOpenPromise } from '@converse/openpromise';
 
 class ModelWithContact extends Model {
+    /**
+     * @typedef {import('../vcard/vcard').default} VCard
+     * @typedef {import('../roster/contact').default} RosterContact
+     */
 
     initialize () {
         super.initialize();
         this.rosterContactAdded = getOpenPromise();
+        /**
+         * @public
+         * @type {RosterContact}
+         */
+
         this.contact = null;
+        /**
+         * @public
+         * @type {VCard}
+         */
         this.vcard = null;
     }
 

+ 1 - 93
src/headless/plugins/vcard/index.js

@@ -1,96 +1,4 @@
-/**
- * @copyright The Converse.js contributors
- * @license Mozilla Public License (MPLv2)
- */
-import "../status/index.js";
 import VCard from './vcard.js';
-import _converse from '../../shared/_converse.js';
-import api, { converse } from '../../shared/api/index.js';
-import vcard_api from './api.js';
 import VCards from "./vcards";
-import {
-    clearVCardsSession,
-    initVCardCollection,
-    onOccupantAvatarChanged,
-    setVCardOnMUCMessage,
-    setVCardOnModel,
-    setVCardOnOccupant,
-} from './utils.js';
 
-const { Strophe } = converse.env;
-
-
-converse.plugins.add('converse-vcard', {
-
-    dependencies: ["converse-status", "converse-roster"],
-
-    // Overrides mentioned here will be picked up by converse.js's
-    // plugin architecture they will replace existing methods on the
-    // relevant objects or classes.
-    // New functions which don't exist yet can also be added.
-    overrides: {
-        XMPPStatus: {
-            getNickname () {
-                const { _converse } = this.__super__;
-                const nick = this.__super__.getNickname.apply(this);
-                if (!nick && _converse.xmppstatus.vcard) {
-                    return _converse.xmppstatus.vcard.get('nickname');
-                } else {
-                    return nick;
-                }
-            },
-
-            getFullname () {
-                const { _converse } = this.__super__;
-                const fullname = this.__super__.getFullname.apply(this);
-                if (!fullname && _converse.xmppstatus.vcard) {
-                    return _converse.xmppstatus.vcard.get('fullname');
-                } else {
-                    return fullname;
-                }
-            }
-        },
-
-        RosterContact: {
-            getDisplayName () {
-                if (!this.get('nickname') && this.vcard) {
-                    return this.vcard.getDisplayName();
-                } else {
-                    return this.__super__.getDisplayName.apply(this);
-                }
-            },
-            getFullname () {
-                if (this.vcard) {
-                    return this.vcard.get('fullname');
-                } else {
-                    return this.__super__.getFullname.apply(this);
-                }
-            }
-        }
-    },
-
-    initialize () {
-        api.promises.add('VCardsInitialized');
-
-        const exports = { VCard, VCards };
-        Object.assign(_converse, exports); // XXX DEPRECATED
-        Object.assign(_converse.exports, exports);
-
-        api.listen.on('chatRoomInitialized', (m) => {
-            setVCardOnModel(m)
-            m.occupants.forEach(setVCardOnOccupant);
-            m.listenTo(m.occupants, 'add', setVCardOnOccupant);
-            m.listenTo(m.occupants, 'change:image_hash', o => onOccupantAvatarChanged(o));
-        });
-
-        api.listen.on('chatBoxInitialized', m => setVCardOnModel(m));
-        api.listen.on('chatRoomMessageInitialized', m => setVCardOnMUCMessage(m));
-        api.listen.on('addClientFeatures', () => api.disco.own.features.add(Strophe.NS.VCARD));
-        api.listen.on('clearSession', () => clearVCardsSession());
-        api.listen.on('messageInitialized', m => setVCardOnModel(m));
-        api.listen.on('rosterContactInitialized', m => setVCardOnModel(m));
-        api.listen.on('statusInitialized', initVCardCollection);
-
-        Object.assign(_converse.api, vcard_api);
-    }
-});
+export { VCard, VCards };

+ 96 - 0
src/headless/plugins/vcard/plugin.js

@@ -0,0 +1,96 @@
+/**
+ * @copyright The Converse.js contributors
+ * @license Mozilla Public License (MPLv2)
+ */
+import "../status/index.js";
+import VCard from './vcard.js';
+import _converse from '../../shared/_converse.js';
+import api, { converse } from '../../shared/api/index.js';
+import vcard_api from './api.js';
+import VCards from "./vcards";
+import {
+    clearVCardsSession,
+    initVCardCollection,
+    onOccupantAvatarChanged,
+    setVCardOnMUCMessage,
+    setVCardOnModel,
+    setVCardOnOccupant,
+} from './utils.js';
+
+const { Strophe } = converse.env;
+
+
+converse.plugins.add('converse-vcard', {
+
+    dependencies: ["converse-status", "converse-roster"],
+
+    // Overrides mentioned here will be picked up by converse.js's
+    // plugin architecture they will replace existing methods on the
+    // relevant objects or classes.
+    // New functions which don't exist yet can also be added.
+    overrides: {
+        XMPPStatus: {
+            getNickname () {
+                const { _converse } = this.__super__;
+                const nick = this.__super__.getNickname.apply(this);
+                if (!nick && _converse.xmppstatus.vcard) {
+                    return _converse.xmppstatus.vcard.get('nickname');
+                } else {
+                    return nick;
+                }
+            },
+
+            getFullname () {
+                const { _converse } = this.__super__;
+                const fullname = this.__super__.getFullname.apply(this);
+                if (!fullname && _converse.xmppstatus.vcard) {
+                    return _converse.xmppstatus.vcard.get('fullname');
+                } else {
+                    return fullname;
+                }
+            }
+        },
+
+        RosterContact: {
+            getDisplayName () {
+                if (!this.get('nickname') && this.vcard) {
+                    return this.vcard.getDisplayName();
+                } else {
+                    return this.__super__.getDisplayName.apply(this);
+                }
+            },
+            getFullname () {
+                if (this.vcard) {
+                    return this.vcard.get('fullname');
+                } else {
+                    return this.__super__.getFullname.apply(this);
+                }
+            }
+        }
+    },
+
+    initialize () {
+        api.promises.add('VCardsInitialized');
+
+        const exports = { VCard, VCards };
+        Object.assign(_converse, exports); // XXX DEPRECATED
+        Object.assign(_converse.exports, exports);
+
+        api.listen.on('chatRoomInitialized', (m) => {
+            setVCardOnModel(m)
+            m.occupants.forEach(setVCardOnOccupant);
+            m.listenTo(m.occupants, 'add', setVCardOnOccupant);
+            m.listenTo(m.occupants, 'change:image_hash', o => onOccupantAvatarChanged(o));
+        });
+
+        api.listen.on('chatBoxInitialized', m => setVCardOnModel(m));
+        api.listen.on('chatRoomMessageInitialized', m => setVCardOnMUCMessage(m));
+        api.listen.on('addClientFeatures', () => api.disco.own.features.add(Strophe.NS.VCARD));
+        api.listen.on('clearSession', () => clearVCardsSession());
+        api.listen.on('messageInitialized', m => setVCardOnModel(m));
+        api.listen.on('rosterContactInitialized', m => setVCardOnModel(m));
+        api.listen.on('statusInitialized', initVCardCollection);
+
+        Object.assign(_converse.api, vcard_api);
+    }
+});

+ 5 - 0
src/headless/plugins/vcard/vcard.js

@@ -18,6 +18,11 @@ class VCard extends Model {
         }
     }
 
+  /**
+   * @param {string|Object} key
+   * @param {string|Object} [val]
+   * @param {Record.<string, any>} [options]
+   */
     set (key, val, options) {
         // Override Model.prototype.set to make sure that the
         // default `image` and `image_type` values are maintained.

+ 1 - 1
src/headless/shared/constants.js

@@ -1,7 +1,7 @@
 import { Strophe } from 'strophe.js';
 
 export const BOSH_WAIT = 59;
-export const VERSION_NAME = "v10.1.5";
+export const VERSION_NAME = "v11.0.0";
 
 export const STATUS_WEIGHTS = {
     offline: 6,

+ 1 - 0
src/headless/types/index.d.ts

@@ -10,4 +10,5 @@ export { api, converse, _converse, i18n, log, u };
 export { ChatBox, Message, Messages } from "./plugins/chat/index.js";
 export { MUCMessage, MUCMessages, MUC, MUCOccupant, MUCOccupants } from "./plugins/muc/index.js";
 export { RosterContact, RosterContacts, Presence, Presences } from "./plugins/roster/index.js";
+export { VCard, VCards } from "./plugins/vcard/index.js";
 //# sourceMappingURL=index.d.ts.map

+ 10 - 2
src/headless/types/plugins/chat/model-with-contact.d.ts

@@ -1,8 +1,16 @@
 export default ModelWithContact;
 declare class ModelWithContact extends Model {
     rosterContactAdded: any;
-    contact: any;
-    vcard: any;
+    /**
+     * @public
+     * @type {RosterContact}
+     */
+    public contact: import("../roster/contact").default;
+    /**
+     * @public
+     * @type {VCard}
+     */
+    public vcard: import("../vcard/vcard").default;
     /**
      * @param {string} jid
      */

+ 3 - 1
src/headless/types/plugins/vcard/index.d.ts

@@ -1,2 +1,4 @@
-export {};
+import VCard from "./vcard.js";
+import VCards from "./vcards";
+export { VCard, VCards };
 //# sourceMappingURL=index.d.ts.map

+ 2 - 0
src/headless/types/plugins/vcard/plugin.d.ts

@@ -0,0 +1,2 @@
+export {};
+//# sourceMappingURL=plugin.d.ts.map

+ 6 - 1
src/headless/types/plugins/vcard/vcard.d.ts

@@ -9,7 +9,12 @@ declare class VCard extends Model {
         image: string;
         image_type: string;
     };
-    set(key: any, val: any, options: any, ...args: any[]): any;
+    /**
+     * @param {string|Object} key
+     * @param {string|Object} [val]
+     * @param {Record.<string, any>} [options]
+     */
+    set(key: string | any, val?: string | any, options?: Record<string, any>, ...args: any[]): any;
     getDisplayName(): any;
 }
 import { Model } from "@converse/skeletor";

+ 10 - 2
src/types/headless/plugins/chat/model-with-contact.d.ts

@@ -1,8 +1,16 @@
 export default ModelWithContact;
 declare class ModelWithContact extends Model {
     rosterContactAdded: any;
-    contact: any;
-    vcard: any;
+    /**
+     * @public
+     * @type {RosterContact}
+     */
+    public contact: import("../roster/contact").default;
+    /**
+     * @public
+     * @type {VCard}
+     */
+    public vcard: import("../vcard/vcard").default;
     /**
      * @param {string} jid
      */

+ 71 - 0
src/types/headless/plugins/roster/contact.d.ts

@@ -0,0 +1,71 @@
+export default RosterContact;
+declare class RosterContact extends Model {
+    defaults(): {
+        chat_state: any;
+        groups: any[];
+        image: string;
+        image_type: string;
+        num_unread: number;
+        status: any;
+    };
+    initialize(attributes: any): Promise<void>;
+    initialized: any;
+    setPresence(): void;
+    presence: any;
+    openChat(): void;
+    /**
+     * Return a string of tab-separated values that are to be used when
+     * matching against filter text.
+     *
+     * The goal is to be able to filter against the VCard fullname,
+     * roster nickname and JID.
+     * @returns {string} Lower-cased, tab-separated values
+     */
+    getFilterCriteria(): string;
+    getDisplayName(): any;
+    getFullname(): any;
+    /**
+     * Send a presence subscription request to this roster contact
+     * @method RosterContacts#subscribe
+     * @param {string} message - An optional message to explain the
+     *      reason for the subscription request.
+     */
+    subscribe(message: string): RosterContact;
+    /**
+     * Upon receiving the presence stanza of type "subscribed",
+     * the user SHOULD acknowledge receipt of that subscription
+     * state notification by sending a presence stanza of type
+     * "subscribe" to the contact
+     * @method RosterContacts#ackSubscribe
+     */
+    ackSubscribe(): void;
+    /**
+     * Upon receiving the presence stanza of type "unsubscribed",
+     * the user SHOULD acknowledge receipt of that subscription state
+     * notification by sending a presence stanza of type "unsubscribe"
+     * this step lets the user's server know that it MUST no longer
+     * send notification of the subscription state change to the user.
+     * @method RosterContacts#ackUnsubscribe
+     */
+    ackUnsubscribe(): void;
+    /**
+     * Unauthorize this contact's presence subscription
+     * @method RosterContacts#unauthorize
+     * @param {string} message - Optional message to send to the person being unauthorized
+     */
+    unauthorize(message: string): RosterContact;
+    /**
+     * Authorize presence subscription
+     * @method RosterContacts#authorize
+     * @param {string} message - Optional message to send to the person being authorized
+     */
+    authorize(message: string): RosterContact;
+    /**
+     * Instruct the XMPP server to remove this contact from our roster
+     * @method RosterContacts#removeFromRoster
+     * @returns {Promise}
+     */
+    removeFromRoster(): Promise<any>;
+}
+import { Model } from "@converse/skeletor";
+//# sourceMappingURL=contact.d.ts.map

+ 85 - 0
src/types/headless/plugins/roster/contacts.d.ts

@@ -0,0 +1,85 @@
+export default RosterContacts;
+declare class RosterContacts extends Collection {
+    constructor();
+    model: typeof RosterContact;
+    data: any;
+    state: Model;
+    onConnected(): void;
+    /**
+     * Register a handler for roster IQ "set" stanzas, which update
+     * roster contacts.
+     */
+    registerRosterHandler(): void;
+    /**
+     * Register a handler for RosterX message stanzas, which are
+     * used to suggest roster contacts to a user.
+     */
+    registerRosterXHandler(): void;
+    /**
+     * Fetches the roster contacts, first by trying the browser cache,
+     * and if that's empty, then by querying the XMPP server.
+     * @returns {promise} Promise which resolves once the contacts have been fetched.
+     */
+    fetchRosterContacts(): Promise<any>;
+    subscribeToSuggestedItems(msg: any): boolean;
+    isSelf(jid: any): any;
+    /**
+     * Add a roster contact and then once we have confirmation from
+     * the XMPP server we subscribe to that contact's presence updates.
+     * @method _converse.RosterContacts#addAndSubscribe
+     * @param { String } jid - The Jabber ID of the user being added and subscribed to.
+     * @param { String } name - The name of that user
+     * @param { Array<String> } groups - Any roster groups the user might belong to
+     * @param { String } message - An optional message to explain the reason for the subscription request.
+     * @param { Object } attributes - Any additional attributes to be stored on the user's model.
+     */
+    addAndSubscribe(jid: string, name: string, groups: Array<string>, message: string, attributes: any): Promise<void>;
+    /**
+     * Send an IQ stanza to the XMPP server to add a new roster contact.
+     * @method _converse.RosterContacts#sendContactAddIQ
+     * @param { String } jid - The Jabber ID of the user being added
+     * @param { String } name - The name of that user
+     * @param { Array<String> } groups - Any roster groups the user might belong to
+     */
+    sendContactAddIQ(jid: string, name: string, groups: Array<string>): any;
+    /**
+     * Adds a RosterContact instance to _converse.roster and
+     * registers the contact on the XMPP server.
+     * Returns a promise which is resolved once the XMPP server has responded.
+     * @method _converse.RosterContacts#addContactToRoster
+     * @param { String } jid - The Jabber ID of the user being added and subscribed to.
+     * @param { String } name - The name of that user
+     * @param { Array<String> } groups - Any roster groups the user might belong to
+     * @param { Object } attributes - Any additional attributes to be stored on the user's model.
+     */
+    addContactToRoster(jid: string, name: string, groups: Array<string>, attributes: any): Promise<any>;
+    subscribeBack(bare_jid: any, presence: any): Promise<void>;
+    /**
+     * Handle roster updates from the XMPP server.
+     * See: https://xmpp.org/rfcs/rfc6121.html#roster-syntax-actions-push
+     * @method _converse.RosterContacts#onRosterPush
+     * @param { Element } iq - The IQ stanza received from the XMPP server.
+     */
+    onRosterPush(iq: Element): void;
+    rosterVersioningSupported(): any;
+    /**
+     * Fetch the roster from the XMPP server
+     * @emits _converse#roster
+     * @returns {promise}
+     */
+    fetchFromServer(): Promise<any>;
+    /**
+     * Update or create RosterContact models based on the given `item` XML
+     * node received in the resulting IQ stanza from the server.
+     * @param { Element } item
+     */
+    updateContact(item: Element): any;
+    createRequestingContact(presence: any): void;
+    handleIncomingSubscription(presence: any): void;
+    handleOwnPresence(presence: any): void;
+    presenceHandler(presence: any): true | void;
+}
+import { Collection } from "@converse/skeletor";
+import RosterContact from "./contact.js";
+import { Model } from "@converse/skeletor";
+//# sourceMappingURL=contacts.d.ts.map

+ 4 - 0
src/types/headless/plugins/roster/filter.d.ts

@@ -0,0 +1,4 @@
+export class RosterFilter extends Model {
+}
+import { Model } from "@converse/skeletor";
+//# sourceMappingURL=filter.d.ts.map

+ 43 - 0
src/types/headless/plugins/roster/utils.d.ts

@@ -0,0 +1,43 @@
+export function unregisterPresenceHandler(): void;
+/**
+ * Roster specific event handler for the clearSession event
+ */
+export function onClearSession(): Promise<void>;
+/**
+ * Roster specific event handler for the presencesInitialized event
+ * @param { Boolean } reconnecting
+ */
+export function onPresencesInitialized(reconnecting: boolean): void;
+/**
+ * Roster specific event handler for the statusInitialized event
+ * @param { Boolean } reconnecting
+ */
+export function onStatusInitialized(reconnecting: boolean): Promise<void>;
+/**
+ * Roster specific event handler for the chatBoxesInitialized event
+ */
+export function onChatBoxesInitialized(): void;
+/**
+ * Roster specific handler for the rosterContactsFetched promise
+ */
+export function onRosterContactsFetched(): void;
+/**
+ * Reject or cancel another user's subscription to our presence updates.
+ * @function rejectPresenceSubscription
+ * @param { String } jid - The Jabber ID of the user whose subscription is being canceled
+ * @param { String } message - An optional message to the user
+ */
+export function rejectPresenceSubscription(jid: string, message: string): void;
+export function contactsComparator(contact1: any, contact2: any): 0 | 1 | -1;
+export function groupsComparator(a: any, b: any): 0 | 1 | -1;
+export function getGroupsAutoCompleteList(): any[];
+export function getJIDsAutoCompleteList(): any[];
+/**
+ * @param {string} query
+ */
+export function getNamesAutoCompleteList(query: string): Promise<{
+    label: any;
+    value: any;
+}[]>;
+export type RosterContacts = import('./contacts').default;
+//# sourceMappingURL=utils.d.ts.map

+ 41 - 0
src/types/headless/plugins/status/api.d.ts

@@ -0,0 +1,41 @@
+declare namespace _default {
+    namespace status {
+        /**
+         * Return the current user's availability status.
+         * @async
+         * @method _converse.api.user.status.get
+         * @example _converse.api.user.status.get();
+         */
+        function get(): Promise<any>;
+        /**
+         * The user's status can be set to one of the following values:
+         *
+         * @async
+         * @method _converse.api.user.status.set
+         * @param { string } value The user's chat status (e.g. 'away', 'dnd', 'offline', 'online', 'unavailable' or 'xa')
+         * @param { string } [message] A custom status message
+         *
+         * @example _converse.api.user.status.set('dnd');
+         * @example _converse.api.user.status.set('dnd', 'In a meeting');
+         */
+        function set(value: string, message?: string): Promise<void>;
+        namespace message {
+            /**
+             * @async
+             * @method _converse.api.user.status.message.get
+             * @returns { Promise<string> } The status message
+             * @example const message = _converse.api.user.status.message.get()
+             */
+            function get(): Promise<string>;
+            /**
+             * @async
+             * @method _converse.api.user.status.message.set
+             * @param { string } status The status message
+             * @example _converse.api.user.status.message.set('In a meeting');
+             */
+            function set(status: string): Promise<void>;
+        }
+    }
+}
+export default _default;
+//# sourceMappingURL=api.d.ts.map

+ 6 - 1
src/types/headless/plugins/vcard/vcard.d.ts

@@ -9,7 +9,12 @@ declare class VCard extends Model {
         image: string;
         image_type: string;
     };
-    set(key: any, val: any, options: any, ...args: any[]): any;
+    /**
+     * @param {string|Object} key
+     * @param {string|Object} [val]
+     * @param {Record.<string, any>} [options]
+     */
+    set(key: string | any, val?: string | any, options?: Record<string, any>, ...args: any[]): any;
     getDisplayName(): any;
 }
 import { Model } from "@converse/skeletor";

+ 2 - 1
src/types/plugins/muc-views/sidebar.d.ts

@@ -6,7 +6,7 @@ export default class MUCSidebar extends CustomElement {
     };
     jid: any;
     initialize(): void;
-    filter: any;
+    filter: RosterFilter;
     model: any;
     render(): import("lit-html").TemplateResult<1>;
     /** @param {MouseEvent} ev */
@@ -17,4 +17,5 @@ export default class MUCSidebar extends CustomElement {
     onOccupantClicked(ev: MouseEvent): void;
 }
 import { CustomElement } from "shared/components/element.js";
+import { RosterFilter } from "@converse/headless/plugins/roster/filter.js";
 //# sourceMappingURL=sidebar.d.ts.map