From c9dca7e0831df97ecf15f68fa170b7c8c620a551 Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Mon, 6 Mar 2023 15:05:13 +0100 Subject: [PATCH] fix download notification and add request notification --- public/scripts/ui.js | 25 +++++++++++++++++++++-- public_included_ws_fallback/scripts/ui.js | 25 +++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 580b73c..02dceab 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -1417,9 +1417,9 @@ class Notifications { this.$button.removeAttribute('hidden'); this.$button.addEventListener('click', _ => this._requestPermission()); } - // Todo: fix Notifications Events.on('text-received', e => this._messageNotification(e.detail.text, e.detail.peerId)); Events.on('files-received', e => this._downloadNotification(e.detail.files)); + Events.on('files-transfer-request', e => this._requestNotification(e.detail.request, e.detail.peerId)); } _requestPermission() { @@ -1492,8 +1492,29 @@ class Notifications { } } + _requestNotification(request, peerId) { + if (document.visibilityState !== 'visible') { + let imagesOnly = true; + for(let i=0; i 1) { + descriptor = imagesOnly ? ' images' : ' files'; + } else { + descriptor = imagesOnly ? ' image' : ' file'; + } + let displayName = $(peerId).querySelector('.name').textContent + let title = `${displayName} would like to transfer ${request.header.length} ${descriptor}`; + const notification = this._notify(title, 'Click to show'); + } + } + _download(notification) { - $('share-or-download').click(); + $('download-btn').click(); notification.close(); } diff --git a/public_included_ws_fallback/scripts/ui.js b/public_included_ws_fallback/scripts/ui.js index e45143e..8968521 100644 --- a/public_included_ws_fallback/scripts/ui.js +++ b/public_included_ws_fallback/scripts/ui.js @@ -1416,9 +1416,9 @@ class Notifications { this.$button.removeAttribute('hidden'); this.$button.addEventListener('click', _ => this._requestPermission()); } - // Todo: fix Notifications Events.on('text-received', e => this._messageNotification(e.detail.text, e.detail.peerId)); Events.on('files-received', e => this._downloadNotification(e.detail.files)); + Events.on('files-transfer-request', e => this._requestNotification(e.detail.request, e.detail.peerId)); } _requestPermission() { @@ -1491,8 +1491,29 @@ class Notifications { } } + _requestNotification(request, peerId) { + if (document.visibilityState !== 'visible') { + let imagesOnly = true; + for(let i=0; i 1) { + descriptor = imagesOnly ? ' images' : ' files'; + } else { + descriptor = imagesOnly ? ' image' : ' file'; + } + let displayName = $(peerId).querySelector('.name').textContent + let title = `${displayName} would like to transfer ${request.header.length} ${descriptor}`; + const notification = this._notify(title, 'Click to show'); + } + } + _download(notification) { - $('share-or-download').click(); + $('download-btn').click(); notification.close(); }