"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.setChatsPrivateStoreRequest = setChatsPrivateStoreRequest;
var _client = require("@xmpp/client");
var _createTimeoutPromise = require("./createTimeoutPromise.xmpp");
async function setChatsPrivateStoreRequest(client, jsonObj) {
  const id = `set-chats-private-req:${Date.now().toString()}`;
  let stanzaHdlrPointer;
  const unsubscribe = () => {
    client?.off('stanza', stanzaHdlrPointer);
  };
  const responsePromise = new Promise((resolve, _reject) => {
    stanzaHdlrPointer = stanza => {
      if (stanza.is('iq') && stanza.attrs.id === id) {
        resolve(true);
      }
    };
    client?.on('stanza', stanzaHdlrPointer);
    const message = (0, _client.xml)('iq', {
      id: id,
      type: 'set'
    }, (0, _client.xml)('query', {
      xmlns: 'jabber:iq:private'
    }, (0, _client.xml)('chatjson', {
      xmlns: 'chatjson:store',
      value: jsonObj
    })));
    client?.send(message);
  });
  const timeoutPromise = (0, _createTimeoutPromise.createTimeoutPromise)(2000, unsubscribe);
  return Promise.race([responsePromise, timeoutPromise]);
}
//# sourceMappingURL=setChatsPrivateStoreRequest.xmpp.js.map