"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getUnnamedUsers = exports.fixUnnamedArrayFromApi = void 0;
var _roomMembers = require("../networking/api-requests/roomMembers.api");
var _roomStore = require("../roomStore");
function getUniqueUsers(messages) {
  const userMap = new Map();
  messages.forEach(({
    user
  }) => {
    if (!userMap.has(user.id)) {
      userMap.set(user.id, user);
    }
  });
  return new Set(userMap.values());
}
const getUnnamedUsers = messages => {
  const uniqueUsers = getUniqueUsers(messages);
  return [...uniqueUsers].filter(user => user?.name?.toLowerCase().includes('deleted'));
};
exports.getUnnamedUsers = getUnnamedUsers;
const fixUnnamedArrayFromApi = async unnamedUsers => {
  const fetchedUsers = await Promise.all(unnamedUsers.map(async user => {
    const apiUser = await (0, _roomMembers.getUserByXmppUsername)(user.id, _roomStore.store.getState().chatSettingStore.user.token);
    return apiUser;
  }));
  return fetchedUsers.filter(u => u !== null);
};
exports.fixUnnamedArrayFromApi = fixUnnamedArrayFromApi;
//# sourceMappingURL=getUnnamedUsers.js.map