-
Notifications
You must be signed in to change notification settings - Fork 64
Front/webpush #2663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
p1gp1g
wants to merge
35
commits into
nextcloud:master
Choose a base branch
from
p1gp1g:front/webpush
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+469
−38
Open
Front/webpush #2663
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
7a24394
feat(webpush): Receive push notifications with web push
p1gp1g 3560525
feat(webpush): Do not fetch on (web) push if notify_push is used
p1gp1g d9c03cb
feat(webpush): Fix webpush setup after permission granted
p1gp1g 26355cb
feat(webpush): Use new appTypes format
p1gp1g 6fe15ae
feat(webpush): Lint
p1gp1g 3e34f6c
feat(webpush): Add serviceWorker to OpenApi
p1gp1g 8b1ea99
feat(webpush): Fix force param
p1gp1g b766876
feat(webpush): Lint js
p1gp1g 78d4d65
feat(webpush): Allow using webpush from web session
p1gp1g fab581e
feat(webpush): typo
p1gp1g ded6dd6
feat(webpush): Add push subscription options
p1gp1g 85cf5b6
feat(webpush): Fix OpenAPI for service worker
p1gp1g bf102db
feat(webpush): Improve notification content from the background
p1gp1g 1e69c30
feat(webpush): Add hack to avoid being unregistered on silent notific…
p1gp1g e4ec6ef
feat(webpush): Subscribe with server VAPID key
p1gp1g 3c750da
feat(webpush): Fix push for web session with ID=0
p1gp1g bf8f2f4
feat(webpush): Use single B64 URL-safe function
p1gp1g 7e12f36
feat(webpush): Register with userVisibleOnly, only if silent push are…
p1gp1g df0292f
feat(webpush): Show silent notification only if needed
p1gp1g fa9d612
fix(webpush): Add worker src domain self
nickvergessen c270710
Update lib/Controller/WebController.php
p1gp1g 993c304
feat(webpush): Call callback(false) if browser doesn't support servic…
p1gp1g 3f733f1
feat(webpush): Use full name for arguments
p1gp1g 0347024
feat(webpush): Keep requestWebNotificationPermissions async
p1gp1g 730f420
feat(webpush): Move web push function to dedicated service file
p1gp1g 9017d4d
fix: Add missing class imports
nickvergessen 1129957
feat(webpush): Use better secure context check
p1gp1g fa870cb
feat(webpush): Lint debugging line
p1gp1g 11109c7
feat(webpush): Always catch when browser need userVisibleOnly
p1gp1g 17d09f6
feat(webpush): Avoid redundant code to set web push
p1gp1g b962973
feat(webpush): Use web push dedicated function to fetch notifications
p1gp1g 8c22c5e
feat(webpush): Add SPDX header
p1gp1g d380839
Fix hasNotifyPush check
p1gp1g 946a5e7
chore(assets): Recompile assets
nickvergessen a42e9db
fix(webpush): Fix psalm in WebController
nickvergessen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Notifications\Controller; | ||
|
|
||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\Attribute\FrontpageRoute; | ||
| use OCP\AppFramework\Http\Attribute\NoCSRFRequired; | ||
| use OCP\AppFramework\Http\Attribute\OpenAPI; | ||
| use OCP\AppFramework\Http\Attribute\PublicPage; | ||
| use OCP\AppFramework\Http\ContentSecurityPolicy; | ||
| use OCP\AppFramework\Http\StreamResponse; | ||
| use OCP\IRequest; | ||
|
|
||
| #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] | ||
| class WebController extends Controller { | ||
| public function __construct( | ||
| string $appName, | ||
| IRequest $request, | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
| } | ||
| /** | ||
| * Return the service worker with `Service-Worker-Allowed: /` header | ||
| * | ||
| * @return StreamResponse<Http::STATUS_OK, array{'Content-Type': 'application/javascript', 'Service-Worker-Allowed': '/'}> | ||
| * | ||
| * 200: The service worker | ||
| */ | ||
| #[PublicPage] | ||
| #[NoCSRFRequired] | ||
| #[FrontpageRoute(verb: 'GET', url: '/service-worker.js')] | ||
| public function serviceWorker(): StreamResponse { | ||
| $response = new StreamResponse( | ||
| __DIR__ . '/../../service-worker.js', | ||
| headers: [ | ||
| 'Content-Type' => 'application/javascript', | ||
| 'Service-Worker-Allowed' => '/' | ||
| ] | ||
| ); | ||
| $policy = new ContentSecurityPolicy(); | ||
| $policy->addAllowedWorkerSrcDomain("'self'"); | ||
| $policy->addAllowedScriptDomain("'self'"); | ||
| $policy->addAllowedConnectDomain("'self'"); | ||
| $response->setContentSecurityPolicy($policy); | ||
| return $response; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Notifications\Listener; | ||
|
|
||
| use OCP\AppFramework\Http\ContentSecurityPolicy; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
| use OCP\IUser; | ||
| use OCP\IUserSession; | ||
| use OCP\Security\CSP\AddContentSecurityPolicyEvent; | ||
|
|
||
| /** | ||
| * @template-implements IEventListener<Event> | ||
| */ | ||
| readonly class CSPListener implements IEventListener { | ||
| public function __construct( | ||
| protected IUserSession $userSession, | ||
| ) { | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function handle(Event $event): void { | ||
| if (!($event instanceof AddContentSecurityPolicyEvent)) { | ||
| return; | ||
| } | ||
|
|
||
| $user = $this->userSession->getUser(); | ||
| if (!$user instanceof IUser) { | ||
| return; | ||
| } | ||
|
|
||
| $csp = new ContentSecurityPolicy(); | ||
| $csp->addAllowedWorkerSrcDomain("'self'"); | ||
| $event->addPolicy($csp); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.