|
|
@ -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', |
|
|
@ -39,50 +41,50 @@ export type MTPhotoSize = { |
|
|
|
|
|
|
|
|
|
|
|
let onRippleClick = function(this: HTMLElement, e: MouseEvent) { |
|
|
|
let onRippleClick = function(this: HTMLElement, e: MouseEvent) { |
|
|
|
var $circle = this.firstElementChild as HTMLSpanElement;//this.querySelector('.c-ripple__circle') as HTMLSpanElement;
|
|
|
|
var $circle = this.firstElementChild as HTMLSpanElement;//this.querySelector('.c-ripple__circle') as HTMLSpanElement;
|
|
|
|
|
|
|
|
|
|
|
|
var rect = this.parentElement.getBoundingClientRect(); |
|
|
|
var rect = this.parentElement.getBoundingClientRect(); |
|
|
|
var x = e.clientX - rect.left; //x position within the element.
|
|
|
|
var x = e.clientX - rect.left; //x position within the element.
|
|
|
|
var y = e.clientY - rect.top; |
|
|
|
var y = e.clientY - rect.top; |
|
|
|
|
|
|
|
|
|
|
|
/* var x = e.pageX - this.parentElement.offsetLeft; |
|
|
|
/* var x = e.pageX - this.parentElement.offsetLeft; |
|
|
|
var y = e.pageY - this.parentElement.offsetTop - this.parentElement.scrollHeight; */ |
|
|
|
var y = e.pageY - this.parentElement.offsetTop - this.parentElement.scrollHeight; */ |
|
|
|
|
|
|
|
|
|
|
|
$circle.style.top = y + 'px'; |
|
|
|
$circle.style.top = y + 'px'; |
|
|
|
$circle.style.left = x + 'px'; |
|
|
|
$circle.style.left = x + 'px'; |
|
|
|
|
|
|
|
|
|
|
|
this.classList.add('active'); |
|
|
|
this.classList.add('active'); |
|
|
|
|
|
|
|
|
|
|
|
//console.log('onrippleclick', e/* e.pageY, this.parentElement.offsetTop */);
|
|
|
|
//console.log('onrippleclick', e/* e.pageY, this.parentElement.offsetTop */);
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export function ripple(elem: Element) { |
|
|
|
export function ripple(elem: Element) { |
|
|
|
/* elem.addEventListener('click', function(e) { |
|
|
|
/* elem.addEventListener('click', function(e) { |
|
|
|
var $circle = elem.querySelector('.c-ripple__circle') as HTMLSpanElement; |
|
|
|
var $circle = elem.querySelector('.c-ripple__circle') as HTMLSpanElement; |
|
|
|
|
|
|
|
|
|
|
|
var x = e.pageX - elem.offsetLeft; |
|
|
|
var x = e.pageX - elem.offsetLeft; |
|
|
|
var y = e.pageY - elem.offsetTop; |
|
|
|
var y = e.pageY - elem.offsetTop; |
|
|
|
|
|
|
|
|
|
|
|
$circle.style.top = y + 'px'; |
|
|
|
$circle.style.top = y + 'px'; |
|
|
|
$circle.style.left = x + 'px'; |
|
|
|
$circle.style.left = x + 'px'; |
|
|
|
|
|
|
|
|
|
|
|
elem.classList.add('active'); |
|
|
|
elem.classList.add('active'); |
|
|
|
}); */ |
|
|
|
}); */ |
|
|
|
|
|
|
|
|
|
|
|
let r = document.createElement('div'); |
|
|
|
let r = document.createElement('div'); |
|
|
|
r.classList.add('c-ripple'); |
|
|
|
r.classList.add('c-ripple'); |
|
|
|
|
|
|
|
|
|
|
|
let span = document.createElement('span'); |
|
|
|
let span = document.createElement('span'); |
|
|
|
span.classList.add('c-ripple__circle'); |
|
|
|
span.classList.add('c-ripple__circle'); |
|
|
|
|
|
|
|
|
|
|
|
r.append(span); |
|
|
|
r.append(span); |
|
|
|
elem.append(r); |
|
|
|
elem.append(r); |
|
|
|
|
|
|
|
|
|
|
|
r.addEventListener('click', onRippleClick); |
|
|
|
r.addEventListener('click', onRippleClick); |
|
|
|
|
|
|
|
|
|
|
|
let onEnd = () => { |
|
|
|
let onEnd = () => { |
|
|
|
r.classList.remove('active'); |
|
|
|
r.classList.remove('active'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
for(let type of ['animationend', 'webkitAnimationEnd', 'oanimationend', 'MSAnimationEnd']) { |
|
|
|
for(let type of ['animationend', 'webkitAnimationEnd', 'oanimationend', 'MSAnimationEnd']) { |
|
|
|
r.addEventListener(type, onEnd); |
|
|
|
r.addEventListener(type, onEnd); |
|
|
|
} |
|
|
|
} |
|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -335,10 +347,10 @@ export function scrollable(el: HTMLDivElement, x = false, y = true) { |
|
|
|
container.classList.add('scrollable'); |
|
|
|
container.classList.add('scrollable'); |
|
|
|
if(x) container.classList.add('scrollable-x'); |
|
|
|
if(x) container.classList.add('scrollable-x'); |
|
|
|
if(y) container.classList.add('scrollable-y'); |
|
|
|
if(y) container.classList.add('scrollable-y'); |
|
|
|
|
|
|
|
|
|
|
|
container.addEventListener('mouseover', () => { |
|
|
|
container.addEventListener('mouseover', () => { |
|
|
|
container.classList.add('active'); |
|
|
|
container.classList.add('active'); |
|
|
|
|
|
|
|
|
|
|
|
container.addEventListener('mouseout', () => { |
|
|
|
container.addEventListener('mouseout', () => { |
|
|
|
container.classList.remove('active'); |
|
|
|
container.classList.remove('active'); |
|
|
|
}, {once: true}); |
|
|
|
}, {once: true}); |
|
|
@ -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); |
|
|
|
|
|
|
|
|
|
|
@ -399,24 +442,24 @@ export function wrapSticker(doc: MTDocument, div: HTMLDivElement, middleware?: ( |
|
|
|
animationData: JSON.parse(json), |
|
|
|
animationData: JSON.parse(json), |
|
|
|
renderer: canvas ? 'canvas' : 'svg' |
|
|
|
renderer: canvas ? 'canvas' : 'svg' |
|
|
|
}, group); |
|
|
|
}, group); |
|
|
|
|
|
|
|
|
|
|
|
if(!canvas) { |
|
|
|
if(!canvas) { |
|
|
|
div.addEventListener('mouseover', (e) => { |
|
|
|
div.addEventListener('mouseover', (e) => { |
|
|
|
let animation = LottieLoader.getAnimation(div, group); |
|
|
|
let animation = LottieLoader.getAnimation(div, group); |
|
|
|
|
|
|
|
|
|
|
|
if(animation) { |
|
|
|
if(animation) { |
|
|
|
//console.log('sticker hover', animation, div);
|
|
|
|
//console.log('sticker hover', animation, div);
|
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
animation.loop = true; |
|
|
|
animation.loop = true; |
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
if(animation.currentFrame == animation.totalFrames - 1) { |
|
|
|
if(animation.currentFrame == animation.totalFrames - 1) { |
|
|
|
animation.goToAndPlay(0, true); |
|
|
|
animation.goToAndPlay(0, true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
animation.play(); |
|
|
|
animation.play(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
div.addEventListener('mouseout', () => { |
|
|
|
div.addEventListener('mouseout', () => { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
animation.loop = false; |
|
|
|
animation.loop = false; |
|
|
@ -451,11 +494,11 @@ export function horizontalMenu(tabs: HTMLUListElement, content: HTMLDivElement, |
|
|
|
|
|
|
|
|
|
|
|
tabs.addEventListener('click', function(e) { |
|
|
|
tabs.addEventListener('click', function(e) { |
|
|
|
let target = e.target as HTMLLIElement; |
|
|
|
let target = e.target as HTMLLIElement; |
|
|
|
|
|
|
|
|
|
|
|
if(target.tagName != 'LI') { |
|
|
|
if(target.tagName != 'LI') { |
|
|
|
target = findUpTag(target, 'LI'); |
|
|
|
target = findUpTag(target, 'LI'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('tabs click:', target); |
|
|
|
console.log('tabs click:', target); |
|
|
|
|
|
|
|
|
|
|
|
if(target.classList.contains('active')) return false; |
|
|
|
if(target.classList.contains('active')) return false; |
|
|
|