From 93d56898b7b32ba6d92997a7b8256d9e0b26b314 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 3 Nov 2019 19:34:55 +0100 Subject: [PATCH] Fixes #1772. Wait for roster to be fetched --- CHANGES.md | 1 + src/headless/converse-roster.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 403f96206..e1a109f22 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ - #1691: Fix `collection.chatbox is undefined` errors - #1733: New message notifications for a minimized chat stack on top of each other - #1757: Chats are hidden behind the controlbox on mobile +- #1772 `_converse.api.contact.add(jid, nick)` fails, says not a function - Prevent editing of sent file uploads. - Initial support for sending custom emojis. Currently only between Converse instances. Still working out a wire protocol for compatibility with other clients. diff --git a/src/headless/converse-roster.js b/src/headless/converse-roster.js index 6f13a1fca..d77c624ca 100644 --- a/src/headless/converse-roster.js +++ b/src/headless/converse-roster.js @@ -1075,8 +1075,9 @@ converse.plugins.add('converse-roster', { * @example * _converse.api.contacts.add('buddy@example.com', 'Buddy') */ - 'add' (jid, name) { - if (!_.isString(jid) || !_.includes(jid, '@')) { + async add (jid, name) { + await _converse.api.waitUntil('rosterContactsFetched'); + if (!_.isString(jid) || !jid.includes('@')) { throw new TypeError('contacts.add: invalid jid'); } _converse.roster.addAndSubscribe(jid, _.isEmpty(name)? jid: name);