Skip to content

Commit 1485314

Browse files
committed
Add option to make method enabled default
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 6589113 commit 1485314

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

acp/wpn_acp_module.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function display_settings()
101101
'S_WEBPUSH_ENABLE' => $this->config['wpn_webpush_enable'],
102102
'WEBPUSH_VAPID_PUBLIC' => $this->config['wpn_webpush_vapid_public'],
103103
'WEBPUSH_VAPID_PRIVATE' => $this->config['wpn_webpush_vapid_private'] ? self::MASKED_PRIVATE_KEY : '',
104+
'S_WEBPUSH_METHOD_ENABLED' => $this->config['wpn_webpush_method_enabled'],
104105
'U_ACTION' => $this->u_action,
105106
]);
106107
}
@@ -117,6 +118,7 @@ public function save_settings()
117118
'wpn_webpush_enable' => ['validate' => 'bool'],
118119
'wpn_webpush_vapid_public' => ['validate' => 'string:25:255', 'lang' => 'WEBPUSH_VAPID_PUBLIC'],
119120
'wpn_webpush_vapid_private'=> ['validate' => 'string:25:255', 'lang' => 'WEBPUSH_VAPID_PRIVATE'],
121+
'wpn_webpush_method_enabled' => ['validate' => 'bool'],
120122
];
121123

122124
// Do not validate and update private key field if the content is ******** and the key was already set

adm/style/wpn_acp_settings.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ <h3>{{ lang('WARNING') }}</h3>
2929
<dt><label for="webpush_vapid_private">{{ lang('WEBPUSH_VAPID_PRIVATE') ~ lang('COLON') }}</label><br><span>{{ lang('WEBPUSH_VAPID_PRIVATE_EXPLAIN') }}</span></dt>
3030
<dd><label><input id="webpush_vapid_private" type="password" name="config[wpn_webpush_vapid_private]" size="25" maxlength="255" autocomplete="off" value="{{ WEBPUSH_VAPID_PRIVATE }}"></label></dd>
3131
</dl>
32+
<dl>
33+
<dt><label>{{ lang('WEBPUSH_METHOD_ENABLED') ~ lang('COLON') }}</label><br><span>{{ lang('WEBPUSH_METHOD_ENABLED_EXPLAIN') }}</span></dt>
34+
<dd><label><input type="radio" class="radio" name="config[wpn_webpush_method_enabled]" value="1" {% if S_WEBPUSH_METHOD_ENABLED %}checked="checked"{% endif %}> {{ lang('YES') }}</label>
35+
<label><input type="radio" class="radio" name="config[wpn_webpush_method_enabled]" value="0"{% if not S_WEBPUSH_METHOD_ENABLED %} checked="checked"{% endif %}> {{ lang('NO') }}</label>
36+
</dl>
3237
</fieldset>
3338
<fieldset class="submit-buttons">
3439
<input class="button1" type="submit" id="submit" name="submit" value="{{ lang('SUBMIT') }}">&nbsp;

language/en/webpushnotifications_module_acp.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@
4646
'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) public key is shared to authenticate push messages from your site.<br><em><strong>Caution:</strong> Modifying the VAPID public key will automatically render all Web Push subscriptions invalid.</em>',
4747
'WEBPUSH_VAPID_PRIVATE' => 'Server identification private key',
4848
'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>',
49+
'WEBPUSH_METHOD_ENABLED' => 'Enable user-based web push notifications by default',
50+
'WEBPUSH_METHOD_ENABLED_EXPLAIN'=> 'When this setting is enabled, users who subscribe and allow browser notifications will start receiving them automatically. They 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 notifications they wish to receive.',
4951
]);

migrations/add_acp_configs.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
*
4+
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2024, phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\webpushnotifications\migrations;
12+
13+
use phpbb\db\migration\migration;
14+
15+
class add_acp_configs extends migration
16+
{
17+
public function effectively_installed(): bool
18+
{
19+
return $this->config->offsetExists('wpn_webpush_method_enabled');
20+
}
21+
22+
public static function depends_on()
23+
{
24+
return ['\phpbb\webpushnotifications\migrations\add_webpush'];
25+
}
26+
27+
public function update_data(): array
28+
{
29+
return [
30+
['config.add', ['wpn_webpush_method_enabled', false]],
31+
];
32+
}
33+
34+
public function revert_data(): array
35+
{
36+
return [
37+
['config.remove', ['wpn_webpush_method_enabled']],
38+
];
39+
}
40+
}

notification/method/webpush.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public function is_available(type_interface $notification_type = null): bool
9696
&& !empty($this->config['wpn_webpush_vapid_public']) && !empty($this->config['wpn_webpush_vapid_private']);
9797
}
9898

99+
public function is_enabled_by_default()
100+
{
101+
return $this->config['wpn_webpush_method_enabled'];
102+
}
103+
99104
/**
100105
* {@inheritdoc}
101106
*/

0 commit comments

Comments
 (0)