mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17343] Clean up code for webpush output
PHPBB-17343
This commit is contained in:
parent
73a06ef4df
commit
1ed5670afe
2 changed files with 19 additions and 16 deletions
|
@ -140,7 +140,10 @@ class webpush extends messenger_base implements extended_method_interface
|
|||
{
|
||||
$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))
|
||||
];
|
||||
|
@ -345,6 +348,14 @@ class webpush extends messenger_base implements extended_method_interface
|
|||
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()]);
|
||||
|
|
|
@ -220,6 +220,13 @@ class webpush
|
|||
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);
|
||||
|
@ -255,7 +262,6 @@ class webpush
|
|||
*/
|
||||
public function worker(): Response
|
||||
{
|
||||
// @todo: only work for logged in users, no anonymous & bot
|
||||
$content = $this->template->render('push_worker.js.twig', [
|
||||
'U_WEBPUSH_GET_NOTIFICATION' => $this->controller_helper->route('phpbb_ucp_push_get_notification_controller'),
|
||||
'ASSETS_VERSION' => $this->config['assets_version'],
|
||||
|
@ -273,20 +279,6 @@ class webpush
|
|||
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_ucp_push_subscribe_controller'),
|
||||
'U_WEBPUSH_UNSUBSCRIBE' => $this->controller_helper->route('phpbb_ucp_push_unsubscribe_controller'),
|
||||
'FORM_TOKENS' => $this->form_helper->get_form_tokens(self::FORM_TOKEN_UCP),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check (un)subscribe form for valid link hash
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue