2020-04-24 03:48:48 +03:00
|
|
|
//import { logger } from "../polyfill";
|
2020-02-06 22:43:07 +07:00
|
|
|
import appDialogsManager from "./appDialogsManager";
|
2020-04-24 03:48:48 +03:00
|
|
|
import { $rootScope } from "../utils";
|
2020-02-08 13:03:09 +07:00
|
|
|
import appImManager from "./appImManager";
|
2020-04-24 03:48:48 +03:00
|
|
|
import AppSearch, { SearchGroup } from "../../components/appSearch";
|
2020-06-13 11:19:39 +03:00
|
|
|
import { parseMenuButtonsTo } from "../../components/misc";
|
2020-05-06 04:03:31 +03:00
|
|
|
import appUsersManager from "./appUsersManager";
|
|
|
|
import Scrollable from "../../components/scrollable_new";
|
2020-06-06 08:26:18 +03:00
|
|
|
import appPeersManager from "../appManagers/appPeersManager";
|
2020-05-13 18:26:40 +03:00
|
|
|
import AvatarElement from "../../components/avatar";
|
2020-06-13 11:19:39 +03:00
|
|
|
import AppNewChannelTab from "../../components/sidebarLeft/newChannel";
|
|
|
|
import AppAddMembersTab from "../../components/sidebarLeft/addMembers";
|
|
|
|
import AppContactsTab from "../../components/sidebarLeft/contacts";
|
|
|
|
import AppNewGroupTab from "../../components/sidebarLeft/newGroup";
|
|
|
|
import AppSettingsTab from "../../components/sidebarLeft/settings";
|
|
|
|
import AppEditProfileTab from "../../components/sidebarLeft/editProfile";
|
|
|
|
import SidebarSlider from "../../components/slider";
|
|
|
|
import SearchInput from "../../components/searchInput";
|
2020-05-13 18:26:40 +03:00
|
|
|
|
|
|
|
AvatarElement;
|
2020-05-06 04:03:31 +03:00
|
|
|
|
2020-06-13 11:19:39 +03:00
|
|
|
const newChannelTab = new AppNewChannelTab();
|
|
|
|
const addMembersTab = new AppAddMembersTab();
|
|
|
|
const contactsTab = new AppContactsTab();
|
|
|
|
const newGroupTab = new AppNewGroupTab();
|
|
|
|
const settingsTab = new AppSettingsTab();
|
|
|
|
const editProfileTab = new AppEditProfileTab();
|
|
|
|
|
|
|
|
export class AppSidebarLeft extends SidebarSlider {
|
|
|
|
public static SLIDERITEMSIDS = {
|
|
|
|
archived: 1,
|
|
|
|
contacts: 2,
|
|
|
|
newChannel: 3,
|
|
|
|
addMembers: 4,
|
|
|
|
newGroup: 5,
|
|
|
|
settings: 6,
|
|
|
|
editProfile: 7,
|
2020-05-13 18:26:40 +03:00
|
|
|
};
|
|
|
|
|
2020-06-13 11:19:39 +03:00
|
|
|
private toolsBtn: HTMLButtonElement;
|
|
|
|
private backBtn: HTMLButtonElement;
|
|
|
|
private searchContainer: HTMLDivElement;
|
|
|
|
//private searchInput = document.getElementById('global-search') as HTMLInputElement;
|
|
|
|
private searchInput: SearchInput;
|
2020-02-08 18:58:22 +07:00
|
|
|
|
2020-06-13 11:19:39 +03:00
|
|
|
private menuEl: HTMLElement;
|
2020-05-27 09:21:16 +03:00
|
|
|
private buttons: {
|
|
|
|
newGroup: HTMLButtonElement,
|
|
|
|
contacts: HTMLButtonElement,
|
|
|
|
archived: HTMLButtonElement,
|
|
|
|
saved: HTMLButtonElement,
|
|
|
|
settings: HTMLButtonElement,
|
|
|
|
help: HTMLButtonElement
|
|
|
|
} = {} as any;
|
|
|
|
public archivedCount: HTMLSpanElement;
|
2020-02-09 13:45:43 +07:00
|
|
|
|
2020-06-13 11:19:39 +03:00
|
|
|
private newBtnMenu: HTMLElement;
|
2020-05-27 09:21:16 +03:00
|
|
|
private newButtons: {
|
|
|
|
channel: HTMLButtonElement,
|
|
|
|
group: HTMLButtonElement,
|
|
|
|
privateChat: HTMLButtonElement,
|
|
|
|
} = {} as any;
|
2020-06-13 11:19:39 +03:00
|
|
|
|
|
|
|
public newChannelTab: AppNewChannelTab;
|
|
|
|
public addMembersTab: AppAddMembersTab;
|
|
|
|
public contactsTab: AppContactsTab;
|
|
|
|
public newGroupTab: AppNewGroupTab;
|
|
|
|
public settingsTab: AppSettingsTab;
|
|
|
|
public editProfileTab: AppEditProfileTab;
|
2020-05-09 15:02:07 +03:00
|
|
|
|
2020-04-24 03:48:48 +03:00
|
|
|
//private log = logger('SL');
|
|
|
|
|
2020-05-06 04:03:31 +03:00
|
|
|
private searchGroups = {
|
2020-04-24 03:48:48 +03:00
|
|
|
contacts: new SearchGroup('Contacts and Chats', 'contacts'),
|
|
|
|
globalContacts: new SearchGroup('Global Search', 'contacts'),
|
2020-05-06 04:03:31 +03:00
|
|
|
messages: new SearchGroup('Global Search', 'messages'),
|
|
|
|
people: new SearchGroup('People', 'contacts', false, 'search-group-people'),
|
|
|
|
recent: new SearchGroup('Recent', 'contacts', false, 'search-group-recent')
|
|
|
|
};
|
2020-06-13 11:19:39 +03:00
|
|
|
private globalSearch: AppSearch;
|
2020-02-21 15:25:19 +07:00
|
|
|
|
2020-02-06 22:43:07 +07:00
|
|
|
constructor() {
|
2020-06-13 11:19:39 +03:00
|
|
|
super(document.getElementById('column-left') as HTMLDivElement, {
|
|
|
|
//[AppSidebarLeft.SLIDERITEMSIDS.archived]: ,
|
|
|
|
[AppSidebarLeft.SLIDERITEMSIDS.newChannel]: newChannelTab,
|
|
|
|
[AppSidebarLeft.SLIDERITEMSIDS.contacts]: contactsTab,
|
|
|
|
[AppSidebarLeft.SLIDERITEMSIDS.addMembers]: addMembersTab,
|
|
|
|
[AppSidebarLeft.SLIDERITEMSIDS.newGroup]: newGroupTab,
|
|
|
|
[AppSidebarLeft.SLIDERITEMSIDS.settings]: settingsTab,
|
|
|
|
[AppSidebarLeft.SLIDERITEMSIDS.editProfile]: editProfileTab,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.searchInput = new SearchInput('Telegram Search');
|
|
|
|
this.sidebarEl.querySelector('.item-main .sidebar-header').append(this.searchInput.container);
|
|
|
|
|
|
|
|
this.toolsBtn = this.sidebarEl.querySelector('.sidebar-tools-button') as HTMLButtonElement;
|
|
|
|
this.backBtn = this.sidebarEl.querySelector('.sidebar-back-button') as HTMLButtonElement;
|
|
|
|
this.searchContainer = this.sidebarEl.querySelector('#search-container') as HTMLDivElement;
|
|
|
|
|
|
|
|
this.newChannelTab = newChannelTab;
|
|
|
|
this.addMembersTab = addMembersTab;
|
|
|
|
this.contactsTab = contactsTab;
|
|
|
|
this.newGroupTab = newGroupTab;
|
|
|
|
this.settingsTab = settingsTab;
|
|
|
|
this.editProfileTab = editProfileTab;
|
|
|
|
|
|
|
|
this.menuEl = this.toolsBtn.querySelector('.btn-menu');
|
|
|
|
this.newBtnMenu = this.sidebarEl.querySelector('#new-menu');
|
|
|
|
|
|
|
|
this.globalSearch = new AppSearch(this.searchContainer, this.searchInput, this.searchGroups);
|
|
|
|
|
2020-05-06 04:03:31 +03:00
|
|
|
let peopleContainer = document.createElement('div');
|
|
|
|
peopleContainer.classList.add('search-group-scrollable');
|
|
|
|
peopleContainer.append(this.searchGroups.people.list);
|
|
|
|
this.searchGroups.people.container.append(peopleContainer);
|
|
|
|
let peopleScrollable = new Scrollable(peopleContainer, 'x');
|
|
|
|
|
2020-05-27 09:21:16 +03:00
|
|
|
parseMenuButtonsTo(this.buttons, this.menuEl.children);
|
|
|
|
parseMenuButtonsTo(this.newButtons, this.newBtnMenu.firstElementChild.children);
|
|
|
|
|
|
|
|
this.archivedCount = this.buttons.archived.querySelector('.archived-count') as HTMLSpanElement;
|
|
|
|
|
|
|
|
this.buttons.saved.addEventListener('click', (e) => {
|
2020-02-17 19:18:06 +07:00
|
|
|
///////this.log('savedbtn click');
|
2020-02-10 14:56:15 +07:00
|
|
|
setTimeout(() => { // menu doesn't close if no timeout (lol)
|
2020-04-08 18:46:43 +03:00
|
|
|
appImManager.setPeer(appImManager.myID);
|
2020-02-10 14:56:15 +07:00
|
|
|
}, 0);
|
2020-02-08 13:03:09 +07:00
|
|
|
});
|
2020-02-07 13:38:55 +07:00
|
|
|
|
2020-05-27 09:21:16 +03:00
|
|
|
this.buttons.archived.addEventListener('click', (e) => {
|
2020-06-13 11:19:39 +03:00
|
|
|
this.selectTab(AppSidebarLeft.SLIDERITEMSIDS.archived);
|
2020-05-06 04:03:31 +03:00
|
|
|
});
|
|
|
|
|
2020-05-27 09:21:16 +03:00
|
|
|
this.buttons.contacts.addEventListener('click', (e) => {
|
2020-05-09 15:02:07 +03:00
|
|
|
this.contactsTab.openContacts();
|
2020-02-11 22:35:57 +07:00
|
|
|
});
|
2020-04-19 00:55:20 +03:00
|
|
|
|
2020-05-27 09:21:16 +03:00
|
|
|
this.buttons.settings.addEventListener('click', () => {
|
2020-05-13 18:26:40 +03:00
|
|
|
this.settingsTab.fillElements();
|
2020-06-13 11:19:39 +03:00
|
|
|
this.selectTab(AppSidebarLeft.SLIDERITEMSIDS.settings);
|
2020-04-19 00:55:20 +03:00
|
|
|
});
|
2020-02-22 18:20:43 +07:00
|
|
|
|
2020-06-13 11:19:39 +03:00
|
|
|
this.searchInput.input.addEventListener('focus', (e) => {
|
2020-02-15 22:20:38 +07:00
|
|
|
this.toolsBtn.classList.remove('active');
|
|
|
|
this.backBtn.classList.add('active');
|
2020-05-06 04:03:31 +03:00
|
|
|
this.searchContainer.classList.remove('hide');
|
|
|
|
void this.searchContainer.offsetWidth; // reflow
|
2020-02-06 22:43:07 +07:00
|
|
|
this.searchContainer.classList.add('active');
|
2020-02-09 17:30:24 +07:00
|
|
|
|
2020-05-13 18:26:40 +03:00
|
|
|
/* this.searchInput.addEventListener('blur', (e) => {
|
2020-02-06 22:43:07 +07:00
|
|
|
if(!this.searchInput.value) {
|
2020-02-15 22:20:38 +07:00
|
|
|
this.toolsBtn.classList.add('active');
|
|
|
|
this.backBtn.classList.remove('active');
|
2020-02-17 19:18:06 +07:00
|
|
|
this.backBtn.click();
|
2020-02-06 22:43:07 +07:00
|
|
|
}
|
2020-05-13 18:26:40 +03:00
|
|
|
}, {once: true}); */
|
2020-02-06 22:43:07 +07:00
|
|
|
});
|
2020-02-10 14:56:15 +07:00
|
|
|
|
2020-02-15 22:20:38 +07:00
|
|
|
this.backBtn.addEventListener('click', (e) => {
|
2020-04-20 00:40:00 +03:00
|
|
|
appDialogsManager.chatsArchivedContainer.classList.remove('active');
|
2020-02-15 22:20:38 +07:00
|
|
|
this.toolsBtn.classList.add('active');
|
|
|
|
this.backBtn.classList.remove('active');
|
2020-02-17 19:18:06 +07:00
|
|
|
this.searchContainer.classList.remove('active');
|
2020-05-06 04:03:31 +03:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.searchContainer.classList.add('hide');
|
|
|
|
this.globalSearch.reset();
|
|
|
|
|
|
|
|
this.searchGroups.people.setActive();
|
|
|
|
//this.searchGroups.recent.setActive();
|
|
|
|
}, 150);
|
2020-02-07 13:38:55 +07:00
|
|
|
});
|
2020-02-11 22:35:57 +07:00
|
|
|
|
2020-05-09 15:02:07 +03:00
|
|
|
this.newButtons.channel.addEventListener('click', (e) => {
|
2020-06-13 11:19:39 +03:00
|
|
|
this.selectTab(AppSidebarLeft.SLIDERITEMSIDS.newChannel);
|
2020-05-09 15:02:07 +03:00
|
|
|
});
|
|
|
|
|
2020-05-27 09:21:16 +03:00
|
|
|
[this.newButtons.group, this.buttons.newGroup].forEach(btn => {
|
2020-05-09 15:02:07 +03:00
|
|
|
btn.addEventListener('click', (e) => {
|
|
|
|
this.addMembersTab.init(0, 'chat', false, (peerIDs) => {
|
|
|
|
this.newGroupTab.init(peerIDs);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-20 00:40:00 +03:00
|
|
|
$rootScope.$on('dialogs_archived_unread', (e: CustomEvent) => {
|
|
|
|
this.archivedCount.innerText = '' + e.detail.count;
|
|
|
|
});
|
|
|
|
|
2020-05-06 04:03:31 +03:00
|
|
|
appUsersManager.getTopPeers().then(categories => {
|
2020-06-13 11:19:39 +03:00
|
|
|
//console.log('got top categories:', categories);
|
2020-05-06 04:03:31 +03:00
|
|
|
|
|
|
|
let category = categories[0];
|
|
|
|
if(!category || !category.peers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
category.peers.forEach((topPeer: {
|
|
|
|
_: 'topPeer',
|
|
|
|
peer: any,
|
|
|
|
rating: number
|
|
|
|
}) => {
|
|
|
|
let peerID = appPeersManager.getPeerID(topPeer.peer);
|
|
|
|
let {dialog, dom} = appDialogsManager.addDialog(peerID, this.searchGroups.people.list, false, true, true);
|
|
|
|
|
|
|
|
this.searchGroups.people.setActive();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-02-06 22:43:07 +07:00
|
|
|
}
|
|
|
|
|
2020-04-08 18:46:43 +03:00
|
|
|
const appSidebarLeft = new AppSidebarLeft();
|
2020-06-16 23:48:08 +03:00
|
|
|
// @ts-ignore
|
|
|
|
if(process.env.NODE_ENV != 'production') {
|
|
|
|
(window as any).appSidebarLeft = appSidebarLeft;
|
|
|
|
}
|
2020-04-08 18:46:43 +03:00
|
|
|
export default appSidebarLeft;
|