diff --git a/SubscribesApp/funcs.py b/SubscribesApp/funcs.py index aa542c8..f8614a8 100644 --- a/SubscribesApp/funcs.py +++ b/SubscribesApp/funcs.py @@ -59,12 +59,13 @@ def get_profile_subscribe_page_content_html(request): subscribe_for_user = None + orders = None if request.user and request.user.is_authenticated: from BillingApp.funcs import get_orders_for_user, get_order_status orders = get_orders_for_user(request.user) - for order in orders: - res = get_order_status(order) - subscribe_for_user = check_n_enable_subscribe_by_order(order) + # for order in orders: + # res = get_order_status(order) + # subscribe_for_user = check_n_enable_subscribe_by_order(order) if not subscribe_for_user: subscribe_for_user = SubscribeForUser.objects.filter(user=request.user) @@ -84,7 +85,8 @@ def get_profile_subscribe_page_content_html(request): Dict = { 'subscribe_for_user': subscribe_for_user, - 'subscribes': subscribes + 'subscribes': subscribes, + 'active_orders': orders, } html = render_to_string(tpl_name, Dict, request=request) diff --git a/static/js/push/registerSw.js b/static/js/push/registerSw.js index 695e02c..e3f6a78 100644 --- a/static/js/push/registerSw.js +++ b/static/js/push/registerSw.js @@ -34,34 +34,42 @@ const showNotAllowed = (message) => { // 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 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 urlBase64ToUint8Array(base64String) { + const padding = '='.repeat((4 - base64String.length % 4) % 4); + const base64 = (base64String + padding) + .replace(/\-/g, '+') + .replace(/_/g, '/') + ; + const rawData = window.atob(base64); + return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0))); } - - - - -function urlB64ToUint8Array(base64String) { - const padding = '='.repeat((4 - base64String.length % 4) % 4); - const base64 = (base64String + padding) - .replace(/\-/g, '+') - .replace(/_/g, '/'); - - const rawData = window.atob(base64); - const outputArray = new Uint8Array(rawData.length); - const outputData = outputArray.map((output, index) => rawData.charCodeAt(index)); - - return outputData; -} +// function urlB64ToUint8Array(base64String) { +// const padding = '='.repeat((4 - base64String.length % 4) % 4); +// const base64 = (base64String + padding) +// .replace(/\-/g, '+') +// .replace(/_/g, '/'); +// +// const rawData = window.atob(base64); +// const outputArray = new Uint8Array(rawData.length); +// const outputData = outputArray.map((output, index) => rawData.charCodeAt(index)); +// +// return outputData; +// } const subscribe = async (reg) => { const subscription = await reg.pushManager.getSubscription(); @@ -75,7 +83,7 @@ const subscribe = async (reg) => { const options = { userVisibleOnly: true, // if key exists, create applicationServerKey property - ...(key && {applicationServerKey: urlB64ToUint8Array2(key)}) + ...(key && {applicationServerKey: urlBase64ToUint8Array(key)}) }; const sub = await reg.pushManager.subscribe(options);