[ticket/17333] Add push subscribe toggle to notification dropdown

PHPBB-17333

Signed-off-by: Matt Friedman <maf675@gmail.com>
This commit is contained in:
Matt Friedman 2024-06-04 09:34:02 -07:00
parent e35a6f7aa5
commit d55ec608ec
No known key found for this signature in database
12 changed files with 51 additions and 8 deletions

View file

@ -495,6 +495,7 @@ class acp_board
'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true],
'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true],
'webpush_method_enables' => ['lang' => 'WEBPUSH_METHOD_ENABLES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'webpush_dropdown_subscribe'=> ['lang' => 'WEBPUSH_DROPDOWN_SUBSCRIBE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'legend3' => 'ACP_SUBMIT_CHANGES',
],

View file

@ -3853,6 +3853,9 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
$timezone_name = $user->lang['timezones'][$timezone_name];
}
/** @var \phpbb\controller\helper $controller_helper */
$controller_helper = $phpbb_container->get('controller.helper');
// Output the notifications
$notifications = false;
if ($config['load_notifications'] && $config['allow_board_notifications'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_type'] != USER_IGNORE)
@ -3869,10 +3872,19 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
{
$template->assign_block_vars('notifications', $notification->prepare_for_display());
}
// Get web push notification data
$methods = $phpbb_notifications->get_subscription_methods();
if ($config['webpush_dropdown_subscribe'] && array_key_exists('notification.method.webpush', $methods))
{
/** @var \phpbb\form\form_helper $form_helper */
$form_helper = $phpbb_container->get('form_helper');
$template_ary = $methods['notification.method.webpush']['method']->get_ucp_template_data($controller_helper, $form_helper);
$template->assign_vars($template_ary);
}
}
/** @var \phpbb\controller\helper $controller_helper */
$controller_helper = $phpbb_container->get('controller.helper');
$notification_mark_hash = generate_link_hash('mark_all_notifications_read');
$phpbb_version_parts = explode('.', PHPBB_VERSION, 3);

View file

@ -330,6 +330,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', '
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', '');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', '');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_enables', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_dropdown_subscribe', '0');
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1);

View file

@ -592,6 +592,8 @@ $lang = array_merge($lang, [
'WEBPUSH_VAPID_PRIVATE_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) private key is used to generate authenticated push messages dispatched from your site. The VAPID private key <strong>must</strong> form a valid public-private key pair alongside the VAPID public key.<br><em><strong>Caution:</strong> Modifying the VAPID private key will automatically render all Web Push subscriptions invalid.</em>',
'WEBPUSH_METHOD_ENABLES' => 'Enable all user-based web push notification options by default',
'WEBPUSH_METHOD_ENABLES_EXPLAIN'=> 'When this setting is enabled, users who subscribe and allow browser notifications will start receiving them automatically. Users only need to visit the UCP Notification settings to disable any unwanted notifications.<br><br>If this setting is disabled, users will not receive any notifications, even if they have subscribed, until they visit the UCP Notification settings to enable the specific notification options they wish to receive.',
'WEBPUSH_DROPDOWN_SUBSCRIBE' => 'Show “Subscribe” button in notification dropdown',
'WEBPUSH_DROPDOWN_SUBSCRIBE_EXPLAIN'=> 'Display a “Subscribe” button in the Notification dropdown, allowing users to easily subscribe to push notifications from anywhere in the forum.',
]);
// Jabber settings

View file

