|
|
@ -1,10 +1,9 @@ |
|
|
|
import { logger } from "../polyfill"; |
|
|
|
import { logger } from "../polyfill"; |
|
|
|
import { scrollable } from "../../components/misc"; |
|
|
|
import { scrollable, putPreloader } from "../../components/misc"; |
|
|
|
import appMessagesManager from "./appMessagesManager"; |
|
|
|
import appMessagesManager from "./appMessagesManager"; |
|
|
|
import appDialogsManager from "./appDialogsManager"; |
|
|
|
import appDialogsManager from "./appDialogsManager"; |
|
|
|
import { isElementInViewport, $rootScope } from "../utils"; |
|
|
|
import { isElementInViewport } from "../utils"; |
|
|
|
import appMessagesIDsManager from "./appMessagesIDsManager"; |
|
|
|
import appMessagesIDsManager from "./appMessagesIDsManager"; |
|
|
|
import apiManager from '../mtproto/apiManager'; |
|
|
|
|
|
|
|
import appImManager from "./appImManager"; |
|
|
|
import appImManager from "./appImManager"; |
|
|
|
|
|
|
|
|
|
|
|
class AppSidebarLeft { |
|
|
|
class AppSidebarLeft { |
|
|
@ -19,6 +18,15 @@ class AppSidebarLeft { |
|
|
|
private listsContainer: HTMLDivElement = null; |
|
|
|
private listsContainer: HTMLDivElement = null; |
|
|
|
private searchMessagesList: HTMLUListElement = null; |
|
|
|
private searchMessagesList: HTMLUListElement = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private chatsContainer = document.getElementById('chats-container') as HTMLDivElement; |
|
|
|
|
|
|
|
private chatsOffsetIndex = 0; |
|
|
|
|
|
|
|
private chatsScroll: HTMLDivElement; |
|
|
|
|
|
|
|
private chatsHidden: any; |
|
|
|
|
|
|
|
private chatsPreloader: HTMLDivElement; |
|
|
|
|
|
|
|
private chatsLoadCount = 0; |
|
|
|
|
|
|
|
private loadDialogsPromise: Promise<any>; |
|
|
|
|
|
|
|
private hiddenScroll: any; |
|
|
|
|
|
|
|
|
|
|
|
private log = logger('SL'); |
|
|
|
private log = logger('SL'); |
|
|
|
|
|
|
|
|
|
|
|
private peerID = 0; |
|
|
|
private peerID = 0; |
|
|
@ -32,28 +40,40 @@ class AppSidebarLeft { |
|
|
|
|
|
|
|
|
|
|
|
private query = ''; |
|
|
|
private query = ''; |
|
|
|
|
|
|
|
|
|
|
|
public myID = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
this.listsContainer = scrollable(this.searchContainer); |
|
|
|
this.chatsPreloader = document.createElement('div'); |
|
|
|
this.searchMessagesList = document.createElement('ul'); |
|
|
|
this.chatsPreloader.classList.add('preloader'); |
|
|
|
|
|
|
|
putPreloader(this.chatsPreloader); |
|
|
|
|
|
|
|
this.chatsContainer.append(this.chatsPreloader); |
|
|
|
|
|
|
|
|
|
|
|
apiManager.getUserID().then((id) => { |
|
|
|
this.chatsLoadCount = Math.round(document.body.scrollHeight / 70 * 1.5); |
|
|
|
this.myID = id; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$on('user_auth', (e: CustomEvent) => { |
|
|
|
let {container: chatsScroll, hiddenElements: chatsHidden, onScroll: hiddenScroll} = scrollable(this.chatsContainer as HTMLDivElement); |
|
|
|
let userAuth = e.detail; |
|
|
|
this.chatsScroll = chatsScroll; |
|
|
|
this.myID = userAuth ? userAuth.id : 0; |
|
|
|
this.chatsHidden = chatsHidden; |
|
|
|
}); |
|
|
|
this.hiddenScroll = hiddenScroll; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appDialogsManager.chatsHidden = this.chatsHidden; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chatsScroll.addEventListener('scroll', this.onChatsScroll.bind(this)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.listsContainer = scrollable(this.searchContainer).container; |
|
|
|
|
|
|
|
this.searchMessagesList = document.createElement('ul'); |
|
|
|
|
|
|
|
|
|
|
|
this.savedBtn.addEventListener('click', () => { |
|
|
|
this.savedBtn.addEventListener('click', () => { |
|
|
|
appImManager.setPeer(this.myID); |
|
|
|
appImManager.setPeer(appImManager.myID); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* this.listsContainer.insertBefore(this.searchMessagesList, this.listsContainer.lastElementChild); |
|
|
|
|
|
|
|
for(let i = 0; i < 25; ++i) { |
|
|
|
|
|
|
|
let li = document.createElement('li'); |
|
|
|
|
|
|
|
li.innerHTML = `<div class="user-avatar is-online" style="font-size: 0px;"><img src="assets/img/camomile.jpg"></div><div class="user-caption"><p><span class="user-title">Влад</span><span><span class="message-status"></span><span class="message-time">14:41</span></span></p><p><span class="user-last-message">это важно</span><span class="tgico-pinnedchat"></span></p></div><div class="c-ripple"><span class="c-ripple__circle" style="top: 65px; left: 338.5px;"></span></div>`; |
|
|
|
|
|
|
|
this.searchMessagesList.append(li); |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
this.listsContainer.addEventListener('scroll', this.onSidebarScroll.bind(this)); |
|
|
|
this.listsContainer.addEventListener('scroll', this.onSidebarScroll.bind(this)); |
|
|
|
|
|
|
|
|
|
|
|
this.searchContainer.append(this.listsContainer); |
|
|
|
//this.searchContainer.append(this.listsContainer);
|
|
|
|
|
|
|
|
|
|
|
|
appDialogsManager.setListClickListener(this.searchMessagesList); |
|
|
|
appDialogsManager.setListClickListener(this.searchMessagesList); |
|
|
|
|
|
|
|
|
|
|
@ -85,7 +105,7 @@ class AppSidebarLeft { |
|
|
|
this.log('input', value); |
|
|
|
this.log('input', value); |
|
|
|
|
|
|
|
|
|
|
|
if(this.listsContainer.contains(this.searchMessagesList)) { |
|
|
|
if(this.listsContainer.contains(this.searchMessagesList)) { |
|
|
|
this.listsContainer.removeChild(this.searchMessagesList) |
|
|
|
this.listsContainer.removeChild(this.searchMessagesList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!value.trim()) { |
|
|
|
if(!value.trim()) { |
|
|
@ -115,11 +135,63 @@ class AppSidebarLeft { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', () => { |
|
|
|
window.addEventListener('resize', () => { |
|
|
|
setTimeout(() => this.onSidebarScroll(), 0); |
|
|
|
this.chatsLoadCount = Math.round(document.body.scrollHeight / 70 * 1.5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
this.onSidebarScroll(); |
|
|
|
|
|
|
|
this.onChatsScroll(); |
|
|
|
|
|
|
|
}, 0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async loadDialogs() { |
|
|
|
|
|
|
|
if(this.loadDialogsPromise/* || 1 == 1 */) return this.loadDialogsPromise; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chatsContainer.append(this.chatsPreloader); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//let offset = appMessagesManager.generateDialogIndex();/* appMessagesManager.dialogsNum */;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
this.loadDialogsPromise = appMessagesManager.getConversations('', this.chatsOffsetIndex, this.chatsLoadCount); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let result = await this.loadDialogsPromise; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(result && result.dialogs && result.dialogs.length) { |
|
|
|
|
|
|
|
this.chatsOffsetIndex = result.dialogs[result.dialogs.length - 1].index; |
|
|
|
|
|
|
|
result.dialogs.forEach((dialog: any) => { |
|
|
|
|
|
|
|
appDialogsManager.addDialog(dialog); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.log('loaded ' + this.chatsLoadCount + ' dialogs by offset:', this.chatsOffsetIndex, result, this.chatsHidden); |
|
|
|
|
|
|
|
this.hiddenScroll(); |
|
|
|
|
|
|
|
} catch(err) { |
|
|
|
|
|
|
|
this.log.error(err); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.chatsPreloader.remove(); |
|
|
|
|
|
|
|
this.loadDialogsPromise = undefined; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public onChatsScroll() { |
|
|
|
|
|
|
|
if(this.chatsHidden.down.length > 0/* || 1 == 1 */) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!this.loadDialogsPromise) { |
|
|
|
|
|
|
|
let d = Array.from(appDialogsManager.chatList.childNodes).slice(-5); |
|
|
|
|
|
|
|
for(let node of d) { |
|
|
|
|
|
|
|
if(isElementInViewport(node)) { |
|
|
|
|
|
|
|
this.loadDialogs(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log('last 5 dialogs:', d);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public onSidebarScroll() { |
|
|
|
public onSidebarScroll() { |
|
|
|
|
|
|
|
if(!this.query.trim()) return; |
|
|
|
|
|
|
|
|
|
|
|
let elements = Array.from(this.searchMessagesList.childNodes).slice(-5); |
|
|
|
let elements = Array.from(this.searchMessagesList.childNodes).slice(-5); |
|
|
|
for(let li of elements) { |
|
|
|
for(let li of elements) { |
|
|
|
if(isElementInViewport(li)) { |
|
|
|
if(isElementInViewport(li)) { |
|
|
@ -150,6 +222,8 @@ class AppSidebarLeft { |
|
|
|
|
|
|
|
|
|
|
|
let query = this.query; |
|
|
|
let query = this.query; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!query.trim()) return; |
|
|
|
|
|
|
|
|
|
|
|
if(this.loadedCount != 0 && this.loadedCount >= this.foundCount) { |
|
|
|
if(this.loadedCount != 0 && this.loadedCount >= this.foundCount) { |
|
|
|
return Promise.resolve(); |
|
|
|
return Promise.resolve(); |
|
|
|
} |
|
|
|
} |
|
|
|