Eduard Kuzmenko
4 years ago
12 changed files with 332 additions and 78 deletions
@ -1,48 +1,24 @@ |
|||||||
import { isTouchSupported } from "../../helpers/touchSupport"; |
|
||||||
import appImManager from "../../lib/appManagers/appImManager"; |
import appImManager from "../../lib/appManagers/appImManager"; |
||||||
import AppSelectPeers from "../appSelectPeers"; |
import PopupPickUser from "./pickUser"; |
||||||
import PopupElement from "."; |
|
||||||
|
|
||||||
export default class PopupForward extends PopupElement { |
|
||||||
private selector: AppSelectPeers; |
|
||||||
//private scrollable: Scrollable;
|
|
||||||
|
|
||||||
|
export default class PopupForward extends PopupPickUser { |
||||||
constructor(fromPeerId: number, mids: number[], onSelect?: () => Promise<void> | void, onClose?: () => void) { |
constructor(fromPeerId: number, mids: number[], onSelect?: () => Promise<void> | void, onClose?: () => void) { |
||||||
super('popup-forward', null, {closable: true, overlayClosable: true, body: true}); |
super({ |
||||||
|
peerTypes: ['dialogs', 'contacts'], |
||||||
if(onClose) this.onClose = onClose; |
onSelect: async(peerId) => { |
||||||
|
if(onSelect) { |
||||||
this.selector = new AppSelectPeers({ |
const res = onSelect(); |
||||||
appendTo: this.body, |
if(res instanceof Promise) { |
||||||
onChange: async() => { |
await res; |
||||||
const peerId = this.selector.getSelected()[0]; |
} |
||||||
this.btnClose.click(); |
} |
||||||
|
|
||||||
this.selector = null; |
|
||||||
|
|
||||||
await (onSelect ? onSelect() || Promise.resolve() : Promise.resolve()); |
|
||||||
|
|
||||||
appImManager.setInnerPeer(peerId); |
appImManager.setInnerPeer(peerId); |
||||||
appImManager.chat.input.initMessagesForward(fromPeerId, mids.slice()); |
appImManager.chat.input.initMessagesForward(fromPeerId, mids.slice()); |
||||||
}, |
}, |
||||||
peerType: ['dialogs', 'contacts'], |
onClose, |
||||||
onFirstRender: () => { |
placeholder: 'Forward to...', |
||||||
this.show(); |
chatRightsAction: 'send' |
||||||
this.selector.checkForTriggers(); // ! due to zero height before mounting
|
|
||||||
|
|
||||||
if(!isTouchSupported) { |
|
||||||
this.selector.input.focus(); |
|
||||||
} |
|
||||||
}, |
|
||||||
chatRightsAction: 'send', |
|
||||||
multiSelect: false, |
|
||||||
rippleEnabled: false |
|
||||||
}); |
}); |
||||||
|
|
||||||
//this.scrollable = new Scrollable(this.body);
|
|
||||||
|
|
||||||
this.selector.input.placeholder = 'Forward to...'; |
|
||||||
this.title.append(this.selector.input); |
|
||||||
} |
} |
||||||
|
|
||||||
} |
} |
@ -0,0 +1,53 @@ |
|||||||
|
import { isTouchSupported } from "../../helpers/touchSupport"; |
||||||
|
import AppSelectPeers from "../appSelectPeers"; |
||||||
|
import PopupElement from "."; |
||||||
|
|
||||||
|
export default class PopupPickUser extends PopupElement { |
||||||
|
protected selector: AppSelectPeers; |
||||||
|
|
||||||
|
constructor(options: { |
||||||
|
peerTypes: AppSelectPeers['peerType'], |
||||||
|
onSelect?: (peerId: number) => Promise<void> | void, |
||||||
|
onClose?: () => void, |
||||||
|
placeholder: string, |
||||||
|
chatRightsAction?: AppSelectPeers['chatRightsAction'] |
||||||
|
}) { |
||||||
|
super('popup-forward', null, {closable: true, overlayClosable: true, body: true}); |
||||||
|
|
||||||
|
if(options.onClose) this.onClose = options.onClose; |
||||||
|
|
||||||
|
this.selector = new AppSelectPeers({ |
||||||
|
appendTo: this.body, |
||||||
|
onChange: async() => { |
||||||
|
const peerId = this.selector.getSelected()[0]; |
||||||
|
this.btnClose.click(); |
||||||
|
|
||||||
|
this.selector = null; |
||||||
|
|
||||||
|
if(options.onSelect) { |
||||||
|
const res = options.onSelect(peerId); |
||||||
|
if(res instanceof Promise) { |
||||||
|
await res; |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
peerType: options.peerTypes, |
||||||
|
onFirstRender: () => { |
||||||
|
this.show(); |
||||||
|
this.selector.checkForTriggers(); // ! due to zero height before mounting
|
||||||
|
|
||||||
|
if(!isTouchSupported) { |
||||||
|
this.selector.input.focus(); |
||||||
|
} |
||||||
|
}, |
||||||
|
chatRightsAction: options.chatRightsAction, |
||||||
|
multiSelect: false, |
||||||
|
rippleEnabled: false |
||||||
|
}); |
||||||
|
|
||||||
|
//this.scrollable = new Scrollable(this.body);
|
||||||
|
|
||||||
|
this.selector.input.placeholder = options.placeholder; |
||||||
|
this.title.append(this.selector.input); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,115 @@ |
|||||||
|
import { SliderSuperTab } from "../../slider"; |
||||||
|
import { SettingSection } from ".."; |
||||||
|
import { attachContextMenuListener, openBtnMenu, positionMenu } from "../../misc"; |
||||||
|
import { attachClickEvent, findUpTag } from "../../../helpers/dom"; |
||||||
|
import ButtonMenu from "../../buttonMenu"; |
||||||
|
import appDialogsManager from "../../../lib/appManagers/appDialogsManager"; |
||||||
|
import appUsersManager from "../../../lib/appManagers/appUsersManager"; |
||||||
|
import Button from "../../button"; |
||||||
|
import PopupPickUser from "../../popups/pickUser"; |
||||||
|
import rootScope from "../../../lib/rootScope"; |
||||||
|
|
||||||
|
export default class AppBlockedUsersTab extends SliderSuperTab { |
||||||
|
public peerIds: number[]; |
||||||
|
private menuElement: HTMLElement; |
||||||
|
|
||||||
|
protected init() { |
||||||
|
this.container.classList.add('blocked-users-container'); |
||||||
|
this.title.innerText = 'Blocked Users'; |
||||||
|
|
||||||
|
{ |
||||||
|
const section = new SettingSection({ |
||||||
|
caption: 'Blocked users will not be able to contact you and will not see your Last Seen time.' |
||||||
|
}); |
||||||
|
|
||||||
|
this.scrollable.append(section.container); |
||||||
|
} |
||||||
|
|
||||||
|
const btnAdd = Button('btn-circle btn-corner tgico-add is-visible'); |
||||||
|
this.content.append(btnAdd); |
||||||
|
|
||||||
|
attachClickEvent(btnAdd, (e) => { |
||||||
|
new PopupPickUser({ |
||||||
|
peerTypes: ['contacts'], |
||||||
|
placeholder: 'Block user...', |
||||||
|
onSelect: (peerId) => { |
||||||
|
//console.log('block', peerId);
|
||||||
|
appUsersManager.toggleBlock(peerId, true); |
||||||
|
}, |
||||||
|
}); |
||||||
|
}, {listenerSetter: this.listenerSetter}); |
||||||
|
|
||||||
|
const list = document.createElement('ul'); |
||||||
|
this.scrollable.container.classList.add('chatlist-container'); |
||||||
|
this.scrollable.append(list); |
||||||
|
|
||||||
|
const add = (peerId: number, append: boolean) => { |
||||||
|
const {dom} = appDialogsManager.addDialogNew({ |
||||||
|
dialog: peerId, |
||||||
|
container: list, |
||||||
|
drawStatus: false, |
||||||
|
rippleEnabled: true, |
||||||
|
avatarSize: 48, |
||||||
|
append |
||||||
|
}); |
||||||
|
|
||||||
|
const user = appUsersManager.getUser(peerId); |
||||||
|
dom.lastMessageSpan.innerHTML = user.pFlags.bot ? ('@' + user.username) : user.rPhone || (user.username ? '@' + user.username : appUsersManager.getUserStatusString(peerId)); |
||||||
|
}; |
||||||
|
|
||||||
|
for(const peerId of this.peerIds) { |
||||||
|
add(peerId, true); |
||||||
|
} |
||||||
|
|
||||||
|
let target: HTMLElement; |
||||||
|
const onUnblock = () => { |
||||||
|
const peerId = +target.dataset.peerId; |
||||||
|
appUsersManager.toggleBlock(peerId, false); |
||||||
|
}; |
||||||
|
|
||||||
|
const element = this.menuElement = ButtonMenu([{ |
||||||
|
icon: 'unlock', |
||||||
|
text: 'Unblock', |
||||||
|
onClick: onUnblock, |
||||||
|
options: {listenerSetter: this.listenerSetter} |
||||||
|
}]); |
||||||
|
element.id = 'blocked-users-contextmenu'; |
||||||
|
element.classList.add('contextmenu'); |
||||||
|
|
||||||
|
document.getElementById('page-chats').append(element); |
||||||
|
|
||||||
|
attachContextMenuListener(this.scrollable.container, (e) => { |
||||||
|
target = findUpTag(e.target, 'LI'); |
||||||
|
if(!target) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if(e instanceof MouseEvent) e.preventDefault(); |
||||||
|
// smth
|
||||||
|
if(e instanceof MouseEvent) e.cancelBubble = true; |
||||||
|
|
||||||
|
positionMenu(e, element); |
||||||
|
openBtnMenu(element); |
||||||
|
}, this.listenerSetter); |
||||||
|
|
||||||
|
this.listenerSetter.add(rootScope, 'peer_block', (update) => { |
||||||
|
const {peerId, blocked} = update; |
||||||
|
if(blocked) { |
||||||
|
add(peerId, false); |
||||||
|
} else { |
||||||
|
const li = list.querySelector(`[data-peer-id="${peerId}"]`); |
||||||
|
if(li) { |
||||||
|
li.remove(); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
onCloseAfterTimeout() { |
||||||
|
if(this.menuElement) { |
||||||
|
this.menuElement.remove(); |
||||||
|
} |
||||||
|
|
||||||
|
return super.onCloseAfterTimeout(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue