Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Friedman <maf675@gmail.com>
  • Loading branch information
iMattPro committed Oct 3, 2024
1 parent bd5469b commit 1b1da0b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
13 changes: 12 additions & 1 deletion notification/method/webpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ public function notify()
{
$data = $notification->get_insert_array();
$data += [
'push_data' => json_encode(array_merge($notification->get_insert_array(), ['notification_type_name' => $notification->get_type()])),
'push_data' => json_encode(array_merge(
$data,
['notification_type_name' => $notification->get_type()]
)),
'notification_time' => time(),
'push_token' => hash('sha256', random_bytes(32))
];
Expand Down Expand Up @@ -349,6 +352,14 @@ public static function clean_data(array $data): array
return array_intersect_key($data, $row);
}

/**
* Get template data for the UCP
*
* @param helper $controller_helper
* @param form_helper $form_helper
*
* @return array
*/
public function get_ucp_template_data(helper $controller_helper, form_helper $form_helper): array
{
$subscription_map = $this->get_user_subscription_map([$this->user->id()]);
Expand Down
24 changes: 8 additions & 16 deletions ucp/controller/webpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ private function get_anonymous_notifications(): string
throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
}

/**
* Get notification data for output from json encoded data stored in database
*
* @param string $notification_data Encoded data stored in database
*
* @return string Data for notification output with javascript
*/
private function get_notification_data(string $notification_data): string
{
$row_data = json_decode($notification_data, true);
Expand All @@ -229,7 +236,7 @@ private function get_notification_data(string $notification_data): string
$notification = $this->notification_manager->get_item_type_class($row_data['notification_type_name'], $row_data);

// Load users for notification
$this->user_loader->load_users($notification->users_to_query(), [USER_IGNORE]);
$this->user_loader->load_users($notification->users_to_query());

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

/**
* Get template variables for subscribe type pages
*
* @return array
*/
protected function get_subscribe_vars(): array
{
return [
'U_WEBPUSH_SUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_subscribe_controller'),
'U_WEBPUSH_UNSUBSCRIBE' => $this->controller_helper->route('phpbb_webpushnotifications_ucp_push_unsubscribe_controller'),
'FORM_TOKENS' => $this->form_helper->get_form_tokens(self::FORM_TOKEN_UCP),
];
}

/**
* Check (un)subscribe form for valid link hash
*
Expand Down

0 comments on commit 1b1da0b

Please sign in to comment.