34 $this->userId = $userId;
38 $bindings = $cache->getValue();
39 if (!empty($bindings))
44 return $result->setResult(
true);
48 OptionUserTable::query()
51 ->where(
'USER_ID', $userId)
55 $bindings = $query->fetch();
56 if ($bindings ===
false)
58 $presetId = Configuration::restoreBindings($userId);
74 return $result->setResult(
true);
79 $settingsBeforeUpdate = ($settingsConfiguration[
'name'] ===
'pinnedChatSort')
84 if (!$this->generalPreset->isPersonal($this->userId))
86 $personalPreset = Preset::getPersonal($this->userId);
88 if ($personalPreset->isExist())
90 $this->generalPreset = $personalPreset;
94 $personalPreset = Preset::getInstance();
95 $personalPreset->initPersonal($this->userId);
96 $this->generalPreset = $personalPreset;
99 $this->generalPreset->bindToUser($this->userId, [Preset::BIND_GENERAL]);
103 $this->generalPreset->general->updateSetting($settingsConfiguration);
106 if (!$this->generalPreset->general->shouldUpdateSimpleNotifySettings($settingsConfiguration))
112 if (!$this->notifyPreset->isPersonal($this->userId))
115 $this->notifyPreset->
bindToUser($this->userId, [Preset::BIND_NOTIFY]);
119 $simpleSchema = $this->generalPreset->general->getSimpleNotifyScheme();
120 $this->notifyPreset->notify->updateSimpleSettings($simpleSchema);
131 if (!$this->notifyPreset->isPersonal($this->userId))
142 $this->notifyPreset->
bindToUser($this->userId, [Preset::BIND_NOTIFY]);
146 $this->notifyPreset->notify->updateSetting($settingsConfiguration);
155 return \CIMStatus::Set($this->userId, [
'STATUS' => $status]);
160 if ($this->generalPreset->getId() ===
null)
162 $this->recoveryBinding(Preset::BIND_GENERAL);
165 if ($this->generalPreset->general ===
null)
167 $this->generalPreset = Preset::getDefaultPreset();
170 return $this->generalPreset->general->toRestFormat();
175 if ($this->notifyPreset->getId() ===
null)
177 $this->recoveryBinding(Preset::BIND_NOTIFY);
180 if ($this->notifyPreset->notify ===
null)
182 $this->notifyPreset = Preset::getDefaultPreset();
185 return $this->notifyPreset->notify->toRestFormat();
188 protected function perfomSideEffect(array $settingConfiguration, ?array $settingsBeforeUpdate)
190 $this->updateUserSearch($settingConfiguration);
191 $this->openDesktopFromPanel($settingConfiguration);
193 if (isset($settingsBeforeUpdate))
195 $this->updatePinSortCost($settingConfiguration, $settingsBeforeUpdate);
199 private function updateUserSearch(array $settingsConfiguration): void
201 $defaultSettings = General::getDefaultSettings();
204 $settingsConfiguration[
'name'] ===
Entity\General::PRIVACY_SEARCH
205 && $this->checkUserSearch($settingsConfiguration[
'value'])
209 $defaultSettings[Entity\General::PRIVACY_SEARCH] === $settingsConfiguration[
'value']
211 : $settingsConfiguration[
'value']
214 \Bitrix\Main\Application::getUserTypeManager()->Update(
218 'UF_IM_SEARCH' => $value
224 private function checkUserSearch($settingValue): bool
226 return in_array($settingValue, [General::PRIVACY_RESULT_ALL, General::PRIVACY_RESULT_CONTACT],
true);
229 private function recoveryBinding(
string $toEntity)
231 $userPreset = Preset::getPersonal($this->userId);
234 $userPreset->isExist()
236 : Preset::getDefaultPreset()
238 $bindingPreset->bindToUser($this->userId, [$toEntity]);
240 if ($toEntity === Preset::BIND_GENERAL)
242 $this->generalPreset = $bindingPreset;
246 $this->notifyPreset = $bindingPreset;
252 private function openDesktopFromPanel(array $settingsConfiguration): void
255 $settingsConfiguration[
'name'] === Entity\General::OPEN_DESKTOP_FROM_PANEL
256 && CModule::IncludeModule(
'pull')
259 Event::add($this->userId, [
261 'command' =>
'settingsUpdate',
264 'openDesktopFromPanel' => $settingsConfiguration[
'value'],
273 return $this->generalPreset->isPersonal($this->userId);
278 return $this->generalPreset->getId();
281 private function updatePinSortCost(array $settingsConfiguration, array $settingsBeforeUpdate): void
283 if ($settingsConfiguration[
'name'] ===
'pinnedChatSort'
284 && $settingsConfiguration[
'value'] !==
'byDate'
287 if ($settingsBeforeUpdate[
'pinnedChatSort'] !==
'byCost')