{if isset($backdrops) && !is_null($backdrops)}
{/if}
{if $instance_name != \OPENVK_DEFAULT_INSTANCE_NAME}{$instance_name}{/if}
{ifset $thisUser} {if $thisUser->isDeactivated()} {else} {/if} {else} {/ifset}
{include header}
{ifset wrap}
{$flashMessage->title}
{$flashMessage->msg|noescape}
{include wrap} {else}
{$flashMessage->title}
{$flashMessage->msg|noescape}
{include content}
{/ifset}
{include "components/cookies.latte"} {script "js/node_modules/msgpack-lite/dist/msgpack.min.js"} {script "js/node_modules/soundjs/lib/soundjs.min.js"} {script "js/node_modules/ky/umd.js"} {script "js/messagebox.js"} {script "js/notifications.js"} {script "js/scroll.js"} {script "js/player.js"} {script "js/al_wall.js"} {script "js/al_docs.js"} {script "js/al_api.js"} {script "js/al_mentions.js"} {script "js/al_polls.js"} {script "js/al_suggestions.js"} {script "js/al_navigation.js"} {script "js/al_comments.js"} {script "js/al_music.js"} {script "js/al_despacito_wall.js"} {script "js/al_photos.js"} {script "js/options.js"} {ifset $thisUser} {script "js/al_notifs.js"} {script "js/al_feed.js"} {/ifset} {script "js/node_modules/leaflet/dist/leaflet.js"} {script "js/node_modules/leaflet-control-geocoder/dist/Control.Geocoder.js"} {css "js/node_modules/leaflet/dist/leaflet.css"} {css "js/node_modules/leaflet-control-geocoder/dist/Control.Geocoder.css"} {ifset bodyScripts} {include bodyScripts} {/ifset} {script "js/router.js"} {/if} {if isset($parentModule) && substr($parentModule, 0, 21) !== 'libchandler:absolute.'} {include content} {/if} {css "js/node_modules/leaflet-control-geocoder/dist/Control.Geocoder.css"} {ifset bodyScripts} {include bodyScripts} {/ifset} {script "js/router.js"} {/if} {if isset($parentModule) && substr($parentModule, 0, 21) !== 'libchandler:absolute.'} {include content} {/if} createjs.Sound.registerSound("/assets/packages/static/openvk/audio/notify.mp3", "notification"); function __actualPlayNotifSound() { createjs.Sound.play("notification"); } window.playNotifSound = Function.noop; function incrementNotificationsCounter() { const parentLink = document.getElementById('notificationLink'); if (!parentLink) return; document.querySelectorAll('a[href="/notifications"]').forEach(link => { let counterObject = parentLink.querySelector('object'); if (!counterObject) { counterObject = document.createElement('object'); counterObject.type = 'internal/link'; counterObject.innerHTML = ' (1)'; parentLink.appendChild(counterObject); } else { const bTag = counterObject.querySelector('b'); if (bTag) { let currentCount = parseInt(bTag.textContent) || 0; bTag.textContent = currentCount + 1; } else { let counterObject = link.querySelector('object'); if (!counterObject) { counterObject = document.createElement('object'); counterObject.type = 'internal/link'; counterObject.innerHTML = ' (1)'; link.appendChild(counterObject); } else { const bTag = counterObject.querySelector('b'); if (bTag) { let currentCount = parseInt(bTag.textContent) || 0; bTag.textContent = currentCount + 1; } else { counterObject.innerHTML = ' (1)'; } } } }); } async function setupNotificationListener() { console.warn("Setting up notifications listener..."); const POLL_INTERVAL = 10000; const CHECK_MORE_INTERVAL = 250; const ERROR_RETRY_INTERVAL = 60000; let isFirstRequest = true; while(true) { try { const notif = await API.Notifications.fetch(); if (notif) { if (!isFirstRequest) { playNotifSound(); console.info("New notification", notif); NewNotification(notif.title, notif.body, notif.ava, Function.noop, (notif.priority || 1) * 6000); incrementNotificationsCounter(); } else { console.info("First request: skipping alert (syncing cursor)"); } } await new Promise(resolve => setTimeout(resolve, CHECK_MORE_INTERVAL)); } catch(rejection) { const isEmpty = rejection.message === "Nothing to report" || rejection.code === 1983; if (isEmpty) { if (isFirstRequest) { console.info("Cursor synced. Real-time notifications enabled."); isFirstRequest = false; } else { console.info("No new notifications found, sleeping for " + POLL_INTERVAL/1000 + "s...") } await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL)); } else { console.error("Poll error, sleeping...", rejection); await new Promise(resolve => setTimeout(resolve, ERROR_RETRY_INTERVAL)); } } } }; (async function() { await setupNotificationListener(); })(); u(document.body).on("click", () => window.playNotifSound = window.__actualPlayNotifSound);