Converse converse.js

Namespace: vcard

_converse.api.vcard

The XEP-0054 VCard API

This API lets you access and update user VCards

Source:

Methods

(static) get(model, forceopt) → {promise}

Parameters:
Name Type Attributes Description
model Model | string

Either a Model instance, or a string JID. If a Model instance is passed in, then it must have either a jid attribute or a muc_jid attribute.

force boolean <optional>

A boolean indicating whether the vcard should be fetched even if it's been fetched before.

Source:
Returns:

A Promise which resolves with the VCard data for a particular JID or for a Model instance which represents an entity with a JID (such as a roster contact, chat or chatroom occupant).

Type
promise
Example
_converse.api.waitUntil('rosterContactsFetched').then(() => {
    _converse.api.vcard.get('someone@example.org').then(
        (vcard) => {
            // Do something with the vcard...
        }
    );
});

(static) set(jid, data)

Enables setting new values for a VCard.

Sends out an IQ stanza to set the user's VCard and if successful, it updates the _converse.VCard for the passed in JID.

Parameters:
Name Type Description
jid string

The JID for which the VCard should be set

data object

A map of VCard keys and values

Source:
Example
_converse.api.vcard.set({
    'jid': _converse.bare_jid,
    'fn': 'John Doe',
    'nickname': 'jdoe'
}).then(() => {
    // Succes
}).catch(() => {
    // Failure
}).

(static) update(model, forceopt) → {promise}

Fetches the VCard associated with a particular Model instance (by using its jid or muc_jid attribute) and then updates the model with the returned VCard data.

Parameters:
Name Type Attributes Description
model Model

A Model instance

force boolean <optional>

A boolean indicating whether the vcard should be fetched again even if it's been fetched before.

Source:
Returns:

A promise which resolves once the update has completed.

Type
promise
Example
_converse.api.waitUntil('rosterContactsFetched').then(async () => {
    const chatbox = await _converse.chatboxes.getChatBox('someone@example.org');
    _converse.api.vcard.update(chatbox);
});