Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.1 KiB

3 years ago
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
2 years ago
import contextMenuController from '../../helpers/contextMenuController';
import {attachContextMenuListener} from '../../helpers/dom/attachContextMenuListener';
import cancelEvent from '../../helpers/dom/cancelEvent';
import ListenerSetter from '../../helpers/listenerSetter';
import rootScope from '../../lib/rootScope';
import ButtonMenu, {ButtonMenuItemOptions} from '../buttonMenu';
3 years ago
export default class SendMenu {
public sendMenu: HTMLDivElement;
private sendMenuButtons: (ButtonMenuItemOptions & {verify: () => boolean})[];
private type: 'schedule' | 'reminder';
2 years ago
3 years ago
constructor(options: {
onSilentClick: () => void,
onScheduleClick: () => void,
listenerSetter?: ListenerSetter,
openSide: string,
onContextElement: HTMLElement,
onOpen?: () => boolean
}) {
this.sendMenuButtons = [{
icon: 'mute',
text: 'Chat.Send.WithoutSound',
onClick: options.onSilentClick,
verify: () => this.type === 'schedule'
}, {
icon: 'schedule',
text: 'Chat.Send.ScheduledMessage',
onClick: options.onScheduleClick,
verify: () => this.type === 'schedule'
}, {
icon: 'schedule',
text: 'Chat.Send.SetReminder',
onClick: options.onScheduleClick,
verify: () => this.type === 'reminder'
}];
2 years ago
3 years ago
this.sendMenu = ButtonMenu(this.sendMenuButtons, options.listenerSetter);
this.sendMenu.classList.add('menu-send', options.openSide);
attachContextMenuListener(options.onContextElement, (e: any) => {
if(options.onOpen && !options.onOpen()) {
return;
}
this.sendMenuButtons.forEach((button) => {
3 years ago
button.element.classList.toggle('hide', !button.verify());
});
2 years ago
3 years ago
cancelEvent(e);
contextMenuController.openBtnMenu(this.sendMenu);
3 years ago
}, options.listenerSetter);
}
3 years ago
public setPeerId(peerId: PeerId) {
3 years ago
this.type = peerId === rootScope.myId ? 'reminder' : 'schedule';
}
};