UNPKG

@zextras/carbonio-shell-ui

Version:

The Zextras Carbonio web client

63 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergePrefs = mergePrefs; exports.mergeProps = mergeProps; exports.mergeAttrs = mergeAttrs; exports.updateIdentities = updateIdentities; const lodash_1 = require("lodash"); function mergePrefs(mods, state) { return (0, lodash_1.reduce)(mods, (acc, pref, key) => ({ ...acc, [key]: pref }), state.settings.prefs); } function mergeProps(mods, state) { return (0, lodash_1.reduce)(mods, (acc, { app, value }, key) => { const newPropValue = { name: key, zimlet: app, _content: value }; const propIndex = (0, lodash_1.findIndex)(acc, (p) => p.name === key && p.zimlet === app); if (propIndex >= 0) { return acc.map((prop, index) => (propIndex === index ? newPropValue : prop)); } return [...acc, newPropValue]; }, state.settings.props); } function mergeAttrs(mods, state) { return (0, lodash_1.reduce)(mods, (acc, attr, key) => ({ ...acc, [key]: attr }), state.settings.attrs); } function updateIdentities(state, identityMods, newIdentities) { if (!state.account) { return undefined; } const sortedAndFilteredIdentities = [ ...(0, lodash_1.filter)(state.account.identities.identity, (item) => !identityMods?.deleteList?.includes(item.id)).filter((i) => i.name !== 'DEFAULT'), ...newIdentities, ...(0, lodash_1.filter)(state.account.identities.identity, (item) => !identityMods?.deleteList?.includes(item.id)).filter((i) => i.name === 'DEFAULT') ]; if (!identityMods?.modifyList) { return sortedAndFilteredIdentities; } return sortedAndFilteredIdentities.map((identity) => { const identityMod = (0, lodash_1.find)(identityMods.modifyList, (mod) => mod.id === identity.id); if (!identityMod) { return identity; } return { ...identity, _attrs: { ...identity._attrs, ...identityMod.prefs }, ...(identityMod.prefs.zimbraPrefIdentityName && identity.name !== 'DEFAULT' ? { name: identityMod.prefs.zimbraPrefIdentityName } : {}) }; }); } //# sourceMappingURL=utils.js.map