|
|
|
@ -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,62 +199,9 @@ class AppSidebarRight {
@@ -201,62 +199,9 @@ class AppSidebarRight {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public loadSidebarMedia(single = false) { |
|
|
|
|
if(testScroll/* || 1 == 1 */) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.log('loadSidebarMedia', single, this.peerID);
|
|
|
|
|
|
|
|
|
|
public performSearchResult(ids: number[], type: string) { |
|
|
|
|
let peerID = this.peerID; |
|
|
|
|
|
|
|
|
|
let typesToLoad = single ? [this.sharedMediaType] : this.sharedMediaTypes; |
|
|
|
|
typesToLoad = typesToLoad.filter(type => !this.loadedAllMedia[type]); |
|
|
|
|
if(!typesToLoad.length) return; |
|
|
|
|
|
|
|
|
|
if(!this.historiesStorage[peerID]) this.historiesStorage[peerID] = {}; |
|
|
|
|
let historyStorage = 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 maxID = this.minMediaID[type] || 0;
|
|
|
|
|
let maxID = history[history.length - 1] || 0; |
|
|
|
|
|
|
|
|
|
let ids = !maxID && appMessagesManager.historiesStorage[peerID] |
|
|
|
|
? appMessagesManager.historiesStorage[peerID].history.slice() : []; |
|
|
|
|
|
|
|
|
|
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(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) { |
|
|
|
@ -313,6 +258,9 @@ class AppSidebarRight {
@@ -313,6 +258,9 @@ class AppSidebarRight {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(photo && photo.url) { |
|
|
|
|
renderImageFromUrl(div, photo.url); |
|
|
|
|
} else { |
|
|
|
|
let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
|
|
|
|
@ -321,6 +269,7 @@ class AppSidebarRight {
@@ -321,6 +269,7 @@ class AppSidebarRight {
|
|
|
|
|
img.onload = () => { |
|
|
|
|
div.style.backgroundImage = 'url(' + url + ')'; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//div.style.backgroundImage = 'url(' + url + ')';
|
|
|
|
|
}); |
|
|
|
@ -394,10 +343,12 @@ class AppSidebarRight {
@@ -394,10 +343,12 @@ class AppSidebarRight {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let url = URL.createObjectURL(blob); |
|
|
|
|
renderImageFromUrl(previewDiv, webpage.photo.url); |
|
|
|
|
|
|
|
|
|
/* let url = URL.createObjectURL(blob); |
|
|
|
|
this.urlsToRevoke.push(url); |
|
|
|
|
|
|
|
|
|
previewDiv.style.backgroundImage = 'url(' + url + ')'; |
|
|
|
|
previewDiv.style.backgroundImage = 'url(' + url + ')'; */ |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.lazyLoadQueueSidebar.push({div: previewDiv, load}); |
|
|
|
@ -471,10 +422,79 @@ class AppSidebarRight {
@@ -471,10 +422,79 @@ class AppSidebarRight {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.onSidebarScroll(); |
|
|
|
|
}).then(() => { |
|
|
|
|
this.loadSidebarMediaPromises[type] = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public loadSidebarMedia(single = false) { |
|
|
|
|
if(testScroll/* || 1 == 1 */) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.log('loadSidebarMedia', single, this.peerID); |
|
|
|
|
|
|
|
|
|
let peerID = this.peerID; |
|
|
|
|
|
|
|
|
|
let typesToLoad = single ? [this.sharedMediaType] : this.sharedMediaTypes; |
|
|
|
|
typesToLoad = typesToLoad.filter(type => !this.loadedAllMedia[type]); |
|
|
|
|
if(!typesToLoad.length) return; |
|
|
|
|
|
|
|
|
|
let historyStorage = this.historiesStorage[peerID] ?? (this.historiesStorage[peerID] = {}); |
|
|
|
|
|
|
|
|
|
this.scroll.lock(); |
|
|
|
|
|
|
|
|
|
let promises = typesToLoad.map(type => { |
|
|
|
|
if(this.loadSidebarMediaPromises[type]) return this.loadSidebarMediaPromises[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;
|
|
|
|
|
let maxID = history[history.length - 1] || 0; |
|
|
|
|
|
|
|
|
|
let ids = !maxID && appMessagesManager.historiesStorage[peerID] |
|
|
|
|
? appMessagesManager.historiesStorage[peerID].history.slice() : []; |
|
|
|
|
|
|
|
|
|
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($rootScope.selectedPeerID != peerID) { |
|
|
|
|
this.log.warn('peer changed'); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(value.history.length < loadCount) { |
|
|
|
|
this.loadedAllMedia[type] = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(this.cleared[type]) { |
|
|
|
|
//ids = history;
|
|
|
|
|
delete this.cleared[type]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
|
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();
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|