diff options
Diffstat (limited to 'src/main/assets')
-rw-r--r-- | src/main/assets/scripts.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js index 3c83bba4..50406f1c 100644 --- a/src/main/assets/scripts.js +++ b/src/main/assets/scripts.js @@ -533,6 +533,20 @@ function fetchUserUri(dataUri) { }) } +function markRead() { + return new Promise((resolve) => { + fetch('/api/messages/mark_read', { + method: 'POST' + }).then(handleErrors) + .then(() => { + resolve(true) + }) + .catch(() => { + resolve(false) + }) + }) +} + const registerServiceWorker = () => { const publicKey = 'BPU0LniKKR0QiaUvILPd9AystmSOU8rWDZobxKm7IJN5HYxOSQdktRdc74TZvyRS9_kyUz7LDN6gUAmAVOmObAU' navigator.serviceWorker.register('/sw.js', { scope: '/' }) @@ -825,4 +839,14 @@ ready(() => { }) notificationsCheckPermissions(button) } + const markReadButton = document.getElementById('messages_mark_read') + if (markReadButton) { + markReadButton.addEventListener('click', () => { + if (markRead()) { + window.location.reload() + } else { + alert('Something went wrong :(') + } + }) + } }) |