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,31 +2647,30 @@ 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;
if (files.length === 1) { let title, fileOther;
title = `${files[0].name}`; const fileName = files[0].name;
if (files.length === 1) {
title = `${fileName}`;
}
else {
if (files.length === 2) {
fileOther = imagesOnly
? Localization.getTranslation("dialogs.file-other-description-image")
: Localization.getTranslation("dialogs.file-other-description-file");
} }
else { else {
let fileOther; fileOther = imagesOnly
if (files.length === 2) { ? Localization.getTranslation("dialogs.file-other-description-image-plural", null, {count: files.length - 1})
fileOther = imagesOnly : Localization.getTranslation("dialogs.file-other-description-file-plural", null, {count: files.length - 1});
? Localization.getTranslation("dialogs.file-other-description-image")
: Localization.getTranslation("dialogs.file-other-description-file");
}
else {
fileOther = imagesOnly
? 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});
}
title = `${files[0].name} ${fileOther}`
} }
const notification = this._notify(title, Localization.getTranslation("notifications.click-to-download")); title = `${fileName} ${fileOther}`
this._bind(notification, _ => this._download(notification));
} }
const notification = this._notify(title, Localization.getTranslation("notifications.click-to-download"));
this._bind(notification, _ => this._download(notification));
} }
_requestNotification(request, peerId) { _requestNotification(request, peerId) {