Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Mail.php
1<?php
2
3namespace Bitrix\Im\V2;
4
8
9class Mail
10{
11 protected const LAST_SEND_MESSAGE = 'last_send_mail_message';
12 protected const LAST_SEND_NOTIFICATION = 'last_send_mail_notification';
13 protected const SEND_DELAY_OPTION_NAME = 'send_mail_delay_seconds';
14 protected const MODULE_ID = 'im';
15
16 protected const DEFAULT_SEND_DELAY = 600;
17
22 public function getMessageIdsToSend(): array
23 {
24 $lastSend = (int)Option::get(static::MODULE_ID, self::LAST_SEND_MESSAGE, 0);
25
26 return $this->getMessageIdsToSendByType(\IM_MESSAGE_PRIVATE, $lastSend);
27 }
28
33 public function getNotificationIdsToSend(?int $limit = null): array
34 {
35 $lastSend = (int)Option::get(static::MODULE_ID, self::LAST_SEND_NOTIFICATION, 0);
36
37 return $this->getMessageIdsToSendByType(\IM_MESSAGE_SYSTEM, $lastSend, $limit);
38 }
39
40 protected function getMessageIdsToSendByType(string $type, int $lastSend, ?int $limit = null): array
41 {
42 $sendDelayInSeconds = (int)Option::get(static::MODULE_ID, self::SEND_DELAY_OPTION_NAME, self::DEFAULT_SEND_DELAY);
43 $sendDelayInSeconds = abs($sendDelayInSeconds);
44 $readDeadline = (new DateTime())->add("-{$sendDelayInSeconds} seconds");
45 $query = MessageUnreadTable::query()
46 ->setSelect(['MESSAGE_ID'])
47 ->where('MESSAGE_ID', '>', $lastSend)
48 ->where('CHAT_TYPE', $type)
49 ->where('DATE_CREATE', '<', $readDeadline)
50 ;
51
52 if (isset($limit))
53 {
54 $query->setLimit($limit);
55 }
56
57 return $query
58 ->fetchCollection()
59 ->getMessageIdList()
60 ;
61 }
62}
const LAST_SEND_NOTIFICATION
Definition Mail.php:12
const DEFAULT_SEND_DELAY
Definition Mail.php:16
const MODULE_ID
Definition Mail.php:14
getNotificationIdsToSend(?int $limit=null)
Definition Mail.php:33
const SEND_DELAY_OPTION_NAME
Definition Mail.php:13
getMessageIdsToSend()
Definition Mail.php:22
const LAST_SEND_MESSAGE
Definition Mail.php:11
getMessageIdsToSendByType(string $type, int $lastSend, ?int $limit=null)
Definition Mail.php:40