|
|
@ -5,6 +5,8 @@ import CryptoWorker from '../lib/crypto/cryptoworker'; |
|
|
|
import LottieLoader from '../lib/lottieLoader'; |
|
|
|
import LottieLoader from '../lib/lottieLoader'; |
|
|
|
import appStickersManager from "../lib/appManagers/appStickersManager"; |
|
|
|
import appStickersManager from "../lib/appManagers/appStickersManager"; |
|
|
|
import appDocsManager from "../lib/appManagers/appDocsManager"; |
|
|
|
import appDocsManager from "../lib/appManagers/appDocsManager"; |
|
|
|
|
|
|
|
import {AppImManager} from "../lib/appManagers/appImManager"; |
|
|
|
|
|
|
|
import {AppMediaViewer} from '../lib/appManagers/appMediaViewer'; |
|
|
|
|
|
|
|
|
|
|
|
export type MTDocument = { |
|
|
|
export type MTDocument = { |
|
|
|
_: 'document', |
|
|
|
_: 'document', |
|
|
@ -213,9 +215,20 @@ export class LazyLoadQueue { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function wrapVideo(doc: MTDocument, container: HTMLDivElement, middleware: () => boolean, messageID: number, justLoader = true, preloader?: ProgressivePreloader) { |
|
|
|
export function wrapVideo(this: any, doc: MTDocument, container: HTMLDivElement, message: any, justLoader = true, preloader?: ProgressivePreloader) { |
|
|
|
if(!container.firstElementChild || container.firstElementChild.tagName != 'IMG') { |
|
|
|
//if(!container.firstElementChild || container.firstElementChild.tagName != 'IMG') {
|
|
|
|
let size = appPhotosManager.setAttachmentSize(doc, container); |
|
|
|
let size = appPhotosManager.setAttachmentSize(doc, container); |
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let peerID = this.peerID ? this.peerID : this.currentMessageID; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//container.classList.add('video');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let img = container.firstElementChild as HTMLImageElement || new Image(); |
|
|
|
|
|
|
|
img.setAttribute('message-id', '' + message.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!container.contains(img)) { |
|
|
|
|
|
|
|
container.append(img); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//return Promise.resolve();
|
|
|
|
//return Promise.resolve();
|
|
|
@ -227,17 +240,18 @@ export function wrapVideo(doc: MTDocument, container: HTMLDivElement, middleware |
|
|
|
let loadVideo = () => { |
|
|
|
let loadVideo = () => { |
|
|
|
let promise = appDocsManager.downloadDoc(doc); |
|
|
|
let promise = appDocsManager.downloadDoc(doc); |
|
|
|
|
|
|
|
|
|
|
|
promise.notify = (details: {done: number, total: number}) => { |
|
|
|
/* promise.notify = (details: {done: number, total: number}) => { |
|
|
|
console.log('doc download', promise, details); |
|
|
|
console.log('doc download', promise, details); |
|
|
|
preloader.setProgress(details.done); |
|
|
|
preloader.setProgress(details.done); |
|
|
|
}; |
|
|
|
}; */ |
|
|
|
|
|
|
|
|
|
|
|
return promise.then(blob => { |
|
|
|
return promise.then(blob => { |
|
|
|
if(!middleware()) { |
|
|
|
if((this.peerID ? this.peerID : this.currentMessageID) != peerID) { |
|
|
|
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('loaded doc:', doc, blob, container.firstElementChild); |
|
|
|
console.log('loaded doc:', doc, blob, container); |
|
|
|
|
|
|
|
|
|
|
|
let video = document.createElement('video'); |
|
|
|
let video = document.createElement('video'); |
|
|
|
video.loop = true; |
|
|
|
video.loop = true; |
|
|
@ -245,52 +259,50 @@ export function wrapVideo(doc: MTDocument, container: HTMLDivElement, middleware |
|
|
|
|
|
|
|
|
|
|
|
if(!justLoader) { |
|
|
|
if(!justLoader) { |
|
|
|
video.controls = true; |
|
|
|
video.controls = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
video.volume = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
video.setAttribute('message-id', '' + messageID); |
|
|
|
video.setAttribute('message-id', '' + message.id); |
|
|
|
|
|
|
|
|
|
|
|
let source = document.createElement('source'); |
|
|
|
let source = document.createElement('source'); |
|
|
|
//source.src = doc.url;
|
|
|
|
//source.src = doc.url;
|
|
|
|
source.src = URL.createObjectURL(blob); |
|
|
|
source.src = URL.createObjectURL(blob); |
|
|
|
source.type = doc.mime_type; |
|
|
|
source.type = doc.mime_type; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(img && container.contains(img)) { |
|
|
|
|
|
|
|
container.removeChild(img); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
video.append(source); |
|
|
|
video.append(source); |
|
|
|
container.append(video); |
|
|
|
container.append(video); |
|
|
|
|
|
|
|
|
|
|
|
if(container.firstElementChild) { |
|
|
|
|
|
|
|
container.firstElementChild.remove(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preloader.detach(); |
|
|
|
preloader.detach(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if(doc.type == 'gif') { |
|
|
|
if(doc.type == 'gif') { |
|
|
|
return loadVideo(); |
|
|
|
return this.peerID ? this.loadMediaQueuePush(loadVideo) : loadVideo(); |
|
|
|
} else { // if video
|
|
|
|
} else { // if video
|
|
|
|
return appPhotosManager.preloadPhoto(doc).then((blob) => { |
|
|
|
let load = () => appPhotosManager.preloadPhoto(doc).then((blob) => { |
|
|
|
if(!middleware()) { |
|
|
|
if((this.peerID ? this.peerID : this.currentMessageID) != peerID) { |
|
|
|
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(container.firstElementChild) { |
|
|
|
img.src = URL.createObjectURL(blob); |
|
|
|
container.firstElementChild.remove(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let image = new Image(); |
|
|
|
|
|
|
|
image.src = URL.createObjectURL(blob); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* image.style.height = doc.h + 'px'; |
|
|
|
/* image.style.height = doc.h + 'px'; |
|
|
|
image.style.width = doc.w + 'px'; */ |
|
|
|
image.style.width = doc.w + 'px'; */ |
|
|
|
|
|
|
|
|
|
|
|
image.setAttribute('message-id', '' + messageID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
container.append(image); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!justLoader) { |
|
|
|
if(!justLoader) { |
|
|
|
return loadVideo(); |
|
|
|
return loadVideo(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
preloader.detach(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.peerID ? this.loadMediaQueuePush(load) : load(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -350,6 +362,37 @@ export function scrollable(el: HTMLDivElement, x = false, y = true) { |
|
|
|
return container; |
|
|
|
return container; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function wrapPhoto(this: AppImManager, photo: any, message: any, container: HTMLDivElement) { |
|
|
|
|
|
|
|
//container.classList.add('photo');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let peerID = this.peerID; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let size = appPhotosManager.setAttachmentSize(photo.id, container); |
|
|
|
|
|
|
|
let image = container.firstElementChild as HTMLImageElement || new Image(); |
|
|
|
|
|
|
|
image.setAttribute('message-id', message.mid); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!container.contains(image)) { |
|
|
|
|
|
|
|
container.append(image); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let preloader = new ProgressivePreloader(container, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let load = () => appPhotosManager.preloadPhoto(photo.id, size).then((blob) => { |
|
|
|
|
|
|
|
if(this.peerID != peerID) { |
|
|
|
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image.src = URL.createObjectURL(blob); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preloader.detach(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('wrapPhoto', load, container, image); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.loadMediaQueue ? this.loadMediaQueuePush(load) : load(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function wrapSticker(doc: MTDocument, div: HTMLDivElement, middleware?: () => boolean, lazyLoadQueue?: LazyLoadQueue, group?: string, canvas?: boolean) { |
|
|
|
export function wrapSticker(doc: MTDocument, div: HTMLDivElement, middleware?: () => boolean, lazyLoadQueue?: LazyLoadQueue, group?: string, canvas?: boolean) { |
|
|
|
let stickerType = doc.mime_type == "application/x-tgsticker" ? 2 : (doc.mime_type == "image/webp" ? 1 : 0); |
|
|
|
let stickerType = doc.mime_type == "application/x-tgsticker" ? 2 : (doc.mime_type == "image/webp" ? 1 : 0); |
|
|
|
|
|
|
|
|
|
|
|