浏览代码

Fixes #1772. Wait for roster to be fetched

JC Brand 5 年之前
父节点
当前提交
93d56898b7
共有 2 个文件被更改,包括 4 次插入2 次删除
  1. 1 0
      CHANGES.md
  2. 3 2
      src/headless/converse-roster.js

+ 1 - 0
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.

+ 3 - 2
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);