diff --git a/README.md b/README.md index f310aab..b7b3008 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -PANDORA +PANDORA Pandora is an open-source web client for the WAHA API. @@ -13,7 +13,7 @@ Pandora is an open-source web client for the WAHA API. - [ ] Sending audio messages - [x] Sending attachments (sends image/video as such)4 - [x] Notification sound5 -- [ ] Browser notification +- [x] Browser notification - [x] Download attachments - [x] Automatically download images6 - [X] Local message storing diff --git a/js/app.js b/js/app.js index be7e60e..13207f3 100644 --- a/js/app.js +++ b/js/app.js @@ -11,8 +11,10 @@ let activeChatState = null; const messageTone = new Audio("./message.ogg"); const longPressEvent = new CustomEvent("longpress"); export let isLoadingChat = false; +export let notificationAuthorization = false; document.addEventListener('DOMContentLoaded', async () => { + askForNotificationPermission(); elements.inputApiKey.value = config.apiKey; elements.inputWahaUrl.value = config.wahaUrl; elements.inputSession.value = config.session; @@ -32,6 +34,10 @@ document.addEventListener('DOMContentLoaded', async () => { } }); +async function askForNotificationPermission() { + notificationAuthorization = await Notification.requestPermission(); +} + async function setupElementsData() { const usr = await getAppUser(); const usrPic = (await getChatPicture(usr.id))?.url; @@ -254,6 +260,9 @@ async function handleIncomingMessage(msg) { if (!msg.fromMe) { messageTone.play(); } + if (notificationAuthorization) { + new Notification("New message", { body: msg.body }); + } if (activeChatState && activeChatState.id === msgChatId) { const msgId = normalizeId(msg.id) || msg.id;