summaryrefslogtreecommitdiffstats
path: root/roles/reverseproxy/files/conversejs/src/headless/shared/api/presence.js
blob: e9180fad7e4b6416281ee55f4948b174ccbd5367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { _converse, api } from '../../core.js';


export default {
    /**
     * @namespace _converse.api.user.presence
     * @memberOf _converse.api.user
     */
    presence: {
        /**
         * Send out a presence stanza
         * @method _converse.api.user.presence.send
         * @param { String } [type]
         * @param { String } [to]
         * @param { String } [status] - An optional status message
         * @param { Array<Element>|Array<Strophe.Builder>|Element|Strophe.Builder } [child_nodes]
         *  Nodes(s) to be added as child nodes of the `presence` XML element.
         */
        async send (type, to, status, child_nodes) {
            await api.waitUntil('statusInitialized');
            if (child_nodes && !Array.isArray(child_nodes)) {
                child_nodes = [child_nodes];
            }
            const model = _converse.xmppstatus
            const presence = await model.constructPresence(type, to, status);
            child_nodes?.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up());
            api.send(presence);

            if (['away', 'chat', 'dnd', 'online', 'xa', undefined].includes(type)) {
                const mucs = await api.rooms.get();
                mucs.forEach(muc => muc.sendStatusPresence(type, status, child_nodes));
            }
        }
    }
}