1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Split out file transfer button handling.

Split out deleting of buttons during file transfer into its own
function.
This commit is contained in:
Juliusz Chroboczek 2023-01-16 14:39:20 +01:00
parent f75b964a6b
commit 645ba5fb48

View file

@ -2441,15 +2441,20 @@ function gotFileTransfer(f) {
/**
* @param {TransferredFile} f
* @param {string} status
* @param {boolean} [delyes]
* @param {boolean} [delno]
*/
function setFileStatus(f, status, delyes, delno) {
function setFileStatus(f, status) {
let statusdiv = document.getElementById('status-' + f.fullid());
if(!statusdiv)
throw new Error("Couldn't find statusdiv");
statusdiv.textContent = status;
if(delyes || delno) {
}
/**
* @param {TransferredFile} f
* @param {boolean} delyes
* @param {boolean} delno
*/
function delFileStatusButtons(f, delyes, delno) {
let div = document.getElementById('file-' + f.fullid());
if(!div)
throw new Error("Couldn't find file div");
@ -2463,7 +2468,6 @@ function setFileStatus(f, status, delyes, delno) {
if(bno)
div.removeChild(bno);
}
}
}
/**
@ -2477,7 +2481,8 @@ function gotFileTransferEvent(state, data) {
case 'inviting':
break;
case 'connecting':
setFileStatus(f, 'Connecting...', true);
delFileStatusButtons(f, true);
setFileStatus(f, 'Connecting...');
break;
case 'connected':
if(f.up)
@ -2486,7 +2491,8 @@ function gotFileTransferEvent(state, data) {
setFileStatus(f, `Receiving... ${f.datalen}/${f.size}`);
break;
case 'done':
setFileStatus(f, 'Done.', true, true);
delFileStatusButtons(f, true, true);
setFileStatus(f, 'Done.');
if(!f.up) {
let url = URL.createObjectURL(data);
let a = document.createElement('a');
@ -2499,10 +2505,11 @@ function gotFileTransferEvent(state, data) {
}
break;
case 'cancelled':
delFileStatusButtons(f, true, true);
if(data)
setFileStatus(f, `Cancelled: ${data.toString()}.`, true, true);
setFileStatus(f, `Cancelled: ${data.toString()}.`);
else
setFileStatus(f, 'Cancelled.', true, true);
setFileStatus(f, 'Cancelled.');
break;
case 'closed':
break;