0.12.47 fix push messages

This commit is contained in:
SDE
2024-05-05 13:37:39 +03:00
parent 474bb9f02e
commit f8caafb2a9
3 changed files with 26 additions and 6 deletions

View File

@@ -69,7 +69,7 @@ def get_inter_http_respose(template_obj, context_Dict, request):
title = getattr(context_Dict['page'], 'title', None) title = getattr(context_Dict['page'], 'title', None)
text = getattr(context_Dict['page'], 'description', None) text = getattr(context_Dict['page'], 'description', None)
# if text and title and not request.user.is_anonymous: if text and title and not request.user.is_anonymous:
# send_push(user=request.user, title=title, text=text) send_push(user=request.user, title=title, text=text)
return HttpResponse(template_obj.render(context_Dict, request)) return HttpResponse(template_obj.render(context_Dict, request))

View File

@@ -33,9 +33,9 @@ ALLOWED_HOSTS = ["*"]
WEBPUSH_SETTINGS = { WEBPUSH_SETTINGS = {
# "VAPID_PUBLIC_KEY": "BKS8byh3MucwCF2h06JY9oey1s1RYII09j-j3ehI3qTYhs965UHv0qNPl-jFjQBbIJCvjVXm9RW6t_oJJK8yMOk", # "VAPID_PUBLIC_KEY": "BKS8byh3MucwCF2h06JY9oey1s1RYII09j-j3ehI3qTYhs965UHv0qNPl-jFjQBbIJCvjVXm9RW6t_oJJK8yMOk",
# "VAPID_PRIVATE_KEY": "f5NMgOntBtRqsyeKwEzloK-051ggMnZGF_GFimERY0w", # "VAPID_PRIVATE_KEY": "f5NMgOntBtRqsyeKwEzloK-051ggMnZGF_GFimERY0w",
"VAPID_PUBLIC_KEY": "BNf5y-99x5UNoaK98VAPKzZOevJHnak-LUmiQFu_r0i8tO3z7TPsto0DKHzNUO76ejNVWjmpL3UoavIsa3C3NEs", "VAPID_PUBLIC_KEY": "BBxRDxjgX-2DbZa3OLtxMuejTxaliMLd6QK6mG15a5oathxDtNcyioMMPMNTbljG-Hvc3eVQniJ_Ue6e1DN7VXM",
"VAPID_PRIVATE_KEY": "4m8Z-bmT7ofb4bxM488eqFUksqnBUGzZh2rBrfSvPGo", "VAPID_PRIVATE_KEY": "YruXqS1ZmxJB2heQU7orDojN-ZQHBSTxkBJ0gVrF0JU",
"VAPID_ADMIN_EMAIL": "admin@tripwb.com" "VAPID_ADMIN_EMAIL": "tripwithbonus@gmail.com"
} }

View File

@@ -30,6 +30,26 @@ const showNotAllowed = (message) => {
button.setAttribute('disabled', 'true'); button.setAttribute('disabled', 'true');
}; };
// urlB64ToUint8Array is a magic function that will encode the base64 public key
// to Array buffer which is needed by the subscription option
function urlB64ToUint8Array2(base64String) {
const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/')
const rawData = atob(base64)
const outputArray = new Uint8Array(rawData.length)
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i)
}
return outputArray
}
function urlB64ToUint8Array(base64String) { function urlB64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4); const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding) const base64 = (base64String + padding)
@@ -55,7 +75,7 @@ const subscribe = async (reg) => {
const options = { const options = {
userVisibleOnly: true, userVisibleOnly: true,
// if key exists, create applicationServerKey property // if key exists, create applicationServerKey property
...(key && {applicationServerKey: urlB64ToUint8Array(key)}) ...(key && {applicationServerKey: urlB64ToUint8Array2(key)})
}; };
const sub = await reg.pushManager.subscribe(options); const sub = await reg.pushManager.subscribe(options);