13 private const UPDATE_UI = [
21 private const UPDATE_USERS_ADD = [
25 private const UPDATE_USERS_DELETE = [
29 private const UPDATE_SETTINGS = [
33 'setManageUsersDelete',
36 'setDisappearingDate',
42 $currentUser = $this->
getAction()->getCurrentUser();
43 $arguments = $this->
getAction()->getArguments();
47 $chat = $arguments[
'chat'];
49 if (!$chat->getChatId())
54 return new EventResult(EventResult::ERROR,
null,
null, $this);
57 if ($currentUser->isAdmin())
62 if ($chat->getAuthorId() === (
int)$currentUser->getId())
67 $actionName = $this->
getAction()->getName();
68 if ($this->inArrayCaseInsensitive($actionName, self::UPDATE_UI,
true))
70 $manageRights = $chat->getManageUI();
73 if ($this->inArrayCaseInsensitive($actionName, self::UPDATE_USERS_ADD,
true))
75 $manageRights = $chat->getManageUsersAdd();
78 if ($this->inArrayCaseInsensitive($actionName, self::UPDATE_USERS_DELETE,
true))
80 $deleteUser = $arguments[
'userId'] ??
null;
82 if ((
int)$deleteUser === (
int)$currentUser->getId())
87 $manageRights = $chat->getManageUsersDelete();
90 if ($this->inArrayCaseInsensitive($actionName, self::UPDATE_SETTINGS,
true))
92 $manageRights = $chat->getManageSettings();
100 $selfRelation = $chat->getSelfRelation();
103 && $selfRelation->getManager()
112 return new EventResult(EventResult::ERROR,
null,
null, $this);
121 private function inArrayCaseInsensitive(
string $needle, array $haystack,
bool $strict =
true):
bool
123 $needle = mb_strtolower($needle);
124 $haystack = array_map(
'mb_strtolower', $haystack);
126 return in_array($needle, $haystack, $strict);
onBeforeAction(Event $event)