"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.initRoomsPresence = void 0;
var _presenceInRoom = require("../networking/xmpp/presenceInRoom.xmpp");
var _pushSubscriptionService = require("../services/pushSubscriptionService");
const initRoomsPresence = async (client, rooms) => {
  console.log('Persisted presence');
  if (!client) {
    return null;
  }
  const jids = Object.keys(rooms || {});
  if (!jids.length) {
    return null;
  }
  await Promise.allSettled(jids.map(async jid => {
    try {
      await (0, _presenceInRoom.presenceInRoom)(client.client, jid);
    } catch (e) {}
  }));
  if (jids.length > 0 && client.client) {
    const userNick = client.client.jid?.getLocal();
    await _pushSubscriptionService.pushSubscriptionService.subscribeToRooms(client.client, jids, userNick).catch(error => {
      console.error('Failed to subscribe to rooms for push:', error);
    });
  }
};
exports.initRoomsPresence = initRoomsPresence;
//# sourceMappingURL=initRoomsPresence.js.map