1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45: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 {TransferredFile} f
* @param {string} status * @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()); let statusdiv = document.getElementById('status-' + f.fullid());
if(!statusdiv) if(!statusdiv)
throw new Error("Couldn't find statusdiv"); throw new Error("Couldn't find statusdiv");
statusdiv.textContent = status; 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()); let div = document.getElementById('file-' + f.fullid());
if(!div) if(!div)
throw new Error("Couldn't find file div"); throw new Error("Couldn't find file div");
@ -2464,7 +2469,6 @@ function setFileStatus(f, status, delyes, delno) {
div.removeChild(bno); div.removeChild(bno);
} }
} }
}
/** /**
* @this {TransferredFile} * @this {TransferredFile}
@ -2477,7 +2481,8 @@ function gotFileTransferEvent(state, data) {
case 'inviting': case 'inviting':
break; break;
case 'connecting': case 'connecting':
setFileStatus(f, 'Connecting...', true); delFileStatusButtons(f, true);
setFileStatus(f, 'Connecting...');
break; break;
case 'connected': case 'connected':
if(f.up) if(f.up)
@ -2486,7 +2491,8 @@ function gotFileTransferEvent(state, data) {
setFileStatus(f, `Receiving... ${f.datalen}/${f.size}`); setFileStatus(f, `Receiving... ${f.datalen}/${f.size}`);
break; break;
case 'done': case 'done':
setFileStatus(f, 'Done.', true, true); delFileStatusButtons(f, true, true);
setFileStatus(f, 'Done.');
if(!f.up) { if(!f.up) {
let url = URL.createObjectURL(data); let url = URL.createObjectURL(data);
let a = document.createElement('a'); let a = document.createElement('a');
@ -2499,10 +2505,11 @@ function gotFileTransferEvent(state, data) {
} }
break; break;
case 'cancelled': case 'cancelled':
delFileStatusButtons(f, true, true);
if(data) if(data)
setFileStatus(f, `Cancelled: ${data.toString()}.`, true, true); setFileStatus(f, `Cancelled: ${data.toString()}.`);
else else
setFileStatus(f, 'Cancelled.', true, true); setFileStatus(f, 'Cancelled.');
break; break;
case 'closed': case 'closed':
break; break;