"use strict";

import { getChatsPrivateStoreRequest } from './getChatsPrivateStoreRequest.xmpp';
import { setChatsPrivateStoreRequest } from './setChatsPrivateStoreRequest.xmpp';
const populateChats = (chats, timestamp) => {
  const populatedData = chats.reduce((acc, chat) => {
    acc[chat] = timestamp;
    return acc;
  }, {});
  return JSON.stringify(populatedData);
};
export async function actionSetTimestampToPrivateStore(client, chatId, timestamp, chats) {
  let storeObj = await getChatsPrivateStoreRequest(client);
  if (storeObj && typeof storeObj === 'object') {
    storeObj[chatId] = timestamp;
    const str = JSON.stringify(storeObj);
    await setChatsPrivateStoreRequest(client, str);
    return true;
  } else {
    await setChatsPrivateStoreRequest(client, populateChats(chats || [], timestamp.toString()));
    return true;
  }
}
//# sourceMappingURL=actionSetTimestampToPrivateStore.xmpp.js.map