18 private const GENERAL =
'general';
19 private const NOTIFY =
'notify';
21 private const PRIVACY_SEARCH =
'privacySearch';
22 private const STATUS =
'status';
33 $result->addError(
new Error($exception->getMessage(), $exception->getCode()));
37 $result->setData($preset);
53 !array_key_exists(self::NOTIFY, $settings)
54 || !array_key_exists(self::GENERAL, $settings)
57 $result->addError(
new Error(
'Incorrect data when receiving chat settings', 400));
61 self::updateUserStatus($userId, $settings[
'general']);
63 self::sendSettingsChangeEvent($userId, $settings[
'general']);
65 self::disableUserSearch($userId, $settings[
'general']);
67 if (isset($settings[
'general'][
'notifyScheme']) && $settings[
'general'][
'notifyScheme'] ===
'simple')
73 \Bitrix\Im\Model\OptionGroupTable::query()
75 ->where(
'USER_ID', $userId)
83 CacheManager::getUserCache($userId)->clearCache();
84 self::enableUserSearch($userId, $settings[
'general']);
89 $userPresetId = $userPresetId[
'ID'];
93 CacheManager::getPresetCache($userPresetId)->clearCache();
95 self::enableUserSearch($userId, $settings[
'general']);
103 if (!in_array($type, [self::NOTIFY, self::GENERAL],
true))
105 $result->addError(
new Error(
'Incorrect data when receiving chat settings', 400));
110 \Bitrix\Im\Model\OptionGroupTable::query()
112 ->where(
'USER_ID', $userId)
115 $userPresetId = $userPresetId[
'ID'] ??
null;
117 if ($type === self::NOTIFY)
121 $preset[
'notify'] = $settings;
122 $preset[
'general'] = [];
130 if ($type === self::GENERAL)
132 self::updateUserStatus($userId, $settings);
134 self::sendSettingsChangeEvent($userId, $settings);
136 self::disableUserSearch($userId, $settings);
141 $preset[
'notify'] = [];
148 self::enableUserSearch($userId, $settings);
151 CacheManager::getPresetCache($userPresetId)->clearCache();
152 CacheManager::getUserCache($userId)->clearCache();
160 COption::GetOptionString(
'im',
'migration_to_new_settings') ===
'Y'
167 $lastConvertedId = COption::GetOptionInt(
'im',
'last_converted_user');
168 return $userId < $lastConvertedId;
174 $notifyScheme = $generalSettings->getValue(
'notifyScheme');
176 if ($notifyScheme !==
'expert')
180 return $generalSettings->getValue(
'notifySchemeSendSite');
184 return $generalSettings->getValue(
'notifySchemeSendEmail');
188 return $generalSettings->getValue(
'notifySchemeSendPush');
192 return $generalSettings->getValue(
'notifySchemeSendXmpp');
196 return (
new Notification($moduleId, $eventId))->isAllowed($userId, $type);
199 private static function sendSettingsChangeEvent(
int $userId, array $generalSettings): void
202 if (isset($generalSettings[
'openDesktopFromPanel']) && CModule::IncludeModule(
'pull'))
204 Event::add($userId, [
206 'command' =>
'settingsUpdate',
209 'openDesktopFromPanel' => $generalSettings[
'openDesktopFromPanel'],
216 private static function disableUserSearch(
int $userId, array $generalSettings): void
220 array_key_exists(self::PRIVACY_SEARCH, $generalSettings)
221 && $defaultSettings[self::PRIVACY_SEARCH] === $generalSettings[self::PRIVACY_SEARCH]
224 global $USER_FIELD_MANAGER;
225 $USER_FIELD_MANAGER->Update(
"USER", $userId, [
'UF_IM_SEARCH' =>
'']);
229 private static function enableUserSearch(
int $userId, array $generalSettings): void
231 if (isset($generalSettings[self::PRIVACY_SEARCH]))
233 global $USER_FIELD_MANAGER;
234 $USER_FIELD_MANAGER->Update(
238 'UF_IM_SEARCH' => $generalSettings[self::PRIVACY_SEARCH],
244 private static function updateUserStatus(
int $userId, array $generalSettings): void
246 if (isset($generalSettings[self::STATUS]))
248 \CIMStatus::Set($userId, [
'STATUS' => $generalSettings[self::STATUS]]);