Refactor _downloadNotification function

This commit is contained in:
schlagmichdoch 2024-02-05 20:39:56 +01:00
parent 417d5421a6
commit 3dd40e238a

View file

@ -2591,7 +2591,7 @@ class Notifications {
Events.on('text-received', e => this._messageNotification(e.detail.text, e.detail.peerId)); 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-received', e => this._downloadNotification(e.detail.files, e.detail.imagesOnly));
Events.on('files-transfer-request', e => this._requestNotification(e.detail.request, e.detail.peerId)); Events.on('files-transfer-request', e => this._requestNotification(e.detail.request, e.detail.peerId));
} }
@ -2647,16 +2647,16 @@ class Notifications {
} }
} }
_downloadNotification(files) { _downloadNotification(files, imagesOnly) {
if (document.visibilityState !== 'visible') { if (document.visibilityState === 'visible') return;
let imagesOnly = files.every(file => file.type.split('/')[0] === 'image');
let title; let title, fileOther;
const fileName = files[0].name;
if (files.length === 1) { if (files.length === 1) {
title = `${files[0].name}`; title = `${fileName}`;
} }
else { else {
let fileOther;
if (files.length === 2) { if (files.length === 2) {
fileOther = imagesOnly fileOther = imagesOnly
? Localization.getTranslation("dialogs.file-other-description-image") ? Localization.getTranslation("dialogs.file-other-description-image")
@ -2667,12 +2667,11 @@ class Notifications {
? Localization.getTranslation("dialogs.file-other-description-image-plural", null, {count: files.length - 1}) ? Localization.getTranslation("dialogs.file-other-description-image-plural", null, {count: files.length - 1})
: Localization.getTranslation("dialogs.file-other-description-file-plural", null, {count: files.length - 1}); : Localization.getTranslation("dialogs.file-other-description-file-plural", null, {count: files.length - 1});
} }
title = `${files[0].name} ${fileOther}` title = `${fileName} ${fileOther}`
} }
const notification = this._notify(title, Localization.getTranslation("notifications.click-to-download")); const notification = this._notify(title, Localization.getTranslation("notifications.click-to-download"));
this._bind(notification, _ => this._download(notification)); this._bind(notification, _ => this._download(notification));
} }
}
_requestNotification(request, peerId) { _requestNotification(request, peerId) {
if (document.visibilityState !== 'visible') { if (document.visibilityState !== 'visible') {