tweb/src/components/appForward.ts
morethanwords b4f16e9244 New stickers (rlottie)
Media viewer:
1) fix arrows
2) forward
3) item opening
QR-code 2FA login fix
Forward dialogs search (not ready yet)
Webpages square and vertical layouts
2020-05-30 09:44:54 +03:00

79 lines
2.3 KiB
TypeScript

import appSidebarRight from "../lib/appManagers/appSidebarRight";
import appMessagesManager from "../lib/appManagers/appMessagesManager";
import { putPreloader } from "./misc";
import { AppSelectPeers } from "./appSelectPeers";
class AppForward {
public container = document.getElementById('forward-container') as HTMLDivElement;
private closeBtn = this.container.querySelector('.sidebar-close-button') as HTMLButtonElement;
private sendBtn = this.container.querySelector('.btn-circle') as HTMLButtonElement;
private selector: AppSelectPeers;
private msgIDs: number[] = [];
constructor() {
this.closeBtn.addEventListener('click', this.close.bind(this));
this.sendBtn.addEventListener('click', () => {
let peerIDs = this.selector.getSelected();
if(this.msgIDs.length && peerIDs.length) {
this.sendBtn.classList.remove('tgico-send');
this.sendBtn.disabled = true;
putPreloader(this.sendBtn);
this.selector.freezed = true;
let s = () => {
let promises = peerIDs.splice(0, 3).map(peerID => {
return appMessagesManager.forwardMessages(peerID, this.msgIDs);
});
Promise.all(promises).then(() => {
if(peerIDs.length) {
return s();
} else {
this.closeBtn.click();
}
});
};
s();
}
});
}
public close() {
this.cleanup();
this.container.classList.remove('active');
}
public cleanup() {
if(this.selector) {
this.selector.container.remove();
this.selector = null;
}
}
public init(ids: number[]) {
this.cleanup();
this.msgIDs = ids;
this.container.classList.add('active');
this.sendBtn.innerHTML = '';
this.sendBtn.classList.add('tgico-send');
this.sendBtn.disabled = false;
this.selector = new AppSelectPeers(this.container, (length) => {
if(length) {
this.sendBtn.classList.add('is-visible');
} else {
this.sendBtn.classList.remove('is-visible');
}
}, 'dialogs', () => {
console.log('forward rendered:', this.container.querySelector('.selector ul').childElementCount);
appSidebarRight.toggleSidebar(true);
});
}
}
export default new AppForward();