-
Notifications
You must be signed in to change notification settings - Fork 35
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
Push notifications #429
Open
mpw-wwu
wants to merge
15
commits into
rubenarslan:develop
Choose a base branch
from
mpw-wwu:push-notifications
base: develop
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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.
Open
Push notifications #429
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
40e2149
Merge branch 'hotfix/v0.18.3'
cyriltata 55b11ac
Added empty ServiceWorker.
mpw-wwu fbf3d63
demo notification from SW, added logo
mpw-wwu 6a93a8e
Proof of concept push notification
mpw-wwu 0256505
Adding Web-App Manifest
mpw-wwu 82ab763
patch for push_subscriptions in database
mpw-wwu 40069b1
Store Push subscriptions to database
mpw-wwu 856ed02
Activating PwaController
mpw-wwu 9531978
Upate database structure for push_subscriptions table
mpw-wwu ec1abd9
Add minishlink/web-push to requirements. This library will be used to…
mpw-wwu da7eb31
Dispatch push notifications together with emails.
mpw-wwu 78e1d9c
Include Run-URL in push message
mpw-wwu d4cde45
PushNotifications: Fix dynamic url passthrough
mpw-wwu 8e70e10
Fix: Firefox on Android
mpw-wwu 061a819
minor adjustments, still broken
mpw-wwu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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,45 @@ | ||
<?php | ||
|
||
class PwaController extends Controller { | ||
|
||
public function __construct(Site &$site) { | ||
parent::__construct($site); | ||
if (!Request::isAjaxRequest()) { | ||
$default_assets = get_default_assets('site'); | ||
$this->registerAssets($default_assets); | ||
} | ||
} | ||
|
||
public function pwaAction() { | ||
error_log('pwaAction in PwaController called'); | ||
|
||
|
||
|
||
} | ||
|
||
public function subscribeAction() { | ||
$_POST = json_decode(file_get_contents('php://input'), true); | ||
$run = new Run($this->getDB(), $_POST['runname']); | ||
|
||
try { | ||
$this->getDB()->insert('survey_push_subscriptions', array( | ||
'run_id' => $run->id, | ||
'endpoint' => $_POST['endpoint'], | ||
'auth' => $_POST['auth'], | ||
'p256dh ' => $_POST['p256dh'], | ||
'session' => Site::getCurrentUser()->user_code | ||
)); | ||
|
||
} catch (Exception $e) { | ||
error_log($e->getMessage()); | ||
|
||
} | ||
|
||
} | ||
|
||
public function indexAction() { | ||
error_log('indexAction of PwaController'); | ||
} | ||
|
||
|
||
} |
This file contains 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 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 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 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,11 @@ | ||
CREATE TABLE `survey_push_subscriptions` ( | ||
`run_id` int(11) NOT NULL, | ||
`endpoint` varchar(500) NOT NULL, | ||
`auth` varchar(45) NOT NULL, | ||
`p256dh` mediumtext, | ||
`session` char(64) NOT NULL, | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `unique_index` (`run_id`,`endpoint`,`session`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8; | ||
|
This file contains 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 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,52 @@ | ||
{ | ||
"name": "Formr", | ||
"theme_color": "#99cc53", | ||
"background_color": "#000000", | ||
"display": "browser", | ||
"Scope": "PsyTD/formr-entwicklung", | ||
"start_url": "https://www.uni-muenster.de/PsyTD/formr-entwicklung", | ||
"icons": [ | ||
{ | ||
"src": "assets/site/img/icons/icon-72x72.png", | ||
"sizes": "72x72", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "assets/site/img/icons/icon-96x96.png", | ||
"sizes": "96x96", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "assets/site/img/icons/icon-128x128.png", | ||
"sizes": "128x128", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "assets/site/img/icons/icon-144x144.png", | ||
"sizes": "144x144", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "assets/site/img/icons/icon-152x152.png", | ||
"sizes": "152x152", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "assets/site/img/icons/icon-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "assets/site/img/icons/icon-384x384.png", | ||
"sizes": "384x384", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "assets/site/img/icons/icon-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
], | ||
"splash_pages": null, | ||
"gcm_sender_id": "103953800507" | ||
} |
This file contains 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,70 @@ | ||
const SW_VERSION = 'formr-v0.0.15' | ||
|
||
notification_options = { | ||
"body": "This is a formr notification.", | ||
"icon": "assets/site/img/logo.png", | ||
"image": "assets/site/img/logo.png", | ||
"vibrate": [5,0,5,0,5], | ||
"requireInteraction": true, | ||
tag: 'renotify', | ||
renotify: true, | ||
// actions: [ | ||
// {action: 'open', title: 'Go to survey'} | ||
// ] | ||
} | ||
|
||
function dispatchNotification() { | ||
console.log('dispatchingNotification'); | ||
self.registration.showNotification('Please continue your Survey', notification_options); | ||
|
||
} | ||
|
||
|
||
|
||
self.addEventListener('install', function(event) { | ||
console.log(`Formr-Service-Worker Version ${SW_VERSION} installed`); | ||
}); | ||
|
||
self.addEventListener('activate', function(event) { | ||
console.log(`Formr-Service-Worker Version ${SW_VERSION} activated`); | ||
}); | ||
|
||
|
||
self.addEventListener('push', function(event) { | ||
console.log('Got a push event'); | ||
if (!(self.Notification && self.Notification.permission === 'granted')) { | ||
return; | ||
} | ||
dispatchNotification(); | ||
}); | ||
|
||
self.addEventListener('notificationclick', function(event) { | ||
var notification = event.notification; | ||
var action = event.action; | ||
|
||
console.log(notification); | ||
|
||
if (action === 'confirm') { | ||
console.log('Confirm was chosen'); | ||
notification.close(); | ||
} else { | ||
console.log(action); | ||
event.waitUntil( | ||
clients.matchAll() | ||
.then(function(clis) { | ||
var client = clis.find(function(c) { | ||
return c.visibilitystate === 'visible'; | ||
}); | ||
|
||
if (client !== undefined) { | ||
client.navigate('https://www.uni-muenster.de/PsyTD/formr-entwicklung/NeuesQueuingSystemTest'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The link to the run needs to be inserted here. Should be part of the push notification. |
||
client.focus(); | ||
} else { | ||
clients.openWindow('https://www.uni-muenster.de/PsyTD/formr-entwicklung/NeuesQueuingSystemTest'); | ||
} | ||
notification.close(); | ||
}) | ||
); | ||
} | ||
|
||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check if we can insert this dynamically.