@ -5,6 +5,8 @@ import CryptoWorker from '../lib/crypto/cryptoworker';
@@ -5,6 +5,8 @@ import CryptoWorker from '../lib/crypto/cryptoworker';
import LottieLoader from '../lib/lottieLoader' ;
import appStickersManager from "../lib/appManagers/appStickersManager" ;
import appDocsManager from "../lib/appManagers/appDocsManager" ;
import { AppImManager } from "../lib/appManagers/appImManager" ;
import { AppMediaViewer } from '../lib/appManagers/appMediaViewer' ;
export type MTDocument = {
_ : 'document' ,
@ -213,9 +215,20 @@ export class LazyLoadQueue {
@@ -213,9 +215,20 @@ export class LazyLoadQueue {
}
}
export function wrapVideo ( doc : MTDocument , container : HTMLDivElement , middleware : ( ) = > boolean , messageID : number , justLoader = true , preloader? : ProgressivePreloader ) {
if ( ! container . firstElementChild || container . firstElementChild . tagName != 'IMG' ) {
export function wrapVideo ( this : any , doc : MTDocument , container : HTMLDivElement , message : any , justLoader = true , preloader? : ProgressivePreloader ) {
//if(!container.firstElementChild || container.firstElementChild.tagName != 'IMG') {
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();
@ -227,17 +240,18 @@ export function wrapVideo(doc: MTDocument, container: HTMLDivElement, middleware
@@ -227,17 +240,18 @@ export function wrapVideo(doc: MTDocument, container: HTMLDivElement, middleware
let loadVideo = ( ) = > {
let promise = appDocsManager . downloadDoc ( doc ) ;
promise . notify = ( details : { done : number , total : number } ) = > {
/ * p r o m i s e . n o t i f y = ( d e t a i l s : { d o n e : n u m b e r , t o t a l : n u m b e r } ) = > {
console . log ( 'doc download' , promise , details ) ;
preloader . setProgress ( details . done ) ;
} ;
} ; * /
return promise . then ( blob = > {
if ( ! middleware ( ) ) {
if ( ( this . peerID ? this . peerID : this.currentMessageID ) != peerID ) {
this . log . warn ( 'peer changed' ) ;
return ;
}
console . log ( 'loaded doc:' , doc , blob , container . firstElementChild ) ;
console . log ( 'loaded doc:' , doc , blob , container ) ;
let video = document . createElement ( 'video' ) ;
video . loop = true ;
@ -245,52 +259,50 @@ export function wrapVideo(doc: MTDocument, container: HTMLDivElement, middleware
@@ -245,52 +259,50 @@ export function wrapVideo(doc: MTDocument, container: HTMLDivElement, middleware
if ( ! justLoader ) {
video . controls = true ;
} else {
video . volume = 0 ;
}
video . setAttribute ( 'message-id' , '' + messageID ) ;
video . setAttribute ( 'message-id' , '' + message . id ) ;
let source = document . createElement ( 'source' ) ;
//source.src = doc.url;
source . src = URL . createObjectURL ( blob ) ;
source . type = doc . mime_type ;
if ( img && container . contains ( img ) ) {
container . removeChild ( img ) ;
}
video . append ( source ) ;
container . append ( video ) ;
if ( container . firstElementChild ) {
container . firstElementChild . remove ( ) ;
}
preloader . detach ( ) ;
} ) ;
} ;
if ( doc . type == 'gif' ) {
return loadVideo ( ) ;
return this . peerID ? this . loadMediaQueuePush ( loadVideo ) : loadVideo ( ) ;
} else { // if video
return appPhotosManager . preloadPhoto ( doc ) . then ( ( blob ) = > {
if ( ! middleware ( ) ) {
let load = ( ) = > appPhotosManager . preloadPhoto ( doc ) . then ( ( blob ) = > {
if ( ( this . peerID ? this . peerID : this.currentMessageID ) != peerID ) {
this . log . warn ( 'peer changed' ) ;
return ;
}
if ( container . firstElementChild ) {
container . firstElementChild . remove ( ) ;
}
let image = new Image ( ) ;
image . src = URL . createObjectURL ( blob ) ;
img . src = URL . createObjectURL ( blob ) ;
/ * i m a g e . s t y l e . h e i g h t = d o c . h + ' p x ' ;
image . style . width = doc . w + 'px' ; * /
image . setAttribute ( 'message-id' , '' + messageID ) ;
container . append ( image ) ;
if ( ! justLoader ) {
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) {
@@ -350,6 +362,37 @@ export function scrollable(el: HTMLDivElement, x = false, y = true) {
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 ) {
let stickerType = doc . mime_type == "application/x-tgsticker" ? 2 : ( doc . mime_type == "image/webp" ? 1 : 0 ) ;