|
|
|
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
|
|
|
|
import { horizontalMenu, formatPhoneNumber, putPreloader } from "../../components/misc"; |
|
|
|
|
import { horizontalMenu, formatPhoneNumber, putPreloader, renderImageFromUrl } from "../../components/misc"; |
|
|
|
|
import Scrollable from '../../components/scrollable'; |
|
|
|
|
import { $rootScope } from "../utils"; |
|
|
|
|
import appMessagesManager from "./appMessagesManager"; |
|
|
|
@ -67,6 +67,9 @@ class AppSidebarRight {
@@ -67,6 +67,9 @@ class AppSidebarRight {
|
|
|
|
|
[type: string]: number[] |
|
|
|
|
} |
|
|
|
|
} = {}; |
|
|
|
|
public usedFromHistory: { |
|
|
|
|
[type: string]: number |
|
|
|
|
} = {}; |
|
|
|
|
|
|
|
|
|
private log = logger('SR'); |
|
|
|
|
|
|
|
|
@ -83,7 +86,7 @@ class AppSidebarRight {
@@ -83,7 +86,7 @@ class AppSidebarRight {
|
|
|
|
|
private mediaDivsByIDs: { |
|
|
|
|
[mid: number]: HTMLDivElement |
|
|
|
|
} = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public urlsToRevoke: string[] = []; |
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
@ -93,8 +96,8 @@ class AppSidebarRight {
@@ -93,8 +96,8 @@ class AppSidebarRight {
|
|
|
|
|
this.scroll = new Scrollable(this.sidebarEl, 'y', 1200, 'SR'); |
|
|
|
|
this.scroll.container.addEventListener('scroll', this.onSidebarScroll.bind(this)); |
|
|
|
|
this.scroll.onScrolledBottom = () => { |
|
|
|
|
if(this.sharedMediaSelected && !this.scroll.hiddenElements.down.length |
|
|
|
|
&& this.sharedMediaSelected.childElementCount/* && false */) { |
|
|
|
|
if(this.sharedMediaSelected && !this.scroll.hiddenElements.down.length && this.sharedMediaSelected.childElementCount/* && false */) { |
|
|
|
|
this.log('onScrolledBottom will load media'); |
|
|
|
|
this.loadSidebarMedia(true); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -104,7 +107,7 @@ class AppSidebarRight {
@@ -104,7 +107,7 @@ class AppSidebarRight {
|
|
|
|
|
|
|
|
|
|
this.sharedMediaType = this.sharedMediaTypes[id]; |
|
|
|
|
this.sharedMediaSelected = tabContent.firstElementChild as HTMLDivElement; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.prevTabID != -1 && !this.sharedMediaSelected.childElementCount) { // quick brown fix
|
|
|
|
|
this.loadSidebarMedia(true); |
|
|
|
|
} |
|
|
|
@ -142,11 +145,10 @@ class AppSidebarRight {
@@ -142,11 +145,10 @@ class AppSidebarRight {
|
|
|
|
|
|
|
|
|
|
let ids = Object.keys(this.mediaDivsByIDs).map(k => +k).sort(); |
|
|
|
|
let idx = ids.findIndex(i => i == messageID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let targets = ids.map(id => ({element: this.mediaDivsByIDs[id], mid: id})); |
|
|
|
|
|
|
|
|
|
appMediaViewer.openMedia(message, target, false, this.sidebarEl, |
|
|
|
|
targets.slice(idx + 1).reverse(), targets.slice(0, idx).reverse(), () => this.loadSidebarMedia(true)); |
|
|
|
|
appMediaViewer.openMedia(message, target, false, this.sidebarEl, targets.slice(idx + 1).reverse(), targets.slice(0, idx).reverse(), () => this.loadSidebarMedia(true)); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.profileElements.notificationsCheckbox.addEventListener('change', () => { |
|
|
|
@ -154,12 +156,7 @@ class AppSidebarRight {
@@ -154,12 +156,7 @@ class AppSidebarRight {
|
|
|
|
|
appImManager.mutePeer(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', () => { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
this.scroll.onScroll(); |
|
|
|
|
this.onSidebarScroll(); |
|
|
|
|
}, 0); |
|
|
|
|
}); |
|
|
|
|
window.addEventListener('resize', this.onSidebarScroll.bind(this)); |
|
|
|
|
|
|
|
|
|
if(testScroll) { |
|
|
|
|
let div = document.createElement('div'); |
|
|
|
@ -191,6 +188,7 @@ class AppSidebarRight {
@@ -191,6 +188,7 @@ class AppSidebarRight {
|
|
|
|
|
setTimeout(() => this.lazyLoadQueueSidebar.check(), 200); |
|
|
|
|
this.sidebarEl.classList.add('active'); |
|
|
|
|
} else this.sidebarEl.classList.remove('active'); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -201,12 +199,237 @@ class AppSidebarRight {
@@ -201,12 +199,237 @@ class AppSidebarRight {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public performSearchResult(ids: number[], type: string) { |
|
|
|
|
let peerID = this.peerID; |
|
|
|
|
|
|
|
|
|
let sharedMediaDiv: HTMLDivElement; |
|
|
|
|
let messages: any[] = []; |
|
|
|
|
for(let mid of ids) { |
|
|
|
|
let message = appMessagesManager.getMessage(mid); |
|
|
|
|
if(message.media) messages.push(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let elemsToAppend: HTMLElement[] = []; |
|
|
|
|
|
|
|
|
|
/*'inputMessagesFilterContacts', |
|
|
|
|
'inputMessagesFilterPhotoVideo', |
|
|
|
|
'inputMessagesFilterDocument', |
|
|
|
|
'inputMessagesFilterUrl', |
|
|
|
|
'inputMessagesFilterVoice'*/ |
|
|
|
|
switch(type) { |
|
|
|
|
case 'inputMessagesFilterPhotoVideo': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentMedia; |
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
let media = message.media.photo || message.media.document || (message.media.webpage && message.media.webpage.document); |
|
|
|
|
if(!media) { |
|
|
|
|
//this.log('no media!', message);
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(media._ == 'document' && media.type != 'video'/* && media.type != 'gif' */) { |
|
|
|
|
//this.log('broken video', media);
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
//console.log(message, photo);
|
|
|
|
|
|
|
|
|
|
let isPhoto = media._ == 'photo'; |
|
|
|
|
|
|
|
|
|
let photo = isPhoto ? appPhotosManager.getPhoto(media.id) : null; |
|
|
|
|
if(!photo || !photo.downloaded) { |
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media, photo, div);
|
|
|
|
|
|
|
|
|
|
let sizes = media.sizes || media.thumbs; |
|
|
|
|
if(sizes && sizes[0].bytes) { |
|
|
|
|
appPhotosManager.setAttachmentPreview(sizes[0].bytes, div, false, true); |
|
|
|
|
} /* else { |
|
|
|
|
this.log('no stripped size', message, media); |
|
|
|
|
} */ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media);
|
|
|
|
|
|
|
|
|
|
let load = () => appPhotosManager.preloadPhoto(isPhoto ? media.id : media, appPhotosManager.choosePhotoSize(media, 200, 200)) |
|
|
|
|
.then((blob) => { |
|
|
|
|
if($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(photo && photo.url) { |
|
|
|
|
renderImageFromUrl(div, photo.url); |
|
|
|
|
} else { |
|
|
|
|
let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
|
|
|
|
|
let img = new Image(); |
|
|
|
|
img.src = url; |
|
|
|
|
img.onload = () => { |
|
|
|
|
div.style.backgroundImage = 'url(' + url + ')'; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//div.style.backgroundImage = 'url(' + url + ')';
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
div.dataset.mid = '' + message.mid; |
|
|
|
|
|
|
|
|
|
if(photo && photo.downloaded) load(); |
|
|
|
|
else this.lazyLoadQueueSidebar.push({div, load}); |
|
|
|
|
|
|
|
|
|
this.lastSharedMediaDiv.append(div); |
|
|
|
|
if(this.lastSharedMediaDiv.childElementCount == 3) { |
|
|
|
|
if(!this.scroll.contains(this.lastSharedMediaDiv)) { |
|
|
|
|
elemsToAppend.push(this.lastSharedMediaDiv); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.lastSharedMediaDiv = document.createElement('div'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.mediaDivsByIDs[message.mid] = div; |
|
|
|
|
|
|
|
|
|
//sharedMediaDiv.append(div);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'inputMessagesFilterDocument': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentDocuments; |
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
if(!message.media.document || message.media.document.type == 'voice') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let doc = message.media.document; |
|
|
|
|
if(doc.attributes) { |
|
|
|
|
if(doc.attributes.find((a: any) => a._ == "documentAttributeSticker")) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('come back down to my knees', message);
|
|
|
|
|
|
|
|
|
|
let div = wrapDocument(message.media.document, true); |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'inputMessagesFilterUrl': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentLinks; |
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
if(!message.media.webpage || message.media.webpage._ == 'webPageEmpty') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let webpage = message.media.webpage; |
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
|
|
|
|
|
let previewDiv = document.createElement('div'); |
|
|
|
|
previewDiv.classList.add('preview'); |
|
|
|
|
|
|
|
|
|
//this.log('wrapping webpage', webpage);
|
|
|
|
|
|
|
|
|
|
if(webpage.photo) { |
|
|
|
|
let load = () => appPhotosManager.preloadPhoto(webpage.photo.id, appPhotosManager.choosePhotoSize(webpage.photo, 380, 0)) |
|
|
|
|
.then((blob) => { |
|
|
|
|
if($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
renderImageFromUrl(previewDiv, webpage.photo.url); |
|
|
|
|
|
|
|
|
|
/* let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
|
|
|
|
|
previewDiv.style.backgroundImage = 'url(' + url + ')'; */ |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.lazyLoadQueueSidebar.push({div: previewDiv, load}); |
|
|
|
|
} else { |
|
|
|
|
previewDiv.innerText = (webpage.title || webpage.description || webpage.url || webpage.display_url).slice(0, 1); |
|
|
|
|
previewDiv.classList.add('empty'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let title = webpage.rTitle || ''; |
|
|
|
|
let subtitle = webpage.rDescription || ''; |
|
|
|
|
let url = RichTextProcessor.wrapRichText(webpage.url || ''); |
|
|
|
|
|
|
|
|
|
if(!title) { |
|
|
|
|
//title = new URL(webpage.url).hostname;
|
|
|
|
|
title = webpage.display_url.split('/', 1)[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
div.append(previewDiv); |
|
|
|
|
div.insertAdjacentHTML('beforeend', ` |
|
|
|
|
<div class="title">${title}</div> |
|
|
|
|
<div class="subtitle">${subtitle}</div> |
|
|
|
|
<div class="url">${url}</div> |
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
if(div.innerText.trim().length) { |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* case 'inputMessagesFilterVoice': { |
|
|
|
|
//this.log('wrapping audio', message.media);
|
|
|
|
|
if(!message.media || !message.media.document || message.media.document.type != 'voice') { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let doc = message.media.document; |
|
|
|
|
|
|
|
|
|
this.log('wrapping audio', doc); |
|
|
|
|
|
|
|
|
|
let audioDiv = wrapAudio(doc); |
|
|
|
|
|
|
|
|
|
this.sharedMedia.contentAudio.append(audioDiv); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
//console.warn('death is my friend', message);
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(this.lastSharedMediaDiv.childElementCount && !this.scroll.contains(this.lastSharedMediaDiv)) { |
|
|
|
|
elemsToAppend.push(this.lastSharedMediaDiv); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(elemsToAppend.length) { |
|
|
|
|
//window.requestAnimationFrame(() => {
|
|
|
|
|
elemsToAppend.forEach(el => this.scroll.append(el)); |
|
|
|
|
//});
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(sharedMediaDiv) { |
|
|
|
|
let parent = sharedMediaDiv.parentElement; |
|
|
|
|
if(parent.lastElementChild.classList.contains('preloader')) { |
|
|
|
|
parent.lastElementChild.remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.onSidebarScroll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public loadSidebarMedia(single = false) { |
|
|
|
|
if(testScroll/* || 1 == 1 */) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('loadSidebarMedia', single, this.peerID);
|
|
|
|
|
|
|
|
|
|
this.log('loadSidebarMedia', single, this.peerID); |
|
|
|
|
|
|
|
|
|
let peerID = this.peerID; |
|
|
|
|
|
|
|
|
@ -214,16 +437,25 @@ class AppSidebarRight {
@@ -214,16 +437,25 @@ class AppSidebarRight {
|
|
|
|
|
typesToLoad = typesToLoad.filter(type => !this.loadedAllMedia[type]); |
|
|
|
|
if(!typesToLoad.length) return; |
|
|
|
|
|
|
|
|
|
if(!this.historiesStorage[peerID]) this.historiesStorage[peerID] = {}; |
|
|
|
|
let historyStorage = this.historiesStorage[peerID]; |
|
|
|
|
|
|
|
|
|
let historyStorage = this.historiesStorage[peerID] ?? (this.historiesStorage[peerID] = {}); |
|
|
|
|
|
|
|
|
|
this.scroll.lock(); |
|
|
|
|
|
|
|
|
|
let promises = typesToLoad.map(type => { |
|
|
|
|
if(this.loadSidebarMediaPromises[type]) return this.loadSidebarMediaPromises[type]; |
|
|
|
|
|
|
|
|
|
if(!historyStorage[type]) historyStorage[type] = []; |
|
|
|
|
let history = historyStorage[type]; |
|
|
|
|
let history = historyStorage[type] ?? (historyStorage[type] = []); |
|
|
|
|
|
|
|
|
|
let loadCount = (appPhotosManager.windowH / 130 | 0) * 3; |
|
|
|
|
|
|
|
|
|
// render from cache
|
|
|
|
|
if(history.length && this.usedFromHistory[type] < history.length && this.cleared[type]) { |
|
|
|
|
let ids = history.slice(this.usedFromHistory[type], this.usedFromHistory[type] + loadCount); |
|
|
|
|
this.log('will render from cache', this.usedFromHistory[type], history, ids, loadCount); |
|
|
|
|
this.usedFromHistory[type] += ids.length; |
|
|
|
|
this.performSearchResult(ids, type); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// заливать новую картинку сюда только после полной отправки!
|
|
|
|
|
//let maxID = this.minMediaID[type] || 0;
|
|
|
|
@ -233,9 +465,9 @@ class AppSidebarRight {
@@ -233,9 +465,9 @@ class AppSidebarRight {
|
|
|
|
|
? appMessagesManager.historiesStorage[peerID].history.slice() : []; |
|
|
|
|
|
|
|
|
|
maxID = !maxID && ids.length ? ids[ids.length - 1] : maxID; |
|
|
|
|
//this.log('search house of glass pre', type, ids, maxID);
|
|
|
|
|
this.log('search house of glass pre', type, ids, maxID); |
|
|
|
|
|
|
|
|
|
let loadCount = history.length ? 50 : 15; |
|
|
|
|
//let loadCount = history.length ? 50 : 15;
|
|
|
|
|
return this.loadSidebarMediaPromises[type] = appMessagesManager.getSearch(peerID, '', {_: type}, maxID, loadCount) |
|
|
|
|
.then(value => { |
|
|
|
|
ids = ids.concat(value.history); |
|
|
|
@ -243,238 +475,26 @@ class AppSidebarRight {
@@ -243,238 +475,26 @@ class AppSidebarRight {
|
|
|
|
|
|
|
|
|
|
this.log('search house of glass', type, value, ids, this.cleared); |
|
|
|
|
|
|
|
|
|
if(value.history.length < loadCount) { |
|
|
|
|
this.loadedAllMedia[type] = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(this.cleared[type]) { |
|
|
|
|
ids = history; |
|
|
|
|
delete this.cleared[type]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let sharedMediaDiv: HTMLDivElement; |
|
|
|
|
let messages: any[] = []; |
|
|
|
|
for(let mid of ids) { |
|
|
|
|
let message = appMessagesManager.getMessage(mid); |
|
|
|
|
if(message.media) messages.push(message); |
|
|
|
|
if(value.history.length < loadCount) { |
|
|
|
|
this.loadedAllMedia[type] = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let elemsToAppend: HTMLElement[] = []; |
|
|
|
|
|
|
|
|
|
/*'inputMessagesFilterContacts', |
|
|
|
|
'inputMessagesFilterPhotoVideo', |
|
|
|
|
'inputMessagesFilterDocument', |
|
|
|
|
'inputMessagesFilterUrl', |
|
|
|
|
'inputMessagesFilterVoice'*/ |
|
|
|
|
switch(type) { |
|
|
|
|
case 'inputMessagesFilterPhotoVideo': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentMedia; |
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
let media = message.media.photo || message.media.document || (message.media.webpage && message.media.webpage.document); |
|
|
|
|
if(!media) { |
|
|
|
|
//this.log('no media!', message);
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(media._ == 'document' && media.type != 'video'/* && media.type != 'gif' */) { |
|
|
|
|
//this.log('broken video', media);
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
//console.log(message, photo);
|
|
|
|
|
|
|
|
|
|
let isPhoto = media._ == 'photo'; |
|
|
|
|
|
|
|
|
|
let photo = isPhoto ? appPhotosManager.getPhoto(media.id) : null; |
|
|
|
|
if(!photo || !photo.downloaded) { |
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media, photo, div);
|
|
|
|
|
|
|
|
|
|
let sizes = media.sizes || media.thumbs; |
|
|
|
|
if(sizes && sizes[0].bytes) { |
|
|
|
|
appPhotosManager.setAttachmentPreview(sizes[0].bytes, div, false, true); |
|
|
|
|
} /* else { |
|
|
|
|
this.log('no stripped size', message, media); |
|
|
|
|
} */ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media);
|
|
|
|
|
|
|
|
|
|
let load = () => appPhotosManager.preloadPhoto(isPhoto ? media.id : media, appPhotosManager.choosePhotoSize(media, 200, 200)) |
|
|
|
|
.then((blob) => { |
|
|
|
|
if($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
|
|
|
|
|
let img = new Image(); |
|
|
|
|
img.src = url; |
|
|
|
|
img.onload = () => { |
|
|
|
|
div.style.backgroundImage = 'url(' + url + ')'; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//div.style.backgroundImage = 'url(' + url + ')';
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
div.dataset.mid = '' + message.mid; |
|
|
|
|
|
|
|
|
|
if(photo && photo.downloaded) load(); |
|
|
|
|
else this.lazyLoadQueueSidebar.push({div, load}); |
|
|
|
|
|
|
|
|
|
this.lastSharedMediaDiv.append(div); |
|
|
|
|
if(this.lastSharedMediaDiv.childElementCount == 3) { |
|
|
|
|
if(!this.scroll.contains(this.lastSharedMediaDiv)) { |
|
|
|
|
elemsToAppend.push(this.lastSharedMediaDiv); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.lastSharedMediaDiv = document.createElement('div'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.mediaDivsByIDs[message.mid] = div; |
|
|
|
|
|
|
|
|
|
//sharedMediaDiv.append(div);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'inputMessagesFilterDocument': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentDocuments; |
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
if(!message.media.document || message.media.document.type == 'voice') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let doc = message.media.document; |
|
|
|
|
if(doc.attributes) { |
|
|
|
|
if(doc.attributes.find((a: any) => a._ == "documentAttributeSticker")) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('come back down to my knees', message);
|
|
|
|
|
|
|
|
|
|
let div = wrapDocument(message.media.document, true); |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'inputMessagesFilterUrl': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentLinks; |
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
if(!message.media.webpage || message.media.webpage._ == 'webPageEmpty') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let webpage = message.media.webpage; |
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
|
|
|
|
|
let previewDiv = document.createElement('div'); |
|
|
|
|
previewDiv.classList.add('preview'); |
|
|
|
|
|
|
|
|
|
//this.log('wrapping webpage', webpage);
|
|
|
|
|
|
|
|
|
|
if(webpage.photo) { |
|
|
|
|
let load = () => appPhotosManager.preloadPhoto(webpage.photo.id, appPhotosManager.choosePhotoSize(webpage.photo, 380, 0)) |
|
|
|
|
.then((blob) => { |
|
|
|
|
if($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
|
|
|
|
|
previewDiv.style.backgroundImage = 'url(' + url + ')'; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.lazyLoadQueueSidebar.push({div: previewDiv, load}); |
|
|
|
|
} else { |
|
|
|
|
previewDiv.innerText = (webpage.title || webpage.description || webpage.url || webpage.display_url).slice(0, 1); |
|
|
|
|
previewDiv.classList.add('empty'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let title = webpage.rTitle || ''; |
|
|
|
|
let subtitle = webpage.rDescription || ''; |
|
|
|
|
let url = RichTextProcessor.wrapRichText(webpage.url || ''); |
|
|
|
|
|
|
|
|
|
if(!title) { |
|
|
|
|
//title = new URL(webpage.url).hostname;
|
|
|
|
|
title = webpage.display_url.split('/', 1)[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
div.append(previewDiv); |
|
|
|
|
div.insertAdjacentHTML('beforeend', ` |
|
|
|
|
<div class="title">${title}</div> |
|
|
|
|
<div class="subtitle">${subtitle}</div> |
|
|
|
|
<div class="url">${url}</div> |
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
if(div.innerText.trim().length) { |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* case 'inputMessagesFilterVoice': { |
|
|
|
|
//this.log('wrapping audio', message.media);
|
|
|
|
|
if(!message.media || !message.media.document || message.media.document.type != 'voice') { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let doc = message.media.document; |
|
|
|
|
|
|
|
|
|
this.log('wrapping audio', doc); |
|
|
|
|
|
|
|
|
|
let audioDiv = wrapAudio(doc); |
|
|
|
|
|
|
|
|
|
this.sharedMedia.contentAudio.append(audioDiv); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
//console.warn('death is my friend', message);
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(this.lastSharedMediaDiv.childElementCount && !this.scroll.contains(this.lastSharedMediaDiv)) { |
|
|
|
|
elemsToAppend.push(this.lastSharedMediaDiv); |
|
|
|
|
if(this.cleared[type]) { |
|
|
|
|
//ids = history;
|
|
|
|
|
delete this.cleared[type]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(elemsToAppend.length) { |
|
|
|
|
//window.requestAnimationFrame(() => {
|
|
|
|
|
elemsToAppend.forEach(el => this.scroll.append(el)); |
|
|
|
|
//});
|
|
|
|
|
if(ids.length) { |
|
|
|
|
this.performSearchResult(ids, type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(sharedMediaDiv) { |
|
|
|
|
let parent = sharedMediaDiv.parentElement; |
|
|
|
|
if(parent.lastElementChild.classList.contains('preloader')) { |
|
|
|
|
parent.lastElementChild.remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.onSidebarScroll(); |
|
|
|
|
}).then(() => { |
|
|
|
|
this.loadSidebarMediaPromises[type] = null; |
|
|
|
|
}, (err) => { |
|
|
|
|
this.log.error('load error:', err); |
|
|
|
|
}).then(() => { |
|
|
|
|
this.loadSidebarMediaPromises[type] = null; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
@ -491,7 +511,7 @@ class AppSidebarRight {
@@ -491,7 +511,7 @@ class AppSidebarRight {
|
|
|
|
|
this.lastSharedMediaDiv = document.createElement('div'); |
|
|
|
|
|
|
|
|
|
//this.log('fillProfileElements');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.requestAnimationFrame(() => { |
|
|
|
|
this.profileContentEl.parentElement.scrollTop = 0; |
|
|
|
|
this.profileElements.bio.style.display = 'none'; |
|
|
|
@ -500,7 +520,7 @@ class AppSidebarRight {
@@ -500,7 +520,7 @@ class AppSidebarRight {
|
|
|
|
|
this.profileElements.notificationsRow.style.display = ''; |
|
|
|
|
this.profileElements.notificationsCheckbox.checked = true; |
|
|
|
|
this.profileElements.notificationsStatus.innerText = 'Enabled'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(this.sharedMedia).forEach(key => { |
|
|
|
|
this.sharedMedia[key].innerHTML = ''; |
|
|
|
|
|
|
|
|
@ -509,12 +529,14 @@ class AppSidebarRight {
@@ -509,12 +529,14 @@ class AppSidebarRight {
|
|
|
|
|
putPreloader(parent, true); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.savedVirtualStates = {}; |
|
|
|
|
this.prevTabID = -1; |
|
|
|
|
this.scroll.setVirtualContainer(null); |
|
|
|
|
(this.profileTabs.children[1] as HTMLLIElement).click(); // set media
|
|
|
|
|
|
|
|
|
|
//this.scroll.getScrollTopOffset();
|
|
|
|
|
|
|
|
|
|
this.loadSidebarMedia(true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -530,6 +552,7 @@ class AppSidebarRight {
@@ -530,6 +552,7 @@ class AppSidebarRight {
|
|
|
|
|
this.sharedMediaTypes.forEach(type => { |
|
|
|
|
//this.minMediaID[type] = 0;
|
|
|
|
|
this.cleared[type] = true; |
|
|
|
|
this.usedFromHistory[type] = 0; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
let setText = (text: string, el: HTMLDivElement) => { |
|
|
|
@ -537,12 +560,14 @@ class AppSidebarRight {
@@ -537,12 +560,14 @@ class AppSidebarRight {
|
|
|
|
|
if(el.childElementCount > 1) { |
|
|
|
|
el.firstElementChild.remove(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let p = document.createElement('p'); |
|
|
|
|
p.innerHTML = text; |
|
|
|
|
el.prepend(p); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
el.style.display = ''; |
|
|
|
|
|
|
|
|
|
//this.scroll.getScrollTopOffset();
|
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -564,7 +589,10 @@ class AppSidebarRight {
@@ -564,7 +589,10 @@ class AppSidebarRight {
|
|
|
|
|
appImManager.setMutedState(muted); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.profileElements.notificationsRow.style.display = 'none'; |
|
|
|
|
window.requestAnimationFrame(() => { |
|
|
|
|
this.profileElements.notificationsRow.style.display = 'none'; |
|
|
|
|
//this.scroll.getScrollTopOffset();
|
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(peerID > 0) { |
|
|
|
@ -590,7 +618,7 @@ class AppSidebarRight {
@@ -590,7 +618,7 @@ class AppSidebarRight {
|
|
|
|
|
appMessagesManager.wrapSingleMessage(userFull.pinned_msg_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.scroll.getScrollTopOffset(); |
|
|
|
|
//this.scroll.getScrollTopOffset();
|
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
let chat = appPeersManager.getPeer(peerID); |
|
|
|
@ -607,11 +635,11 @@ class AppSidebarRight {
@@ -607,11 +635,11 @@ class AppSidebarRight {
|
|
|
|
|
setText(RichTextProcessor.wrapRichText(chatFull.about), this.profileElements.bio); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.scroll.getScrollTopOffset(); |
|
|
|
|
//this.scroll.getScrollTopOffset();
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.scroll.getScrollTopOffset(); |
|
|
|
|
//this.scroll.getScrollTopOffset();
|
|
|
|
|
//this.loadSidebarMedia();
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|