@@ -49,105 +49,105 @@ |
||
49 | 49 | */ |
50 | 50 | class PushProvider extends AbstractProvider { |
51 | 51 | |
52 | - /** @var string */ |
|
53 | - public const NOTIFICATION_TYPE = 'DISPLAY'; |
|
52 | + /** @var string */ |
|
53 | + public const NOTIFICATION_TYPE = 'DISPLAY'; |
|
54 | 54 | |
55 | - /** @var IManager */ |
|
56 | - private $manager; |
|
55 | + /** @var IManager */ |
|
56 | + private $manager; |
|
57 | 57 | |
58 | - /** @var ITimeFactory */ |
|
59 | - private $timeFactory; |
|
58 | + /** @var ITimeFactory */ |
|
59 | + private $timeFactory; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param IConfig $config |
|
63 | - * @param IManager $manager |
|
64 | - * @param ILogger $logger |
|
65 | - * @param L10NFactory $l10nFactory |
|
66 | - * @param IUrlGenerator $urlGenerator |
|
67 | - * @param ITimeFactory $timeFactory |
|
68 | - */ |
|
69 | - public function __construct(IConfig $config, |
|
70 | - IManager $manager, |
|
71 | - ILogger $logger, |
|
72 | - L10NFactory $l10nFactory, |
|
73 | - IURLGenerator $urlGenerator, |
|
74 | - ITimeFactory $timeFactory) { |
|
75 | - parent::__construct($logger, $l10nFactory, $urlGenerator, $config); |
|
76 | - $this->manager = $manager; |
|
77 | - $this->timeFactory = $timeFactory; |
|
78 | - } |
|
61 | + /** |
|
62 | + * @param IConfig $config |
|
63 | + * @param IManager $manager |
|
64 | + * @param ILogger $logger |
|
65 | + * @param L10NFactory $l10nFactory |
|
66 | + * @param IUrlGenerator $urlGenerator |
|
67 | + * @param ITimeFactory $timeFactory |
|
68 | + */ |
|
69 | + public function __construct(IConfig $config, |
|
70 | + IManager $manager, |
|
71 | + ILogger $logger, |
|
72 | + L10NFactory $l10nFactory, |
|
73 | + IURLGenerator $urlGenerator, |
|
74 | + ITimeFactory $timeFactory) { |
|
75 | + parent::__construct($logger, $l10nFactory, $urlGenerator, $config); |
|
76 | + $this->manager = $manager; |
|
77 | + $this->timeFactory = $timeFactory; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Send push notification to all users. |
|
82 | - * |
|
83 | - * @param VEvent $vevent |
|
84 | - * @param string $calendarDisplayName |
|
85 | - * @param IUser[] $users |
|
86 | - * @throws \Exception |
|
87 | - */ |
|
88 | - public function send(VEvent $vevent, |
|
89 | - string $calendarDisplayName=null, |
|
90 | - array $users=[]):void { |
|
91 | - if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') { |
|
92 | - return; |
|
93 | - } |
|
80 | + /** |
|
81 | + * Send push notification to all users. |
|
82 | + * |
|
83 | + * @param VEvent $vevent |
|
84 | + * @param string $calendarDisplayName |
|
85 | + * @param IUser[] $users |
|
86 | + * @throws \Exception |
|
87 | + */ |
|
88 | + public function send(VEvent $vevent, |
|
89 | + string $calendarDisplayName=null, |
|
90 | + array $users=[]):void { |
|
91 | + if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') { |
|
92 | + return; |
|
93 | + } |
|
94 | 94 | |
95 | - $eventDetails = $this->extractEventDetails($vevent); |
|
96 | - $eventDetails['calendar_displayname'] = $calendarDisplayName; |
|
97 | - $eventUUID = (string) $vevent->UID; |
|
98 | - if (!$eventUUID) { |
|
99 | - return; |
|
100 | - }; |
|
101 | - $eventUUIDHash = hash('sha256', $eventUUID, false); |
|
95 | + $eventDetails = $this->extractEventDetails($vevent); |
|
96 | + $eventDetails['calendar_displayname'] = $calendarDisplayName; |
|
97 | + $eventUUID = (string) $vevent->UID; |
|
98 | + if (!$eventUUID) { |
|
99 | + return; |
|
100 | + }; |
|
101 | + $eventUUIDHash = hash('sha256', $eventUUID, false); |
|
102 | 102 | |
103 | - foreach ($users as $user) { |
|
104 | - /** @var INotification $notification */ |
|
105 | - $notification = $this->manager->createNotification(); |
|
106 | - $notification->setApp(Application::APP_ID) |
|
107 | - ->setUser($user->getUID()) |
|
108 | - ->setDateTime($this->timeFactory->getDateTime()) |
|
109 | - ->setObject(Application::APP_ID, $eventUUIDHash) |
|
110 | - ->setSubject('calendar_reminder', [ |
|
111 | - 'title' => $eventDetails['title'], |
|
112 | - 'start_atom' => $eventDetails['start_atom'] |
|
113 | - ]) |
|
114 | - ->setMessage('calendar_reminder', $eventDetails); |
|
103 | + foreach ($users as $user) { |
|
104 | + /** @var INotification $notification */ |
|
105 | + $notification = $this->manager->createNotification(); |
|
106 | + $notification->setApp(Application::APP_ID) |
|
107 | + ->setUser($user->getUID()) |
|
108 | + ->setDateTime($this->timeFactory->getDateTime()) |
|
109 | + ->setObject(Application::APP_ID, $eventUUIDHash) |
|
110 | + ->setSubject('calendar_reminder', [ |
|
111 | + 'title' => $eventDetails['title'], |
|
112 | + 'start_atom' => $eventDetails['start_atom'] |
|
113 | + ]) |
|
114 | + ->setMessage('calendar_reminder', $eventDetails); |
|
115 | 115 | |
116 | - $this->manager->notify($notification); |
|
117 | - } |
|
118 | - } |
|
116 | + $this->manager->notify($notification); |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @var VEvent $vevent |
|
122 | - * @return array |
|
123 | - * @throws \Exception |
|
124 | - */ |
|
125 | - protected function extractEventDetails(VEvent $vevent):array { |
|
126 | - /** @var Property\ICalendar\DateTime $start */ |
|
127 | - $start = $vevent->DTSTART; |
|
128 | - $end = $this->getDTEndFromEvent($vevent); |
|
120 | + /** |
|
121 | + * @var VEvent $vevent |
|
122 | + * @return array |
|
123 | + * @throws \Exception |
|
124 | + */ |
|
125 | + protected function extractEventDetails(VEvent $vevent):array { |
|
126 | + /** @var Property\ICalendar\DateTime $start */ |
|
127 | + $start = $vevent->DTSTART; |
|
128 | + $end = $this->getDTEndFromEvent($vevent); |
|
129 | 129 | |
130 | - return [ |
|
131 | - 'title' => isset($vevent->SUMMARY) |
|
132 | - ? ((string) $vevent->SUMMARY) |
|
133 | - : null, |
|
134 | - 'description' => isset($vevent->DESCRIPTION) |
|
135 | - ? ((string) $vevent->DESCRIPTION) |
|
136 | - : null, |
|
137 | - 'location' => isset($vevent->LOCATION) |
|
138 | - ? ((string) $vevent->LOCATION) |
|
139 | - : null, |
|
140 | - 'all_day' => $start instanceof Property\ICalendar\Date, |
|
141 | - /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
142 | - 'start_atom' => $start->getDateTime()->format(\DateTime::ATOM), |
|
143 | - 'start_is_floating' => $start->isFloating(), |
|
144 | - /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
145 | - 'start_timezone' => $start->getDateTime()->getTimezone()->getName(), |
|
146 | - /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
147 | - 'end_atom' => $end->getDateTime()->format(\DateTime::ATOM), |
|
148 | - 'end_is_floating' => $end->isFloating(), |
|
149 | - /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
150 | - 'end_timezone' => $end->getDateTime()->getTimezone()->getName(), |
|
151 | - ]; |
|
152 | - } |
|
130 | + return [ |
|
131 | + 'title' => isset($vevent->SUMMARY) |
|
132 | + ? ((string) $vevent->SUMMARY) |
|
133 | + : null, |
|
134 | + 'description' => isset($vevent->DESCRIPTION) |
|
135 | + ? ((string) $vevent->DESCRIPTION) |
|
136 | + : null, |
|
137 | + 'location' => isset($vevent->LOCATION) |
|
138 | + ? ((string) $vevent->LOCATION) |
|
139 | + : null, |
|
140 | + 'all_day' => $start instanceof Property\ICalendar\Date, |
|
141 | + /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
142 | + 'start_atom' => $start->getDateTime()->format(\DateTime::ATOM), |
|
143 | + 'start_is_floating' => $start->isFloating(), |
|
144 | + /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
145 | + 'start_timezone' => $start->getDateTime()->getTimezone()->getName(), |
|
146 | + /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
147 | + 'end_atom' => $end->getDateTime()->format(\DateTime::ATOM), |
|
148 | + 'end_is_floating' => $end->isFloating(), |
|
149 | + /** @phan-suppress-next-line PhanUndeclaredClassMethod */ |
|
150 | + 'end_timezone' => $end->getDateTime()->getTimezone()->getName(), |
|
151 | + ]; |
|
152 | + } |
|
153 | 153 | } |