Delete channel, group
This commit is contained in:
parent
9d5dcc0e4a
commit
166f63b5f8
@ -7,7 +7,9 @@ import CheckboxField from "../../checkboxField";
|
|||||||
import Button from "../../button";
|
import Button from "../../button";
|
||||||
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
||||||
import appProfileManager from "../../../lib/appManagers/appProfileManager";
|
import appProfileManager from "../../../lib/appManagers/appProfileManager";
|
||||||
import { attachClickEvent } from "../../../helpers/dom";
|
import { attachClickEvent, toggleDisability } from "../../../helpers/dom";
|
||||||
|
import PopupPeer from "../../popups/peer";
|
||||||
|
import { addCancelButton } from "../../popups";
|
||||||
|
|
||||||
export default class AppEditChannelTab extends SliderSuperTab {
|
export default class AppEditChannelTab extends SliderSuperTab {
|
||||||
private nameInputField: InputField;
|
private nameInputField: InputField;
|
||||||
@ -15,10 +17,12 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
private editPeer: EditPeer;
|
private editPeer: EditPeer;
|
||||||
public peerId: number;
|
public peerId: number;
|
||||||
|
|
||||||
protected init() {
|
protected async init() {
|
||||||
this.container.classList.add('edit-peer-container', 'edit-channel-container');
|
this.container.classList.add('edit-peer-container', 'edit-channel-container');
|
||||||
this.title.innerHTML = 'Edit';
|
this.title.innerHTML = 'Edit';
|
||||||
|
|
||||||
|
const chatFull = await appProfileManager.getChannelFull(-this.peerId, true);
|
||||||
|
|
||||||
{
|
{
|
||||||
const section = new SettingSection({noDelimiter: true});
|
const section = new SettingSection({noDelimiter: true});
|
||||||
const inputFields: InputField[] = [];
|
const inputFields: InputField[] = [];
|
||||||
@ -39,9 +43,7 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
|
|
||||||
this.nameInputField.setOriginalValue(appChatsManager.getChat(-this.peerId).title);
|
this.nameInputField.setOriginalValue(appChatsManager.getChat(-this.peerId).title);
|
||||||
|
|
||||||
appProfileManager.getChatFull(-this.peerId).then(chatFull => {
|
this.descriptionInputField.setOriginalValue(chatFull.about);
|
||||||
this.descriptionInputField.setOriginalValue(chatFull.about);
|
|
||||||
});
|
|
||||||
|
|
||||||
inputWrapper.append(this.nameInputField.container, this.descriptionInputField.container);
|
inputWrapper.append(this.nameInputField.container, this.descriptionInputField.container);
|
||||||
|
|
||||||
@ -128,6 +130,27 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
|
|
||||||
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'Delete Channel'});
|
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'Delete Channel'});
|
||||||
|
|
||||||
|
attachClickEvent(btnDelete, () => {
|
||||||
|
new PopupPeer('popup-delete-channel', {
|
||||||
|
peerId: this.peerId,
|
||||||
|
title: 'Delete Group?',
|
||||||
|
description: `Are you sure you want to delete this channel? All subscribers will be removed and all messages will be lost.`,
|
||||||
|
buttons: addCancelButton([{
|
||||||
|
text: 'DELETE',
|
||||||
|
callback: () => {
|
||||||
|
toggleDisability([btnDelete], true);
|
||||||
|
|
||||||
|
appChatsManager.deleteChannel(-this.peerId).then(() => {
|
||||||
|
this.close();
|
||||||
|
}, () => {
|
||||||
|
toggleDisability([btnDelete], false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
isDanger: true
|
||||||
|
}])
|
||||||
|
}).show();
|
||||||
|
}, {listenerSetter: this.listenerSetter});
|
||||||
|
|
||||||
section.content.append(btnDelete);
|
section.content.append(btnDelete);
|
||||||
|
|
||||||
this.scrollable.append(section.container);
|
this.scrollable.append(section.container);
|
||||||
|
@ -7,7 +7,10 @@ import CheckboxField from "../../checkboxField";
|
|||||||
import Button from "../../button";
|
import Button from "../../button";
|
||||||
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
||||||
import appProfileManager from "../../../lib/appManagers/appProfileManager";
|
import appProfileManager from "../../../lib/appManagers/appProfileManager";
|
||||||
import { attachClickEvent } from "../../../helpers/dom";
|
import { attachClickEvent, toggleDisability } from "../../../helpers/dom";
|
||||||
|
import { ChatFull } from "../../../layer";
|
||||||
|
import PopupPeer from "../../popups/peer";
|
||||||
|
import { addCancelButton } from "../../popups";
|
||||||
|
|
||||||
export default class AppEditGroupTab extends SliderSuperTab {
|
export default class AppEditGroupTab extends SliderSuperTab {
|
||||||
private groupNameInputField: InputField;
|
private groupNameInputField: InputField;
|
||||||
@ -15,10 +18,12 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
private editPeer: EditPeer;
|
private editPeer: EditPeer;
|
||||||
public peerId: number;
|
public peerId: number;
|
||||||
|
|
||||||
protected init() {
|
protected async init() {
|
||||||
this.container.classList.add('edit-peer-container', 'edit-group-container');
|
this.container.classList.add('edit-peer-container', 'edit-group-container');
|
||||||
this.title.innerHTML = 'Edit';
|
this.title.innerHTML = 'Edit';
|
||||||
|
|
||||||
|
const chatFull = await appProfileManager.getChatFull(-this.peerId, true);
|
||||||
|
|
||||||
{
|
{
|
||||||
const section = new SettingSection({noDelimiter: true});
|
const section = new SettingSection({noDelimiter: true});
|
||||||
const inputFields: InputField[] = [];
|
const inputFields: InputField[] = [];
|
||||||
@ -39,9 +44,7 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
|
|
||||||
this.groupNameInputField.setOriginalValue(appChatsManager.getChat(-this.peerId).title);
|
this.groupNameInputField.setOriginalValue(appChatsManager.getChat(-this.peerId).title);
|
||||||
|
|
||||||
appProfileManager.getChatFull(-this.peerId).then(chatFull => {
|
this.descriptionInputField.setOriginalValue(chatFull.about);
|
||||||
this.descriptionInputField.setOriginalValue(chatFull.about);
|
|
||||||
});
|
|
||||||
|
|
||||||
inputWrapper.append(this.groupNameInputField.container, this.descriptionInputField.container);
|
inputWrapper.append(this.groupNameInputField.container, this.descriptionInputField.container);
|
||||||
|
|
||||||
@ -54,6 +57,8 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
});
|
});
|
||||||
this.content.append(this.editPeer.nextBtn);
|
this.content.append(this.editPeer.nextBtn);
|
||||||
|
|
||||||
|
//section.content.append(this.editPeer.avatarEdit.container, inputWrapper);
|
||||||
|
|
||||||
const groupTypeRow = new Row({
|
const groupTypeRow = new Row({
|
||||||
title: 'Group Type',
|
title: 'Group Type',
|
||||||
subtitle: 'Private',
|
subtitle: 'Private',
|
||||||
@ -70,7 +75,7 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
|
|
||||||
const administratorsRow = new Row({
|
const administratorsRow = new Row({
|
||||||
title: 'Administrators',
|
title: 'Administrators',
|
||||||
subtitle: '5',
|
subtitle: '' + ((chatFull as ChatFull.channelFull).admins_count || 1),
|
||||||
icon: 'admin',
|
icon: 'admin',
|
||||||
clickable: true
|
clickable: true
|
||||||
});
|
});
|
||||||
@ -119,22 +124,44 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const showChatHistoryCheckboxField = new CheckboxField({
|
const showChatHistoryCheckboxField = new CheckboxField({
|
||||||
text: 'Show chat history for new members',
|
text: 'Show chat history for new members'
|
||||||
checked: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(appChatsManager.isChannel(-this.peerId) && !(chatFull as ChatFull.channelFull).pFlags.hidden_prehistory) {
|
||||||
|
showChatHistoryCheckboxField.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
section.content.append(membersRow.container, showChatHistoryCheckboxField.label);
|
section.content.append(membersRow.container, showChatHistoryCheckboxField.label);
|
||||||
|
|
||||||
this.scrollable.append(section.container);
|
this.scrollable.append(section.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if(appChatsManager.isChannel(-this.peerId)) {
|
||||||
const section = new SettingSection({
|
const section = new SettingSection({});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'Delete Group'});
|
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'Delete Group'});
|
||||||
|
|
||||||
|
attachClickEvent(btnDelete, () => {
|
||||||
|
new PopupPeer('popup-delete-group', {
|
||||||
|
peerId: this.peerId,
|
||||||
|
title: 'Delete Group?',
|
||||||
|
description: `Are you sure you want to delete this group? All members will be removed, and all messages will be lost.`,
|
||||||
|
buttons: addCancelButton([{
|
||||||
|
text: 'DELETE',
|
||||||
|
callback: () => {
|
||||||
|
toggleDisability([btnDelete], true);
|
||||||
|
|
||||||
|
appChatsManager.deleteChannel(-this.peerId).then(() => {
|
||||||
|
this.close();
|
||||||
|
}, () => {
|
||||||
|
toggleDisability([btnDelete], false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
isDanger: true
|
||||||
|
}])
|
||||||
|
}).show();
|
||||||
|
}, {listenerSetter: this.listenerSetter});
|
||||||
|
|
||||||
section.content.append(btnDelete);
|
section.content.append(btnDelete);
|
||||||
|
|
||||||
this.scrollable.append(section.container);
|
this.scrollable.append(section.container);
|
||||||
|
@ -531,6 +531,18 @@ export class AppChatsManager {
|
|||||||
return this.isChannel(id) ? this.leaveChannel(id) : this.leaveChat(id);
|
return this.isChannel(id) ? this.leaveChannel(id) : this.leaveChat(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteChannel(id: number) {
|
||||||
|
return apiManager.invokeApi('channels.deleteChannel', {
|
||||||
|
channel: this.getChannelInput(id)
|
||||||
|
}).then(this.onChatUpdated.bind(this, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public migrateChat(id: number) {
|
||||||
|
return apiManager.invokeApi('messages.migrateChat', {
|
||||||
|
chat_id: id
|
||||||
|
}).then(this.onChatUpdated.bind(this, id));
|
||||||
|
}
|
||||||
|
|
||||||
public editPhoto(id: number, inputFile: InputFile) {
|
public editPhoto(id: number, inputFile: InputFile) {
|
||||||
const inputChatPhoto: InputChatPhoto = {
|
const inputChatPhoto: InputChatPhoto = {
|
||||||
_: 'inputChatUploadedPhoto',
|
_: 'inputChatUploadedPhoto',
|
||||||
|
Loading…
Reference in New Issue
Block a user