|
|
@ -1,11 +1,7 @@ |
|
|
|
//import { MTDocument, ProgressivePreloader, wrapVideo } from "../../components/misc";
|
|
|
|
|
|
|
|
import appPeersManager from "./appPeersManager"; |
|
|
|
import appPeersManager from "./appPeersManager"; |
|
|
|
import appDialogsManager from "./appDialogsManager"; |
|
|
|
import appDialogsManager from "./appDialogsManager"; |
|
|
|
import appPhotosManager from "./appPhotosManager"; |
|
|
|
import appPhotosManager from "./appPhotosManager"; |
|
|
|
import appSidebarRight from "./appSidebarRight"; |
|
|
|
|
|
|
|
import { $rootScope } from "../utils"; |
|
|
|
|
|
|
|
import appMessagesManager from "./appMessagesManager"; |
|
|
|
import appMessagesManager from "./appMessagesManager"; |
|
|
|
//import { CancellablePromise } from "../mtproto/apiFileManager";
|
|
|
|
|
|
|
|
import { RichTextProcessor } from "../richtextprocessor"; |
|
|
|
import { RichTextProcessor } from "../richtextprocessor"; |
|
|
|
import { logger } from "../polyfill"; |
|
|
|
import { logger } from "../polyfill"; |
|
|
|
import ProgressivePreloader from "../../components/preloader"; |
|
|
|
import ProgressivePreloader from "../../components/preloader"; |
|
|
@ -33,10 +29,7 @@ export class AppMediaViewer { |
|
|
|
mover: this.overlaysDiv.querySelector('.media-viewer-mover') as HTMLDivElement |
|
|
|
mover: this.overlaysDiv.querySelector('.media-viewer-mover') as HTMLDivElement |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private reverse = false; |
|
|
|
|
|
|
|
public currentMessageID = 0; |
|
|
|
public currentMessageID = 0; |
|
|
|
private higherMsgID: number | undefined = 0; |
|
|
|
|
|
|
|
private lowerMsgID: number | undefined = 0; |
|
|
|
|
|
|
|
private preloader: ProgressivePreloader = null; |
|
|
|
private preloader: ProgressivePreloader = null; |
|
|
|
|
|
|
|
|
|
|
|
private lastTarget: HTMLElement = null; |
|
|
|
private lastTarget: HTMLElement = null; |
|
|
@ -57,23 +50,6 @@ export class AppMediaViewer { |
|
|
|
this.setMoverToTarget(this.lastTarget, true); |
|
|
|
this.setMoverToTarget(this.lastTarget, true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/* this.buttons.prev.addEventListener('click', () => { |
|
|
|
|
|
|
|
let id = this.reverse ? this.lowerMsgID : this.higherMsgID; |
|
|
|
|
|
|
|
if(id) { |
|
|
|
|
|
|
|
this.openMedia(appMessagesManager.getMessage(id), this.reverse); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.buttons.prev.style.display = 'none'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.buttons.next.addEventListener('click', () => { |
|
|
|
|
|
|
|
let id = this.reverse ? this.higherMsgID : this.lowerMsgID; |
|
|
|
|
|
|
|
if(id) { |
|
|
|
|
|
|
|
this.openMedia(appMessagesManager.getMessage(id), this.reverse); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.buttons.next.style.display = 'none'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); */ |
|
|
|
|
|
|
|
this.buttons.prev.addEventListener('click', () => { |
|
|
|
this.buttons.prev.addEventListener('click', () => { |
|
|
|
let target = this.prevTarget; |
|
|
|
let target = this.prevTarget; |
|
|
|
if(target) { |
|
|
|
if(target) { |
|
|
@ -104,71 +80,6 @@ export class AppMediaViewer { |
|
|
|
this.buttons.close.click(); |
|
|
|
this.buttons.close.click(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
/* this.buttons.prev.onclick = (e) => { |
|
|
|
|
|
|
|
let history = appSidebarRight.historiesStorage[$rootScope.selectedPeerID]['inputMessagesFilterPhotoVideo'].slice(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let message: any; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!this.reverse) { |
|
|
|
|
|
|
|
for(let mid of history) { |
|
|
|
|
|
|
|
if(mid > this.currentMessageID) { |
|
|
|
|
|
|
|
let _message = appMessagesManager.getMessage(mid); |
|
|
|
|
|
|
|
if(_message.media && _message.media.photo) { |
|
|
|
|
|
|
|
message = _message; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for(let mid of history) { |
|
|
|
|
|
|
|
if(mid < this.currentMessageID) { |
|
|
|
|
|
|
|
let _message = appMessagesManager.getMessage(mid); |
|
|
|
|
|
|
|
if(_message.media && _message.media.photo) { |
|
|
|
|
|
|
|
message = _message; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(message) { |
|
|
|
|
|
|
|
this.openMedia(message.media.photo, message.mid, this.reverse); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.buttons.prev.style.display = 'none'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.buttons.next.onclick = (e) => { |
|
|
|
|
|
|
|
let history = appSidebarRight.historiesStorage[$rootScope.selectedPeerID]['inputMessagesFilterPhotoVideo'].slice(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let message: any; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.reverse) { |
|
|
|
|
|
|
|
for(let mid of history) { |
|
|
|
|
|
|
|
if(mid > this.currentMessageID) { |
|
|
|
|
|
|
|
let _message = appMessagesManager.getMessage(mid); |
|
|
|
|
|
|
|
if(_message.media && _message.media.photo) { |
|
|
|
|
|
|
|
message = _message; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
for(let mid of history) { |
|
|
|
|
|
|
|
if(mid < this.currentMessageID) { |
|
|
|
|
|
|
|
let _message = appMessagesManager.getMessage(mid); |
|
|
|
|
|
|
|
if(_message.media && _message.media.photo) { |
|
|
|
|
|
|
|
message = _message; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(message) { |
|
|
|
|
|
|
|
this.openMedia(message.media.photo, message.mid, this.reverse); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.buttons.next.style.display = 'none'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; */ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public setMoverToTarget(target: HTMLElement, closing = false) { |
|
|
|
public setMoverToTarget(target: HTMLElement, closing = false) { |
|
|
@ -186,6 +97,8 @@ export class AppMediaViewer { |
|
|
|
mover.style.width = containerRect.width + 'px'; |
|
|
|
mover.style.width = containerRect.width + 'px'; |
|
|
|
mover.style.height = containerRect.height + 'px'; |
|
|
|
mover.style.height = containerRect.height + 'px'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mover.style.borderRadius = window.getComputedStyle(target.parentElement).getPropertyValue('border-radius'); |
|
|
|
|
|
|
|
|
|
|
|
if(!closing) { |
|
|
|
if(!closing) { |
|
|
|
let img: HTMLImageElement; |
|
|
|
let img: HTMLImageElement; |
|
|
|
let video: HTMLVideoElement; |
|
|
|
let video: HTMLVideoElement; |
|
|
@ -216,27 +129,30 @@ export class AppMediaViewer { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
this.overlaysDiv.classList.remove('active'); |
|
|
|
this.overlaysDiv.classList.remove('active'); |
|
|
|
}, 125); |
|
|
|
}, 200 / 2); |
|
|
|
setTimeout(() => { |
|
|
|
setTimeout(() => { |
|
|
|
mover.innerHTML = ''; |
|
|
|
mover.innerHTML = ''; |
|
|
|
mover.classList.remove('active'); |
|
|
|
mover.classList.remove('active'); |
|
|
|
mover.style.display = 'none'; |
|
|
|
mover.style.display = 'none'; |
|
|
|
}, 250); |
|
|
|
}, 200); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return () => { |
|
|
|
return () => { |
|
|
|
mover.style.transform = `translate(${containerRect.left}px, ${containerRect.top}px) scale(1, 1)`; |
|
|
|
mover.style.transform = `translate(${containerRect.left}px, ${containerRect.top}px) scale(1, 1)`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
mover.style.borderRadius = ''; |
|
|
|
|
|
|
|
}, 200 / 2); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public openMedia(message: any, reverse = false, target?: HTMLElement, prevTarget?: HTMLElement, nextTarget?: HTMLElement) { |
|
|
|
public openMedia(message: any, target?: HTMLElement, prevTarget?: HTMLElement, nextTarget?: HTMLElement) { |
|
|
|
this.log('openMedia doc:', message, prevTarget, nextTarget); |
|
|
|
this.log('openMedia doc:', message, prevTarget, nextTarget); |
|
|
|
let media = message.media.photo || message.media.document || message.media.webpage.document || message.media.webpage.photo; |
|
|
|
let media = message.media.photo || message.media.document || message.media.webpage.document || message.media.webpage.photo; |
|
|
|
|
|
|
|
|
|
|
|
let isVideo = media.mime_type == 'video/mp4'; |
|
|
|
let isVideo = media.mime_type == 'video/mp4'; |
|
|
|
|
|
|
|
|
|
|
|
this.currentMessageID = message.mid; |
|
|
|
this.currentMessageID = message.mid; |
|
|
|
this.reverse = reverse; |
|
|
|
|
|
|
|
this.prevTarget = prevTarget || null; |
|
|
|
this.prevTarget = prevTarget || null; |
|
|
|
this.nextTarget = nextTarget || null; |
|
|
|
this.nextTarget = nextTarget || null; |
|
|
|
|
|
|
|
|
|
|
@ -273,13 +189,9 @@ export class AppMediaViewer { |
|
|
|
let mover = this.content.mover; |
|
|
|
let mover = this.content.mover; |
|
|
|
|
|
|
|
|
|
|
|
this.lastTarget = target; |
|
|
|
this.lastTarget = target; |
|
|
|
//this.setMoverToTarget(target);
|
|
|
|
|
|
|
|
let maxWidth = appPhotosManager.windowW - 16; |
|
|
|
let maxWidth = appPhotosManager.windowW - 16; |
|
|
|
let maxHeight = appPhotosManager.windowH - 100; |
|
|
|
let maxHeight = appPhotosManager.windowH - 100; |
|
|
|
if(isVideo) { |
|
|
|
if(isVideo) { |
|
|
|
//this.preloader.attach(container);
|
|
|
|
|
|
|
|
//this.preloader.setProgress(75);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let size = appPhotosManager.setAttachmentSize(media, container, maxWidth, maxHeight); |
|
|
|
let size = appPhotosManager.setAttachmentSize(media, container, maxWidth, maxHeight); |
|
|
|
|
|
|
|
|
|
|
|
this.log('will wrap video', media, size); |
|
|
|
this.log('will wrap video', media, size); |
|
|
@ -296,18 +208,6 @@ export class AppMediaViewer { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/* appPhotosManager.setAttachmentSize(media, container, appPhotosManager.windowW, appPhotosManager.windowH); |
|
|
|
|
|
|
|
wrapVideo.call(this, media, container, message, false, this.preloader).then(() => { |
|
|
|
|
|
|
|
if(this.currentMessageID != message.mid) { |
|
|
|
|
|
|
|
this.log.warn('media viewer changed video'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
container.classList.remove('loading'); |
|
|
|
|
|
|
|
container.style.width = ''; |
|
|
|
|
|
|
|
container.style.height = ''; |
|
|
|
|
|
|
|
}); */ |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let size = appPhotosManager.setAttachmentSize(media.id, container, maxWidth, maxHeight); |
|
|
|
let size = appPhotosManager.setAttachmentSize(media.id, container, maxWidth, maxHeight); |
|
|
|
|
|
|
|
|
|
|
@ -337,31 +237,8 @@ export class AppMediaViewer { |
|
|
|
}, 0); |
|
|
|
}, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* let history = appSidebarRight.historiesStorage[$rootScope.selectedPeerID]['inputMessagesFilterPhotoVideo'].slice(); |
|
|
|
|
|
|
|
let index = history.findIndex(m => m == message.mid); |
|
|
|
|
|
|
|
let comparer = (mid: number) => { |
|
|
|
|
|
|
|
let _message = appMessagesManager.getMessage(mid); |
|
|
|
|
|
|
|
let media = _message.media; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(media && (media.photo || (media.document && ['video', 'gif'].indexOf(media.document.type) !== -1))) return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.higherMsgID = history.slice(0, index).reverse().find(comparer); |
|
|
|
|
|
|
|
this.lowerMsgID = history.slice(index + 1).find(comparer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.reverse) { |
|
|
|
|
|
|
|
this.buttons.prev.style.display = this.lowerMsgID !== undefined ? '' : 'none'; |
|
|
|
|
|
|
|
this.buttons.next.style.display = this.higherMsgID !== undefined ? '' : 'none'; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.buttons.prev.style.display = this.higherMsgID !== undefined ? '' : 'none'; |
|
|
|
|
|
|
|
this.buttons.next.style.display = this.lowerMsgID !== undefined ? '' : 'none'; |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.buttons.prev.style.display = this.prevTarget ? '' : 'none'; |
|
|
|
this.buttons.prev.style.display = this.prevTarget ? '' : 'none'; |
|
|
|
this.buttons.next.style.display = this.nextTarget ? '' : 'none'; |
|
|
|
this.buttons.next.style.display = this.nextTarget ? '' : 'none'; |
|
|
|
|
|
|
|
|
|
|
|
//console.log('prev and next', prevMsgID, nextMsgID);
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|