tweb/src/components/sidebarRight/tabs/userPermissions.ts

128 lines
4.6 KiB
TypeScript
Raw Normal View History

2021-04-08 15:52:31 +02:00
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import { attachClickEvent } from "../../../helpers/dom/clickEvent";
import toggleDisability from "../../../helpers/dom/toggleDisability";
2021-03-19 13:14:42 +01:00
import { deepEqual } from "../../../helpers/object";
import { ChannelParticipant } from "../../../layer";
import appChatsManager from "../../../lib/appManagers/appChatsManager";
import appDialogsManager from "../../../lib/appManagers/appDialogsManager";
import appUsersManager from "../../../lib/appManagers/appUsersManager";
import Button from "../../button";
import { SettingSection } from "../../sidebarLeft";
import { SliderSuperTabEventable } from "../../sliderTab";
import { ChatPermissions } from "./groupPermissions";
export default class AppUserPermissionsTab extends SliderSuperTabEventable {
2021-03-19 15:27:02 +01:00
public participant: ChannelParticipant;
2021-10-21 15:16:43 +02:00
public chatId: ChatId;
public userId: UserId;
2021-03-19 13:14:42 +01:00
protected init() {
this.container.classList.add('edit-peer-container', 'user-permissions-container');
2021-03-28 20:37:11 +02:00
this.setTitle('UserRestrictions');
2021-03-19 13:14:42 +01:00
2021-03-19 15:27:02 +01:00
let destroyListener: () => void;
2021-03-19 13:14:42 +01:00
{
const section = new SettingSection({
2021-03-28 20:37:11 +02:00
name: 'UserRestrictionsCanDo',
2021-03-19 13:14:42 +01:00
});
const div = document.createElement('div');
div.classList.add('chatlist-container');
section.content.insertBefore(div, section.title);
2021-07-20 18:11:58 +02:00
const list = appDialogsManager.createChatList({new: true});
2021-03-19 13:14:42 +01:00
div.append(list);
const {dom} = appDialogsManager.addDialogNew({
2021-10-21 15:16:43 +02:00
dialog: this.userId.toPeerId(false),
2021-03-19 13:14:42 +01:00
container: list,
drawStatus: false,
rippleEnabled: true,
avatarSize: 48
});
2021-03-28 20:37:11 +02:00
dom.lastMessageSpan.append(appUsersManager.getUserStatusString(this.userId));
2021-03-19 13:14:42 +01:00
const p = new ChatPermissions({
chatId: this.chatId,
listenerSetter: this.listenerSetter,
appendTo: section.content,
2021-03-19 15:27:02 +01:00
participant: this.participant._ === 'channelParticipantBanned' ? this.participant : undefined
2021-03-19 13:14:42 +01:00
});
2021-03-19 15:27:02 +01:00
destroyListener = () => {
2021-03-19 13:14:42 +01:00
//appChatsManager.editChatDefaultBannedRights(this.chatId, p.takeOut());
const rights = p.takeOut();
2021-03-19 15:27:02 +01:00
if(this.participant._ === 'channelParticipantBanned' && deepEqual(this.participant.banned_rights.pFlags, rights.pFlags)) {
2021-03-19 13:14:42 +01:00
return;
}
appChatsManager.editBanned(this.chatId, this.participant, rights);
2021-03-19 15:27:02 +01:00
};
this.eventListener.addEventListener('destroy', destroyListener, {once: true});
2021-03-19 13:14:42 +01:00
this.scrollable.append(section.container);
}
{
const section = new SettingSection({});
2021-03-19 15:27:02 +01:00
if(this.participant._ === 'channelParticipantBanned') {
2021-03-28 20:37:11 +02:00
const btnDeleteException = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'GroupPermission.Delete'});
2021-03-19 15:27:02 +01:00
attachClickEvent(btnDeleteException, () => {
const toggle = toggleDisability([btnDeleteException], true);
appChatsManager.clearChannelParticipantBannedRights(this.chatId, this.participant).then(() => {
this.eventListener.removeEventListener('destroy', destroyListener);
this.close();
}, () => {
toggle();
});
}, {listenerSetter: this.listenerSetter});
section.content.append(btnDeleteException);
}
2021-03-28 20:37:11 +02:00
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'deleteuser', text: 'UserRestrictionsBlock'});
2021-03-19 13:14:42 +01:00
attachClickEvent(btnDelete, () => {
2021-03-28 20:37:11 +02:00
const toggle = toggleDisability([btnDelete], true);
appChatsManager.kickFromChannel(this.chatId, this.participant).then(() => {
this.eventListener.removeEventListener('destroy', destroyListener);
this.close();
});
/* new PopupPeer('popup-group-kick-user', {
2021-03-19 13:14:42 +01:00
peerId: -this.chatId,
2021-03-19 15:27:02 +01:00
title: 'Ban User?',
description: `Are you sure you want to ban <b>${appPeersManager.getPeerTitle(this.userId)}</b>`,
2021-03-19 13:14:42 +01:00
buttons: addCancelButton([{
2021-03-19 15:27:02 +01:00
text: 'BAN',
2021-03-19 13:14:42 +01:00
callback: () => {
2021-03-19 15:27:02 +01:00
const toggle = toggleDisability([btnDelete], true);
2021-03-19 13:14:42 +01:00
2021-03-19 15:27:02 +01:00
appChatsManager.kickFromChannel(this.chatId, this.participant).then(() => {
this.eventListener.removeEventListener('destroy', destroyListener);
2021-03-19 13:14:42 +01:00
this.close();
}, () => {
2021-03-19 15:27:02 +01:00
toggle();
2021-03-19 13:14:42 +01:00
});
},
isDanger: true
}])
2021-03-28 20:37:11 +02:00
}).show(); */
2021-03-19 13:14:42 +01:00
}, {listenerSetter: this.listenerSetter});
section.content.append(btnDelete);
this.scrollable.append(section.container);
}
}
}