mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17010] Clean up push worker
PHPBB3-17010
This commit is contained in:
parent
adf639e871
commit
4e9fb6ed4f
1 changed files with 19 additions and 25 deletions
|
@ -6,46 +6,40 @@ self.addEventListener('push', event => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let itemId = 0,
|
let itemId = 0;
|
||||||
typeId = 0;
|
let typeId = 0;
|
||||||
try {
|
try {
|
||||||
const notificationData = event.data.json();
|
const notificationData = event.data.json();
|
||||||
itemId = notificationData['item_id'];
|
itemId = notificationData.item_id;
|
||||||
typeId = notificationData['type_id'];
|
typeId = notificationData.type_id;
|
||||||
} catch (e) {
|
} catch {
|
||||||
self.registration.showNotification(event.data.text());
|
self.registration.showNotification(event.data.text());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
|
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
|
||||||
|
|
||||||
let formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('item_id', itemId.toString(10));
|
formData.append('item_id', itemId.toString(10));
|
||||||
formData.append('type_id', typeId.toString(10));
|
formData.append('type_id', typeId.toString(10));
|
||||||
|
|
||||||
fetch(getNotificationUrl, {
|
fetch(getNotificationUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Requested-With': 'XMLHttpRequest'
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
},
|
},
|
||||||
body: formData
|
body: formData,
|
||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then(response => response.json())
|
||||||
.then((response) => {
|
.then(response => {
|
||||||
const responseBody = response.title + "\n" + response.text;
|
const responseBody = response.title + '\n' + response.text;
|
||||||
const options = {
|
const options = {
|
||||||
body: responseBody,
|
body: responseBody,
|
||||||
data: response,
|
data: response,
|
||||||
icon: response.avatar.src
|
icon: response.avatar.src,
|
||||||
// foo: ''
|
};
|
||||||
//icon: image
|
self.registration.showNotification(response.heading, options);
|
||||||
}
|
});
|
||||||
self.registration.showNotification(
|
|
||||||
response.heading,
|
|
||||||
options
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue