Ver Fonte

roster: avoid race-condition by waiting for contacts to be fetched

before creating any new ones
JC Brand há 5 anos atrás
pai
commit
b08f5d355b
2 ficheiros alterados com 2 adições e 0 exclusões
  1. 1 0
      spec/protocol.js
  2. 1 0
      src/headless/converse-roster.js

+ 1 - 0
spec/protocol.js

@@ -112,6 +112,7 @@
                  *   </query>
                  *   </query>
                  *   </iq>
                  *   </iq>
                  */
                  */
+                await test_utils.waitForRoster(_converse, 'all', 0);
                 expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
                 expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
                 expect(sent_stanza.toLocaleString()).toBe(
                 expect(sent_stanza.toLocaleString()).toBe(
                     `<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
                     `<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+

+ 1 - 0
src/headless/converse-roster.js

@@ -516,6 +516,7 @@ converse.plugins.add('converse-roster', {
              * @param { Object } attributes - Any additional attributes to be stored on the user's model.
              * @param { Object } attributes - Any additional attributes to be stored on the user's model.
              */
              */
             async addContactToRoster (jid, name, groups, attributes) {
             async addContactToRoster (jid, name, groups, attributes) {
+                await _converse.api.waitUntil('rosterContactsFetched');
                 groups = groups || [];
                 groups = groups || [];
                 try {
                 try {
                     await this.sendContactAddIQ(jid, name, groups);
                     await this.sendContactAddIQ(jid, name, groups);