@ -512,6 +512,9 @@ $lang = array_merge($lang, array(
),
'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.',
'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: <a href="mailto:%1$s">%1$s</a>',
'NOTIFY_WEB_PUSH_ENABLE' => 'Enable Web Push notifications',
'NOTIFY_WEB_PUSH_SUBSCRIBE' => 'Subscribe',
'NOTIFY_WEB_PUSH_SUBSCRIBED'=> 'Subscribed',
'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.',
'NO_ACTION' => 'No action specified.',
'NO_ADMINISTRATORS' => 'There are no administrators.',

View file

@ -26,13 +26,14 @@ class add_webpush_options extends migration
public function effectively_installed(): bool
{
return $this->config->offsetExists('webpush_method_enables');
return $this->config->offsetExists('webpush_method_enables') || $this->config->offsetExists('webpush_dropdown_subscribe');
}
public function update_data(): array
{
return [
['config.add', ['webpush_method_enables', false]],
['config.add', ['webpush_dropdown_subscribe', false]],
];
}
@ -40,6 +41,7 @@ class add_webpush_options extends migration
{
return [
['config.remove', ['webpush_method_enables']],
['config.remove', ['webpush_dropdown_subscribe']],
];
}
}

View file

@ -355,7 +355,7 @@ class webpush extends messenger_base implements extended_method_interface
}
return [
'NOTIFICATIONS_WEBPUSH_ENABLE' => true,
'NOTIFICATIONS_WEBPUSH_ENABLE' => $this->config['webpush_dropdown_subscribe'] || stripos($this->user->page['page'], 'notification_options'),
'U_WEBPUSH_SUBSCRIBE' => $controller_helper->route('phpbb_ucp_push_subscribe_controller'),
'U_WEBPUSH_UNSUBSCRIBE' => $controller_helper->route('phpbb_ucp_push_unsubscribe_controller'),
'VAPID_PUBLIC_KEY' => $this->config['webpush_vapid_public'],

View file

@ -44,6 +44,13 @@
<div class="footer">
<a href="{U_VIEW_ALL_NOTIFICATIONS}"><span>{L_SEE_ALL}</span></a>
</div>
{% if NOTIFICATIONS_WEBPUSH_ENABLE and notification_types is not defined %}
<div class="notification-dropdown-footer">
<span class="ellipsis-text">{{ lang('NOTIFY_WEB_PUSH_ENABLE') ~ lang('COLON') }}</span>
<button id="subscribe_webpush" name="subscribe_webpush" class="notification-subscribe_toggle">{{ Icon('font', 'toggle-off', lang('NOTIFY_WEB_PUSH_SUBSCRIBE'), false, 'icon-lightgray') }}</button>
<button id="unsubscribe_webpush" name="unsubscribe_webpush" class="notification-subscribe_toggle hidden">{{ Icon('font', 'toggle-on', lang('NOTIFY_WEB_PUSH_SUBSCRIBED'), false, 'icon-blue') }}</button>
</div>
{% endif %}
{% EVENT notification_dropdown_footer_after %}
</div>
</div>

View file

@ -63,6 +63,10 @@
<!-- EVENT overall_header_stylesheets_after -->
{% if NOTIFICATIONS_WEBPUSH_ENABLE %}
{% include('ucp_notifications_webpush.html') %}
{% endif %}
</head>
<body id="phpbb" class="nojs notouch section-{SCRIPT_NAME} {S_CONTENT_DIRECTION} {BODY_CLASS}">

View file

@ -1,9 +1,5 @@
{% include('ucp_header.html') %}
{% if NOTIFICATIONS_WEBPUSH_ENABLE %}
{% include('ucp_notifications_webpush.html') %}
{% endif %}
<form id="ucp" method="post" action="{{ S_UCP_ACTION }}"{{ S_FORM_ENCTYPE }}>
<h2 class="cp-title">{{ TITLE }}</h2>

View file

@ -220,3 +220,9 @@ button::-moz-focus-inner {
.avatar-cropper-buttons > .button-group {
margin: 4px;
}
/* Notification buttons
--------------------------------------------- */
.notification-subscribe_toggle:disabled {
opacity: 0.7;
}

View file

@ -1340,6 +1340,15 @@ ul.linklist:after,
display: block;
}
.dropdown-extended .notification-dropdown-footer {
white-space: nowrap;
border-top: solid 1px #b9b9b9;
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
padding: 5px 10px;
}
.notification-avatar,
.notification-menu .notification-list .notification-item .avatar,
.notification-menu .notification-list .notification-item .gravatar {