|
|
|
@ -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'); |
|
|
|
|
|
|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -145,8 +148,7 @@ class AppSidebarRight {
@@ -145,8 +148,7 @@ class AppSidebarRight {
|
|
|
|
|
|
|
|
|
|
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,280 +199,302 @@ class AppSidebarRight {
@@ -201,280 +199,302 @@ class AppSidebarRight {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public loadSidebarMedia(single = false) { |
|
|
|
|
if(testScroll/* || 1 == 1 */) { |
|
|
|
|
return; |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//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; |
|
|
|
|
typesToLoad = typesToLoad.filter(type => !this.loadedAllMedia[type]); |
|
|
|
|
if(!typesToLoad.length) return; |
|
|
|
|
if(media._ == 'document' && media.type != 'video'/* && media.type != 'gif' */) { |
|
|
|
|
//this.log('broken video', media);
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!this.historiesStorage[peerID]) this.historiesStorage[peerID] = {}; |
|
|
|
|
let historyStorage = this.historiesStorage[peerID]; |
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
//console.log(message, photo);
|
|
|
|
|
|
|
|
|
|
this.scroll.lock(); |
|
|
|
|
let isPhoto = media._ == 'photo'; |
|
|
|
|
|
|
|
|
|
let promises = typesToLoad.map(type => { |
|
|
|
|
if(this.loadSidebarMediaPromises[type]) return this.loadSidebarMediaPromises[type]; |
|
|
|
|
let photo = isPhoto ? appPhotosManager.getPhoto(media.id) : null; |
|
|
|
|
if(!photo || !photo.downloaded) { |
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media, photo, div);
|
|
|
|
|
|
|
|
|
|
if(!historyStorage[type]) historyStorage[type] = []; |
|
|
|
|
let history = historyStorage[type]; |
|
|
|
|
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); |
|
|
|
|
} */ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// заливать новую картинку сюда только после полной отправки!
|
|
|
|
|
//let maxID = this.minMediaID[type] || 0;
|
|
|
|
|
let maxID = history[history.length - 1] || 0; |
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media);
|
|
|
|
|
|
|
|
|
|
let ids = !maxID && appMessagesManager.historiesStorage[peerID] |
|
|
|
|
? appMessagesManager.historiesStorage[peerID].history.slice() : []; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
maxID = !maxID && ids.length ? ids[ids.length - 1] : maxID; |
|
|
|
|
//this.log('search house of glass pre', type, ids, maxID);
|
|
|
|
|
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 + ')'; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
//div.style.backgroundImage = 'url(' + url + ')';
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.log('search house of glass', type, value, ids, this.cleared); |
|
|
|
|
div.dataset.mid = '' + message.mid; |
|
|
|
|
|
|
|
|
|
if(value.history.length < loadCount) { |
|
|
|
|
this.loadedAllMedia[type] = true; |
|
|
|
|
} |
|
|
|
|
if(photo && photo.downloaded) load(); |
|
|
|
|
else this.lazyLoadQueueSidebar.push({div, load}); |
|
|
|
|
|
|
|
|
|
if($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.lastSharedMediaDiv.append(div); |
|
|
|
|
if(this.lastSharedMediaDiv.childElementCount == 3) { |
|
|
|
|
if(!this.scroll.contains(this.lastSharedMediaDiv)) { |
|
|
|
|
elemsToAppend.push(this.lastSharedMediaDiv); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(this.cleared[type]) { |
|
|
|
|
ids = history; |
|
|
|
|
delete this.cleared[type]; |
|
|
|
|
} |
|
|
|
|
this.lastSharedMediaDiv = document.createElement('div'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.mediaDivsByIDs[message.mid] = div; |
|
|
|
|
|
|
|
|
|
let sharedMediaDiv: HTMLDivElement; |
|
|
|
|
let messages: any[] = []; |
|
|
|
|
for(let mid of ids) { |
|
|
|
|
let message = appMessagesManager.getMessage(mid); |
|
|
|
|
if(message.media) messages.push(message); |
|
|
|
|
//sharedMediaDiv.append(div);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(media._ == 'document' && media.type != 'video'/* && media.type != 'gif' */) { |
|
|
|
|
//this.log('broken video', media);
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
case 'inputMessagesFilterDocument': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentDocuments; |
|
|
|
|
|
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
//console.log(message, photo);
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
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; |
|
|
|
|
if(!photo || !photo.downloaded) { |
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media, photo, div);
|
|
|
|
|
//this.log('come back down to my knees', message);
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} */ |
|
|
|
|
} |
|
|
|
|
let div = wrapDocument(message.media.document, true); |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('inputMessagesFilterPhotoVideo', message, media);
|
|
|
|
|
case 'inputMessagesFilterUrl': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentLinks; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
for(let message of messages) { |
|
|
|
|
if(!message.media.webpage || message.media.webpage._ == 'webPageEmpty') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
let webpage = message.media.webpage; |
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
|
|
|
|
|
let img = new Image(); |
|
|
|
|
img.src = url; |
|
|
|
|
img.onload = () => { |
|
|
|
|
div.style.backgroundImage = 'url(' + url + ')'; |
|
|
|
|
}; |
|
|
|
|
let previewDiv = document.createElement('div'); |
|
|
|
|
previewDiv.classList.add('preview'); |
|
|
|
|
|
|
|
|
|
//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(); |
|
|
|
|
else this.lazyLoadQueueSidebar.push({div, load}); |
|
|
|
|
renderImageFromUrl(previewDiv, webpage.photo.url); |
|
|
|
|
|
|
|
|
|
this.lastSharedMediaDiv.append(div); |
|
|
|
|
if(this.lastSharedMediaDiv.childElementCount == 3) { |
|
|
|
|
if(!this.scroll.contains(this.lastSharedMediaDiv)) { |
|
|
|
|
elemsToAppend.push(this.lastSharedMediaDiv); |
|
|
|
|
} |
|
|
|
|
/* let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
|
|
|
|
|
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': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentDocuments; |
|
|
|
|
div.append(previewDiv); |
|
|
|
|
div.insertAdjacentHTML('beforeend', ` |
|
|
|
|
<div class="title">${title}</div> |
|
|
|
|
<div class="subtitle">${subtitle}</div> |
|
|
|
|
<div class="url">${url}</div> |
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
if(!message.media.document || message.media.document.type == 'voice') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if(div.innerText.trim().length) { |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
/* case 'inputMessagesFilterVoice': { |
|
|
|
|
//this.log('wrapping audio', message.media);
|
|
|
|
|
if(!message.media || !message.media.document || message.media.document.type != 'voice') { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'inputMessagesFilterUrl': { |
|
|
|
|
sharedMediaDiv = this.sharedMedia.contentLinks; |
|
|
|
|
let doc = message.media.document; |
|
|
|
|
|
|
|
|
|
for(let message of messages) { |
|
|
|
|
if(!message.media.webpage || message.media.webpage._ == 'webPageEmpty') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
this.log('wrapping audio', doc); |
|
|
|
|
|
|
|
|
|
let webpage = message.media.webpage; |
|
|
|
|
let div = document.createElement('div'); |
|
|
|
|
let audioDiv = wrapAudio(doc); |
|
|
|
|
|
|
|
|
|
let previewDiv = document.createElement('div'); |
|
|
|
|
previewDiv.classList.add('preview'); |
|
|
|
|
this.sharedMedia.contentAudio.append(audioDiv); |
|
|
|
|
|
|
|
|
|
//this.log('wrapping webpage', webpage);
|
|
|
|
|
break; |
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
//console.warn('death is my friend', message);
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
if(this.lastSharedMediaDiv.childElementCount && !this.scroll.contains(this.lastSharedMediaDiv)) { |
|
|
|
|
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}); |
|
|
|
|
} else { |
|
|
|
|
previewDiv.innerText = (webpage.title || webpage.description || webpage.url || webpage.display_url).slice(0, 1); |
|
|
|
|
previewDiv.classList.add('empty'); |
|
|
|
|
} |
|
|
|
|
if(sharedMediaDiv) { |
|
|
|
|
let parent = sharedMediaDiv.parentElement; |
|
|
|
|
if(parent.lastElementChild.classList.contains('preloader')) { |
|
|
|
|
parent.lastElementChild.remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let title = webpage.rTitle || ''; |
|
|
|
|
let subtitle = webpage.rDescription || ''; |
|
|
|
|
let url = RichTextProcessor.wrapRichText(webpage.url || ''); |
|
|
|
|
this.onSidebarScroll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!title) { |
|
|
|
|
//title = new URL(webpage.url).hostname;
|
|
|
|
|
title = webpage.display_url.split('/', 1)[0]; |
|
|
|
|
} |
|
|
|
|
public loadSidebarMedia(single = false) { |
|
|
|
|
if(testScroll/* || 1 == 1 */) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
div.append(previewDiv); |
|
|
|
|
div.insertAdjacentHTML('beforeend', ` |
|
|
|
|
<div class="title">${title}</div> |
|
|
|
|
<div class="subtitle">${subtitle}</div> |
|
|
|
|
<div class="url">${url}</div> |
|
|
|
|
`);
|
|
|
|
|
this.log('loadSidebarMedia', single, this.peerID); |
|
|
|
|
|
|
|
|
|
if(div.innerText.trim().length) { |
|
|
|
|
elemsToAppend.push(div); |
|
|
|
|
} |
|
|
|
|
let peerID = this.peerID; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
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.log('wrapping audio', message.media);
|
|
|
|
|
if(!message.media || !message.media.document || message.media.document.type != 'voice') { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
this.scroll.lock(); |
|
|
|
|
|
|
|
|
|
let promises = typesToLoad.map(type => { |
|
|
|
|
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: |
|
|
|
|
//console.warn('death is my friend', message);
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
maxID = !maxID && ids.length ? ids[ids.length - 1] : maxID; |
|
|
|
|
this.log('search house of glass pre', type, ids, maxID); |
|
|
|
|
|
|
|
|
|
//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)) { |
|
|
|
|
elemsToAppend.push(this.lastSharedMediaDiv); |
|
|
|
|
if($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(elemsToAppend.length) { |
|
|
|
|
//window.requestAnimationFrame(() => {
|
|
|
|
|
elemsToAppend.forEach(el => this.scroll.append(el)); |
|
|
|
|
//});
|
|
|
|
|
if(value.history.length < loadCount) { |
|
|
|
|
this.loadedAllMedia[type] = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(sharedMediaDiv) { |
|
|
|
|
let parent = sharedMediaDiv.parentElement; |
|
|
|
|
if(parent.lastElementChild.classList.contains('preloader')) { |
|
|
|
|
parent.lastElementChild.remove(); |
|
|
|
|
} |
|
|
|
|
if(this.cleared[type]) { |
|
|
|
|
//ids = history;
|
|
|
|
|
delete this.cleared[type]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.onSidebarScroll(); |
|
|
|
|
}).then(() => { |
|
|
|
|
this.loadSidebarMediaPromises[type] = null; |
|
|
|
|
if(ids.length) { |
|
|
|
|
this.performSearchResult(ids, type); |
|
|
|
|
} |
|
|
|
|
}, (err) => { |
|
|
|
|
this.log.error('load error:', err); |
|
|
|
|
}).then(() => { |
|
|
|
|
this.loadSidebarMediaPromises[type] = null; |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
@ -515,6 +535,8 @@ class AppSidebarRight {
@@ -515,6 +535,8 @@ class AppSidebarRight {
|
|
|
|
|
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) => { |
|
|
|
@ -543,6 +566,8 @@ class AppSidebarRight {
@@ -543,6 +566,8 @@ class AppSidebarRight {
|
|
|
|
|
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();
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|