|
|
@ -108,7 +108,9 @@ export class AppDialogsManager { |
|
|
|
private lastActiveElements: Set<HTMLElement> = new Set(); |
|
|
|
private lastActiveElements: Set<HTMLElement> = new Set(); |
|
|
|
|
|
|
|
|
|
|
|
private offsets: {top: number, bottom: number} = {top: 0, bottom: 0}; |
|
|
|
private offsets: {top: number, bottom: number} = {top: 0, bottom: 0}; |
|
|
|
loadContacts: () => void; |
|
|
|
|
|
|
|
|
|
|
|
private loadContacts: () => void; |
|
|
|
|
|
|
|
private processContact: (peerId: number) => void; |
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
this.chatsPreloader = putPreloader(null, true); |
|
|
|
this.chatsPreloader = putPreloader(null, true); |
|
|
@ -190,8 +192,7 @@ export class AppDialogsManager { |
|
|
|
this.setFiltersUnreadCount(); |
|
|
|
this.setFiltersUnreadCount(); |
|
|
|
}); */ |
|
|
|
}); */ |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('dialog_flush', (e) => { |
|
|
|
rootScope.addEventListener('dialog_flush', ({peerId}) => { |
|
|
|
const peerId: number = e.peerId; |
|
|
|
|
|
|
|
const dialog = appMessagesManager.getDialogOnly(peerId); |
|
|
|
const dialog = appMessagesManager.getDialogOnly(peerId); |
|
|
|
if(dialog) { |
|
|
|
if(dialog) { |
|
|
|
this.setLastMessage(dialog); |
|
|
|
this.setLastMessage(dialog); |
|
|
@ -200,29 +201,31 @@ export class AppDialogsManager { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('dialogs_multiupdate', (e) => { |
|
|
|
rootScope.addEventListener('dialogs_multiupdate', (dialogs) => { |
|
|
|
const dialogs = e; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(const id in dialogs) { |
|
|
|
for(const id in dialogs) { |
|
|
|
const dialog = dialogs[id]; |
|
|
|
const dialog = dialogs[id]; |
|
|
|
this.updateDialog(dialog); |
|
|
|
this.updateDialog(dialog); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.processContact) { |
|
|
|
|
|
|
|
this.processContact(+id); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.validateForFilter(); |
|
|
|
this.validateForFilter(); |
|
|
|
this.setFiltersUnreadCount(); |
|
|
|
this.setFiltersUnreadCount(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('dialog_drop', (e) => { |
|
|
|
rootScope.addEventListener('dialog_drop', ({peerId}) => { |
|
|
|
const {peerId} = e; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.deleteDialog(peerId); |
|
|
|
this.deleteDialog(peerId); |
|
|
|
this.setFiltersUnreadCount(); |
|
|
|
this.setFiltersUnreadCount(); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('dialog_unread', (e) => { |
|
|
|
if(this.processContact) { |
|
|
|
const info = e; |
|
|
|
this.processContact(peerId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const dialog = appMessagesManager.getDialogOnly(info.peerId); |
|
|
|
rootScope.addEventListener('dialog_unread', ({peerId}) => { |
|
|
|
|
|
|
|
const dialog = appMessagesManager.getDialogOnly(peerId); |
|
|
|
if(dialog) { |
|
|
|
if(dialog) { |
|
|
|
this.setUnreadMessages(dialog); |
|
|
|
this.setUnreadMessages(dialog); |
|
|
|
this.validateForFilter(); |
|
|
|
this.validateForFilter(); |
|
|
@ -234,16 +237,18 @@ export class AppDialogsManager { |
|
|
|
this.setUnreadMessages(dialog); // возможно это не нужно, но нужно менять is-muted
|
|
|
|
this.setUnreadMessages(dialog); // возможно это не нужно, но нужно менять is-muted
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('dialog_draft', (e) => { |
|
|
|
rootScope.addEventListener('dialog_draft', ({peerId}) => { |
|
|
|
const dialog = appMessagesManager.getDialogOnly(e.peerId); |
|
|
|
const dialog = appMessagesManager.getDialogOnly(peerId); |
|
|
|
if(dialog) { |
|
|
|
if(dialog) { |
|
|
|
this.updateDialog(dialog); |
|
|
|
this.updateDialog(dialog); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.processContact) { |
|
|
|
|
|
|
|
this.processContact(peerId); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('peer_changed', (e) => { |
|
|
|
rootScope.addEventListener('peer_changed', (peerId) => { |
|
|
|
const peerId = e; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//const perf = performance.now();
|
|
|
|
//const perf = performance.now();
|
|
|
|
for(const element of this.lastActiveElements) { |
|
|
|
for(const element of this.lastActiveElements) { |
|
|
|
if(+element.dataset.peerId !== peerId) { |
|
|
|
if(+element.dataset.peerId !== peerId) { |
|
|
@ -260,8 +265,7 @@ export class AppDialogsManager { |
|
|
|
//this.log('peer_changed total time:', performance.now() - perf);
|
|
|
|
//this.log('peer_changed total time:', performance.now() - perf);
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('filter_update', (e) => { |
|
|
|
rootScope.addEventListener('filter_update', (filter) => { |
|
|
|
const filter: DialogFilter = e; |
|
|
|
|
|
|
|
if(!this.filtersRendered[filter.id]) { |
|
|
|
if(!this.filtersRendered[filter.id]) { |
|
|
|
this.addFilter(filter); |
|
|
|
this.addFilter(filter); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -280,8 +284,7 @@ export class AppDialogsManager { |
|
|
|
elements.title.innerHTML = RichTextProcessor.wrapEmojiText(filter.title); |
|
|
|
elements.title.innerHTML = RichTextProcessor.wrapEmojiText(filter.title); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('filter_delete', (e) => { |
|
|
|
rootScope.addEventListener('filter_delete', (filter) => { |
|
|
|
const filter: DialogFilter = e; |
|
|
|
|
|
|
|
const elements = this.filtersRendered[filter.id]; |
|
|
|
const elements = this.filtersRendered[filter.id]; |
|
|
|
if(!elements) return; |
|
|
|
if(!elements) return; |
|
|
|
|
|
|
|
|
|
|
@ -301,9 +304,7 @@ export class AppDialogsManager { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('filter_order', (e) => { |
|
|
|
rootScope.addEventListener('filter_order', (order) => { |
|
|
|
const order = e; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const containerToAppend = this.folders.menu as HTMLElement; |
|
|
|
const containerToAppend = this.folders.menu as HTMLElement; |
|
|
|
order.forEach((filterId) => { |
|
|
|
order.forEach((filterId) => { |
|
|
|
const filter = appMessagesManager.filtersStorage.filters[filterId]; |
|
|
|
const filter = appMessagesManager.filtersStorage.filters[filterId]; |
|
|
@ -319,9 +320,7 @@ export class AppDialogsManager { |
|
|
|
} */ |
|
|
|
} */ |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
rootScope.addEventListener('peer_typings', (e) => { |
|
|
|
rootScope.addEventListener('peer_typings', ({peerId, typings}) => { |
|
|
|
const {peerId, typings} = e; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dialog = appMessagesManager.getDialogOnly(peerId); |
|
|
|
const dialog = appMessagesManager.getDialogOnly(peerId); |
|
|
|
if(!dialog) return; |
|
|
|
if(!dialog) return; |
|
|
|
|
|
|
|
|
|
|
@ -888,16 +887,27 @@ export class AppDialogsManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private onListLengthChange = () => { |
|
|
|
private onListLengthChange = () => { |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.checkIfPlaceholderNeeded(); |
|
|
|
this.checkIfPlaceholderNeeded(); |
|
|
|
|
|
|
|
|
|
|
|
if(this.filterId > 0) return; |
|
|
|
if(this.filterId > 0) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const count = this.chatList.childElementCount; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const parts = this.chatList.parentElement.parentElement; |
|
|
|
const bottom = this.chatList.parentElement.nextElementSibling as HTMLElement; |
|
|
|
const bottom = this.chatList.parentElement.nextElementSibling as HTMLElement; |
|
|
|
|
|
|
|
const hasContacts = !!bottom.childElementCount; |
|
|
|
|
|
|
|
if(count >= 10) { |
|
|
|
|
|
|
|
if(hasContacts) { |
|
|
|
|
|
|
|
parts.classList.remove('with-contacts'); |
|
|
|
|
|
|
|
bottom.innerHTML = ''; |
|
|
|
|
|
|
|
this.loadContacts = undefined; |
|
|
|
|
|
|
|
this.processContact = undefined; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(bottom.childElementCount) return; |
|
|
|
return; |
|
|
|
|
|
|
|
} else if(hasContacts) return; |
|
|
|
|
|
|
|
|
|
|
|
bottom.parentElement.classList.add('with-contacts'); |
|
|
|
parts.classList.add('with-contacts'); |
|
|
|
|
|
|
|
|
|
|
|
const section = new SettingSection({ |
|
|
|
const section = new SettingSection({ |
|
|
|
name: 'Contacts', |
|
|
|
name: 'Contacts', |
|
|
@ -911,7 +921,7 @@ export class AppDialogsManager { |
|
|
|
const sortedUserList = new SortedUserList({avatarSize: 42, new: true}); |
|
|
|
const sortedUserList = new SortedUserList({avatarSize: 42, new: true}); |
|
|
|
this.loadContacts = () => { |
|
|
|
this.loadContacts = () => { |
|
|
|
const pageCount = appPhotosManager.windowH / 60 | 0; |
|
|
|
const pageCount = appPhotosManager.windowH / 60 | 0; |
|
|
|
const arr = contacts.splice(0, pageCount); |
|
|
|
const arr = contacts.splice(0, pageCount).filter(this.verifyUserIdForContacts); |
|
|
|
|
|
|
|
|
|
|
|
arr.forEach((peerId) => { |
|
|
|
arr.forEach((peerId) => { |
|
|
|
sortedUserList.add(peerId); |
|
|
|
sortedUserList.add(peerId); |
|
|
@ -924,6 +934,17 @@ export class AppDialogsManager { |
|
|
|
|
|
|
|
|
|
|
|
this.loadContacts(); |
|
|
|
this.loadContacts(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.processContact = (peerId) => { |
|
|
|
|
|
|
|
if(peerId < 0) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const good = this.verifyUserIdForContacts(peerId); |
|
|
|
|
|
|
|
const added = sortedUserList.has(peerId); |
|
|
|
|
|
|
|
if(!added && good) sortedUserList.add(peerId); |
|
|
|
|
|
|
|
else if(added && !good) sortedUserList.delete(peerId); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const list = sortedUserList.list; |
|
|
|
const list = sortedUserList.list; |
|
|
|
list.classList.add('chatlist-new'); |
|
|
|
list.classList.add('chatlist-new'); |
|
|
|
this.setListClickListener(list); |
|
|
|
this.setListClickListener(list); |
|
|
@ -934,6 +955,11 @@ export class AppDialogsManager { |
|
|
|
bottom.append(section.container); |
|
|
|
bottom.append(section.container); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private verifyUserIdForContacts = (peerId: number) => { |
|
|
|
|
|
|
|
const dialog = appMessagesManager.getDialogOnly(peerId); |
|
|
|
|
|
|
|
return !dialog; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public onChatsRegularScroll = () => { |
|
|
|
public onChatsRegularScroll = () => { |
|
|
|
if(this.sliceTimeout) clearTimeout(this.sliceTimeout); |
|
|
|
if(this.sliceTimeout) clearTimeout(this.sliceTimeout); |
|
|
|
this.sliceTimeout = window.setTimeout(() => { |
|
|
|
this.sliceTimeout = window.setTimeout(() => { |
|
|
@ -944,7 +970,7 @@ export class AppDialogsManager { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!this.chatList.childElementCount) { |
|
|
|
if(!this.chatList.childElementCount || this.processContact) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|