|
|
@ -385,8 +385,6 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
}): HTMLElement { |
|
|
|
}): HTMLElement { |
|
|
|
if(!fontWeight) fontWeight = 500; |
|
|
|
if(!fontWeight) fontWeight = 500; |
|
|
|
|
|
|
|
|
|
|
|
const uploading = message.pFlags.is_outgoing; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const doc = (message.media.document || message.media.webpage.document) as MyDocument; |
|
|
|
const doc = (message.media.document || message.media.webpage.document) as MyDocument; |
|
|
|
if(doc.type === 'audio' || doc.type === 'voice') { |
|
|
|
if(doc.type === 'audio' || doc.type === 'voice') { |
|
|
|
const audioElement = new AudioElement(); |
|
|
|
const audioElement = new AudioElement(); |
|
|
@ -409,23 +407,28 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
return audioElement; |
|
|
|
return audioElement; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uploading = message.pFlags.is_outgoing && message.media?.preloader; |
|
|
|
|
|
|
|
|
|
|
|
let extSplitted = doc.file_name ? doc.file_name.split('.') : ''; |
|
|
|
let extSplitted = doc.file_name ? doc.file_name.split('.') : ''; |
|
|
|
let ext = ''; |
|
|
|
let ext = ''; |
|
|
|
ext = extSplitted.length > 1 && Array.isArray(extSplitted) ? extSplitted.pop().toLowerCase() : 'file'; |
|
|
|
ext = extSplitted.length > 1 && Array.isArray(extSplitted) ? extSplitted.pop().toLowerCase() : 'file'; |
|
|
|
|
|
|
|
|
|
|
|
let docDiv = document.createElement('div'); |
|
|
|
let docDiv = document.createElement('div'); |
|
|
|
docDiv.classList.add('document', `ext-${ext}`); |
|
|
|
docDiv.classList.add('document', `ext-${ext}`); |
|
|
|
|
|
|
|
docDiv.dataset.docId = doc.id; |
|
|
|
|
|
|
|
|
|
|
|
const icoDiv = document.createElement('div'); |
|
|
|
const icoDiv = document.createElement('div'); |
|
|
|
icoDiv.classList.add('document-ico'); |
|
|
|
icoDiv.classList.add('document-ico'); |
|
|
|
|
|
|
|
|
|
|
|
if(doc.thumbs?.length || (uploading && doc.url && doc.type === 'photo')) { |
|
|
|
if(doc.thumbs?.length || (message.pFlags.is_outgoing && doc.url && doc.type === 'photo')) { |
|
|
|
docDiv.classList.add('document-with-thumb'); |
|
|
|
docDiv.classList.add('document-with-thumb'); |
|
|
|
|
|
|
|
|
|
|
|
if(uploading) { |
|
|
|
let imgs: HTMLImageElement[] = []; |
|
|
|
|
|
|
|
if(message.pFlags.is_outgoing) { |
|
|
|
icoDiv.innerHTML = `<img src="${doc.url}">`; |
|
|
|
icoDiv.innerHTML = `<img src="${doc.url}">`; |
|
|
|
|
|
|
|
imgs.push(icoDiv.firstElementChild as HTMLImageElement); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
wrapPhoto({ |
|
|
|
const wrapped = wrapPhoto({ |
|
|
|
photo: doc, |
|
|
|
photo: doc, |
|
|
|
message: null, |
|
|
|
message: null, |
|
|
|
container: icoDiv, |
|
|
|
container: icoDiv, |
|
|
@ -435,10 +438,11 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
withoutPreloader: true |
|
|
|
withoutPreloader: true |
|
|
|
}); |
|
|
|
}); |
|
|
|
icoDiv.style.width = icoDiv.style.height = ''; |
|
|
|
icoDiv.style.width = icoDiv.style.height = ''; |
|
|
|
|
|
|
|
if(wrapped.images.thumb) imgs.push(wrapped.images.thumb); |
|
|
|
|
|
|
|
if(wrapped.images.full) imgs.push(wrapped.images.full); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const img = icoDiv.querySelector('img'); |
|
|
|
imgs.forEach(img => img.classList.add('document-thumb')); |
|
|
|
if(img) img.classList.add('document-thumb'); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
icoDiv.innerText = ext; |
|
|
|
icoDiv.innerText = ext; |
|
|
|
} |
|
|
|
} |
|
|
@ -461,49 +465,70 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
docDiv.innerHTML = ` |
|
|
|
docDiv.innerHTML = ` |
|
|
|
${!uploading ? `<div class="document-download"></div>` : ''} |
|
|
|
${doc.downloaded && !uploading ? '' : `<div class="document-download"></div>`} |
|
|
|
<div class="document-name"><middle-ellipsis-element data-font-weight="${fontWeight}">${fileName}</middle-ellipsis-element>${titleAdditionHTML}</div> |
|
|
|
<div class="document-name"><middle-ellipsis-element data-font-weight="${fontWeight}">${fileName}</middle-ellipsis-element>${titleAdditionHTML}</div> |
|
|
|
<div class="document-size">${size}</div> |
|
|
|
<div class="document-size">${size}</div> |
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
docDiv.prepend(icoDiv); |
|
|
|
docDiv.prepend(icoDiv); |
|
|
|
|
|
|
|
|
|
|
|
if(!uploading) { |
|
|
|
if(!uploading && message.pFlags.is_outgoing) { |
|
|
|
const downloadDiv = docDiv.querySelector('.document-download') as HTMLDivElement; |
|
|
|
return docDiv; |
|
|
|
const preloader = new ProgressivePreloader(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const load = () => { |
|
|
|
let downloadDiv: HTMLElement, preloader: ProgressivePreloader = null; |
|
|
|
const download = appDocsManager.saveDocFile(doc, appImManager.chat.bubbles ? appImManager.chat.bubbles.lazyLoadQueue.queueId : 0); |
|
|
|
const onLoad = () => { |
|
|
|
|
|
|
|
if(downloadDiv) { |
|
|
|
|
|
|
|
downloadDiv.classList.add('downloaded'); |
|
|
|
|
|
|
|
const _downloadDiv = downloadDiv; |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
_downloadDiv.remove(); |
|
|
|
|
|
|
|
}, 200); |
|
|
|
|
|
|
|
downloadDiv = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
download.then(() => { |
|
|
|
if(preloader) { |
|
|
|
downloadDiv.classList.add('downloaded'); |
|
|
|
preloader = null; |
|
|
|
setTimeout(() => { |
|
|
|
} |
|
|
|
downloadDiv.remove(); |
|
|
|
}; |
|
|
|
}, 200); |
|
|
|
|
|
|
|
}); |
|
|
|
const load = () => { |
|
|
|
|
|
|
|
const doc = appDocsManager.getDoc(docDiv.dataset.docId); |
|
|
|
|
|
|
|
const download = appDocsManager.saveDocFile(doc, appImManager.chat.bubbles ? appImManager.chat.bubbles.lazyLoadQueue.queueId : 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(downloadDiv) { |
|
|
|
|
|
|
|
download.then(onLoad); |
|
|
|
preloader.attach(downloadDiv, true, download); |
|
|
|
preloader.attach(downloadDiv, true, download); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return {download}; |
|
|
|
return {download}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
preloader.construct(); |
|
|
|
if(!(doc.downloaded && !uploading)) { |
|
|
|
preloader.setManual(); |
|
|
|
downloadDiv = docDiv.querySelector('.document-download'); |
|
|
|
preloader.attach(downloadDiv); |
|
|
|
preloader = message.media.preloader as ProgressivePreloader; |
|
|
|
preloader.setDownloadFunction(load); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachClickEvent(docDiv, (e) => { |
|
|
|
if(!preloader) { |
|
|
|
preloader.onClick(e); |
|
|
|
preloader = new ProgressivePreloader(); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if(doc.downloaded) { |
|
|
|
preloader.construct(); |
|
|
|
downloadDiv.classList.add('downloaded'); |
|
|
|
preloader.setManual(); |
|
|
|
} */ |
|
|
|
preloader.attach(downloadDiv); |
|
|
|
} else if(message.media?.preloader) { |
|
|
|
preloader.setDownloadFunction(load); |
|
|
|
const icoDiv = docDiv.querySelector('.document-ico'); |
|
|
|
} else { |
|
|
|
message.media.preloader.attach(icoDiv, false); |
|
|
|
preloader.attach(downloadDiv); |
|
|
|
|
|
|
|
message.media.promise.then(onLoad); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachClickEvent(docDiv, (e) => { |
|
|
|
|
|
|
|
if(preloader) { |
|
|
|
|
|
|
|
preloader.onClick(e); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
load(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return docDiv; |
|
|
|
return docDiv; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|