ca1213c32f
Fix chat date blinking Fix displaying sent messages to new dialog Scroll to date bubble if message is bigger than viewport Fix releasing keyboard by inline helper Fix clearing self user Fix displaying sent public poll Update contacts counter in dialogs placeholder Improve multiselect animation Disable lottie icon animations if they're disabled Fix changing mtproto transport during authorization
161 lines
4.7 KiB
TypeScript
161 lines
4.7 KiB
TypeScript
/*
|
|
* https://github.com/morethanwords/tweb
|
|
* Copyright (C) 2019-2021 Eduard Kuzmenko
|
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
|
*/
|
|
|
|
import { SliderSuperTab } from "../../slider";
|
|
import { SettingSection } from "..";
|
|
import { attachContextMenuListener, openBtnMenu, positionMenu } from "../../misc";
|
|
import ButtonMenu from "../../buttonMenu";
|
|
import appDialogsManager from "../../../lib/appManagers/appDialogsManager";
|
|
import appUsersManager from "../../../lib/appManagers/appUsersManager";
|
|
import PopupPickUser from "../../popups/pickUser";
|
|
import rootScope from "../../../lib/rootScope";
|
|
import findUpTag from "../../../helpers/dom/findUpTag";
|
|
import ButtonCorner from "../../buttonCorner";
|
|
import { attachClickEvent } from "../../../helpers/dom/clickEvent";
|
|
|
|
export default class AppBlockedUsersTab extends SliderSuperTab {
|
|
public peerIds: PeerId[];
|
|
private menuElement: HTMLElement;
|
|
|
|
protected init() {
|
|
this.header.classList.add('with-border');
|
|
this.container.classList.add('blocked-users-container');
|
|
this.setTitle('BlockedUsers');
|
|
|
|
{
|
|
const section = new SettingSection({
|
|
caption: 'BlockedUsersInfo'
|
|
});
|
|
|
|
this.scrollable.append(section.container);
|
|
}
|
|
|
|
const btnAdd = ButtonCorner({icon: 'add', className: 'is-visible'});
|
|
this.content.append(btnAdd);
|
|
|
|
attachClickEvent(btnAdd, (e) => {
|
|
new PopupPickUser({
|
|
peerTypes: ['contacts'],
|
|
placeholder: 'BlockModal.Search.Placeholder',
|
|
onSelect: (peerId) => {
|
|
//console.log('block', peerId);
|
|
appUsersManager.toggleBlock(peerId, true);
|
|
},
|
|
});
|
|
}, {listenerSetter: this.listenerSetter});
|
|
|
|
const list = appDialogsManager.createChatList();
|
|
this.scrollable.container.classList.add('chatlist-container');
|
|
this.scrollable.append(list);
|
|
|
|
const add = (peerId: PeerId, append: boolean) => {
|
|
const {dom} = appDialogsManager.addDialogNew({
|
|
dialog: peerId,
|
|
container: list,
|
|
drawStatus: false,
|
|
rippleEnabled: true,
|
|
avatarSize: 48,
|
|
append
|
|
});
|
|
|
|
const user = appUsersManager.getUser(peerId);
|
|
if(user.pFlags.bot) {
|
|
dom.lastMessageSpan.append('@' + user.username);
|
|
} else {
|
|
if(user.phone) dom.lastMessageSpan.innerHTML = appUsersManager.formatUserPhone(user.phone);
|
|
else dom.lastMessageSpan.append(user.username ? '@' + user.username : appUsersManager.getUserStatusString(peerId));
|
|
}
|
|
|
|
//dom.titleSpan.innerHTML = 'Raaid El Syed';
|
|
//dom.lastMessageSpan.innerHTML = '+1 234 567891';
|
|
};
|
|
|
|
for(const peerId of this.peerIds) {
|
|
add(peerId, true);
|
|
}
|
|
|
|
let target: HTMLElement;
|
|
const onUnblock = () => {
|
|
const peerId = target.dataset.peerId.toPeerId();
|
|
appUsersManager.toggleBlock(peerId, false);
|
|
};
|
|
|
|
const element = this.menuElement = ButtonMenu([{
|
|
icon: 'lockoff',
|
|
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;
|
|
const li = list.querySelector(`[data-peer-id="${peerId}"]`);
|
|
if(blocked) {
|
|
if(!li) {
|
|
add(peerId, false);
|
|
}
|
|
} else {
|
|
if(li) {
|
|
li.remove();
|
|
}
|
|
}
|
|
});
|
|
|
|
const LOAD_COUNT = 50;
|
|
let loading = false;
|
|
this.scrollable.onScrolledBottom = () => {
|
|
if(loading) {
|
|
return;
|
|
}
|
|
|
|
loading = true;
|
|
appUsersManager.getBlocked(list.childElementCount, LOAD_COUNT).then(res => {
|
|
for(const peerId of res.peerIds) {
|
|
add(peerId, true);
|
|
}
|
|
|
|
if(res.peerIds.length < LOAD_COUNT || list.childElementCount === res.count) {
|
|
this.scrollable.onScrolledBottom = null;
|
|
}
|
|
|
|
this.scrollable.checkForTriggers();
|
|
}).finally(() => {
|
|
loading = false;
|
|
});
|
|
};
|
|
}
|
|
|
|
onOpenAfterTimeout() {
|
|
this.scrollable.onScroll();
|
|
}
|
|
|
|
onCloseAfterTimeout() {
|
|
if(this.menuElement) {
|
|
this.menuElement.remove();
|
|
}
|
|
|
|
return super.onCloseAfterTimeout();
|
|
}
|
|
}
|