Skip to content

Commit 9ef8134

Browse files
committed
Code cleanup
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 7192343 commit 9ef8134

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

notification/method/webpush.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ public function notify()
144144
{
145145
$data = $notification->get_insert_array();
146146
$data += [
147-
'push_data' => json_encode(array_merge($notification->get_insert_array(), ['notification_type_name' => $notification->get_type()])),
147+
'push_data' => json_encode(array_merge(
148+
$data,
149+
['notification_type_name' => $notification->get_type()]
150+
)),
148151
'notification_time' => time(),
149152
'push_token' => hash('sha256', random_bytes(32))
150153
];
@@ -349,6 +352,14 @@ public static function clean_data(array $data): array
349352
return array_intersect_key($data, $row);
350353
}
351354

355+
/**
356+
* Get template data for the UCP
357+
*
358+
* @param helper $controller_helper
359+
* @param form_helper $form_helper
360+
*
361+
* @return array
362+
*/
352363
public function get_ucp_template_data(helper $controller_helper, form_helper $form_helper): array
353364
{
354365
$subscription_map = $this->get_user_subscription_map([$this->user->id()]);

ucp/controller/webpush.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ private function get_anonymous_notifications(): string
215215
throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
216216
}
217217

218+
/**
219+
* Get notification data for output from json encoded data stored in database
220+
*
221+
* @param string $notification_data Encoded data stored in database
222+
*
223+
* @return string Data for notification output with javascript
224+
*/
218225
private function get_notification_data(string $notification_data): string
219226
{
220227
$row_data = json_decode($notification_data, true);
@@ -229,7 +236,7 @@ private function get_notification_data(string $notification_data): string
229236
$notification = $this->notification_manager->get_item_type_class($row_data['notification_type_name'], $row_data);
230237

231238
// Load users for notification
232-
$this->user_loader->load_users($notification->users_to_query(), [USER_IGNORE]);
239+
$this->user_loader->load_users($notification->users_to_query());
233240

234241
return json_encode([
235242
'heading' => $this->config['sitename'],
@@ -250,7 +257,6 @@ private function get_notification_data(string $notification_data): string
250257
*/
251258
public function worker(): Response
252259
{
253-
// @todo: only work for logged in users, no anonymous & bot
254260
$content = $this->template->render('@phpbb_webpushnotifications/push_worker.js.twig', [
255261
'U_WEBPUSH_GET_NOTIFICATION' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_get_notification_controller'),
256262
'ASSETS_VERSION' => $this->config['assets_version'],
@@ -268,20 +274,6 @@ public function worker(): Response
268274
return $response;
269275
}
270276

271-
/**
272-
* Get template variables for subscribe type pages
273-
*
274-
* @return array
275-
*/
276-
protected function get_subscribe_vars(): array
277-
{
278-
return [
279-
'U_WEBPUSH_SUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_subscribe_controller'),
280-
'U_WEBPUSH_UNSUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_unsubscribe_controller'),
281-
'FORM_TOKENS' => $this->form_helper->get_form_tokens(self::FORM_TOKEN_UCP),
282-
];
283-
}
284-
285277
/**
286278
* Check (un)subscribe form for valid link hash
287279
*

0 commit comments

Comments
 (0)