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