28 $this->userId = $userId;
29 $this->message = $message;
30 $this->storage = $storage;
35 $storage = new \Bitrix\Mail\Storage\MessageAccess();
36 return new self($userId, $message, $storage);
41 $messageStorage = new \Bitrix\Mail\Storage\Message();
42 $message = $messageStorage->getMessage($messageId);
54 $userId = $USER->GetID();
58 throw new \Bitrix\Main\SystemException(
'message access: user id error');
61 return $message instanceof \Bitrix\Mail\Item\Message
68 return (
bool)self::getUserMailbox($this->getMessage()->getMailboxId(), $this->getUserId());
73 return ActivityTable::getList([
79 '==ID' => $activityId,
85 public function getEntitiesForType($entityType): array
87 $collection = $this->getCollection($this->getMessage());
92 foreach ($collection as $item)
94 if ($item->getEntityType() === $entityType)
96 $bindings[] = $item->getEntityId();
107 public function canViewMessage(): bool
114 $collection = $this->getCollection($this->getMessage());
117 foreach ($collection as $item)
119 switch ($item->getEntityType())
122 if (\
Bitrix\
Mail\Helper\MessageAccess::checkAccessForChat($item->getEntityId(), $this->getUserId()))
128 if (\
Bitrix\
Mail\Helper\MessageAccess::checkAccessForCalendarEvent($item->getEntityId(), $this->getUserId()))
146 return $this->message;
149 private function getUserId(): int
151 return $this->userId;
154 private function getStorage(): IMessageAccessStorage
156 return $this->storage;
159 private function getCollection(\
Bitrix\
Mail\Item\Message $item): \
Bitrix\
Mail\Collection\MessageAccess
161 return $this->getStorage()->getCollectionForMessage($item);
164 private static function getUserMailbox(
int $mailboxId,
int $userId)