"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.actionSetTimestampToPrivateStore = actionSetTimestampToPrivateStore;
var _getChatsPrivateStoreRequest = require("./getChatsPrivateStoreRequest.xmpp");
var _setChatsPrivateStoreRequest = require("./setChatsPrivateStoreRequest.xmpp");
const populateChats = (chats, timestamp) => {
  const populatedData = chats.reduce((acc, chat) => {
    acc[chat] = timestamp;
    return acc;
  }, {});
  return JSON.stringify(populatedData);
};
async function actionSetTimestampToPrivateStore(client, chatId, timestamp, chats) {
  let storeObj = await (0, _getChatsPrivateStoreRequest.getChatsPrivateStoreRequest)(client);
  if (storeObj && typeof storeObj === 'object') {
    storeObj[chatId] = timestamp;
    const str = JSON.stringify(storeObj);
    await (0, _setChatsPrivateStoreRequest.setChatsPrivateStoreRequest)(client, str);
    return true;
  } else {
    await (0, _setChatsPrivateStoreRequest.setChatsPrivateStoreRequest)(client, populateChats(chats || [], timestamp.toString()));
    return true;
  }
}
//# sourceMappingURL=actionSetTimestampToPrivateStore.xmpp.js.map