Browse Source

Channel type editing

master
Eduard Kuzmenko 4 years ago
parent
commit
a6fb84d550
  1. 31
      src/components/sidebarRight/tabs/chatType.ts
  2. 199
      src/components/sidebarRight/tabs/editChannel.ts
  3. 164
      src/components/sidebarRight/tabs/editChat.ts
  4. 15
      src/components/sidebarRight/tabs/sharedMedia.ts

31
src/components/sidebarRight/tabs/groupType.ts → src/components/sidebarRight/tabs/chatType.ts

@ -22,34 +22,37 @@ import I18n from "../../../lib/langPack"; @@ -22,34 +22,37 @@ import I18n from "../../../lib/langPack";
import PopupPeer from "../../popups/peer";
import ButtonCorner from "../../buttonCorner";
export default class AppGroupTypeTab extends SliderSuperTabEventable {
public peerId: number;
export default class AppChatTypeTab extends SliderSuperTabEventable {
public chatId: number;
public chatFull: ChatFull;
protected init() {
this.container.classList.add('edit-peer-container', 'group-type-container');
this.setTitle('GroupType');
const isBroadcast = appChatsManager.isBroadcast(this.chatId);
this.setTitle(isBroadcast ? 'ChannelType' : 'GroupType');
const section = new SettingSection({
name: 'GroupType'
name: isBroadcast ? 'ChannelType' : 'GroupType'
});
const random = randomLong();
const privateRow = new Row({
radioField: new RadioField({
langKey: 'MegaPrivate',
langKey: isBroadcast ? 'ChannelPrivate' : 'MegaPrivate',
name: random,
value: 'private'
}),
subtitleLangKey: 'MegaPrivateInfo'
subtitleLangKey: isBroadcast ? 'ChannelPrivateInfo' : 'MegaPrivateInfo'
});
const publicRow = new Row({
radioField: new RadioField({
langKey: 'MegaPublic',
langKey: isBroadcast ? 'ChannelPublic' : 'MegaPublic',
name: random,
value: 'public'
}),
subtitleLangKey: 'MegaPublicInfo'
subtitleLangKey: isBroadcast ? 'ChannelPublicInfo' : 'MegaPublicInfo'
});
const form = RadioFormFromRows([privateRow, publicRow], (value) => {
const a = [privateSection, publicSection];
@ -61,7 +64,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable { @@ -61,7 +64,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable {
onChange();
});
const chat: Chat = appChatsManager.getChat(-this.peerId);
const chat: Chat = appChatsManager.getChat(this.chatId);
section.content.append(form);
@ -70,7 +73,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable { @@ -70,7 +73,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable {
//let revoked = false;
const linkRow = new Row({
title: (this.chatFull.exported_invite as ExportedChatInvite.chatInviteExported).link,
subtitleLangKey: 'MegaPrivateLinkHelp',
subtitleLangKey: isBroadcast ? 'ChannelPrivateLinkHelp' : 'MegaPrivateLinkHelp',
clickable: () => {
copyTextToClipboard((this.chatFull.exported_invite as ExportedChatInvite.chatInviteExported).link);
toast(I18n.format('LinkCopied', true));
@ -86,7 +89,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable { @@ -86,7 +89,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable {
callback: () => {
const toggle = toggleDisability([btnRevoke], true);
appProfileManager.getChatInviteLink(-this.peerId, true).then(link => {
appProfileManager.getChatInviteLink(this.chatId, true).then(link => {
toggle();
linkRow.title.innerHTML = link;
//revoked = true;
@ -102,7 +105,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable { @@ -102,7 +105,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable {
privateSection.content.append(linkRow.container, btnRevoke);
const publicSection = new SettingSection({
caption: 'Channel.UsernameAboutGroup',
caption: isBroadcast ? 'Channel.UsernameAboutChannel' : 'Channel.UsernameAboutGroup',
noDelimiter: true
});
@ -126,7 +129,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable { @@ -126,7 +129,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable {
invalidText: 'Link.Invalid',
takenText: 'Link.Taken',
onChange: onChange,
peerId: this.peerId,
peerId: -this.chatId,
head: placeholder
});
@ -141,7 +144,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable { @@ -141,7 +144,7 @@ export default class AppGroupTypeTab extends SliderSuperTabEventable {
attachClickEvent(applyBtn, () => {
/* const unsetLoader = */setButtonLoader(applyBtn);
const username = publicRow.radioField.checked ? linkInputField.getValue() : '';
appChatsManager.migrateChat(-this.peerId).then(channelId => {
appChatsManager.migrateChat(this.chatId).then(channelId => {
return appChatsManager.updateUsername(channelId, username);
}).then(() => {
//unsetLoader();

199
src/components/sidebarRight/tabs/editChannel.ts

@ -1,199 +0,0 @@ @@ -1,199 +0,0 @@
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import { SliderSuperTab } from "../../slider"
import InputField from "../../inputField";
import EditPeer from "../../editPeer";
import { SettingSection } from "../../sidebarLeft";
import Row from "../../row";
import CheckboxField from "../../checkboxField";
import Button from "../../button";
import appChatsManager from "../../../lib/appManagers/appChatsManager";
import appProfileManager from "../../../lib/appManagers/appProfileManager";
import { attachClickEvent, toggleDisability } from "../../../helpers/dom";
import PopupPeer from "../../popups/peer";
import { addCancelButton } from "../../popups";
import { i18n } from "../../../lib/langPack";
import { numberThousandSplitter } from "../../../helpers/number";
export default class AppEditChannelTab extends SliderSuperTab {
private nameInputField: InputField;
private descriptionInputField: InputField;
private editPeer: EditPeer;
public peerId: number;
protected async init() {
this.container.classList.add('edit-peer-container', 'edit-channel-container');
this.setTitle('Edit');
const chatFull = await appProfileManager.getChannelFull(-this.peerId, true);
{
const section = new SettingSection({noDelimiter: true});
if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
const inputFields: InputField[] = [];
const inputWrapper = document.createElement('div');
inputWrapper.classList.add('input-wrapper');
this.nameInputField = new InputField({
label: 'Channel.ChannelNameHolder',
name: 'channel-name',
maxLength: 255
});
this.descriptionInputField = new InputField({
label: 'DescriptionPlaceholder',
name: 'channel-description',
maxLength: 255
});
this.nameInputField.setOriginalValue(appChatsManager.getChat(-this.peerId).title);
this.descriptionInputField.setOriginalValue(chatFull.about);
inputWrapper.append(this.nameInputField.container, this.descriptionInputField.container);
inputFields.push(this.nameInputField, this.descriptionInputField);
this.editPeer = new EditPeer({
peerId: this.peerId,
inputFields,
listenerSetter: this.listenerSetter
});
this.content.append(this.editPeer.nextBtn);
section.content.append(this.editPeer.avatarEdit.container, inputWrapper);
attachClickEvent(this.editPeer.nextBtn, () => {
this.editPeer.nextBtn.disabled = true;
let promises: Promise<any>[] = [];
const id = -this.peerId;
if(this.nameInputField.isValid()) {
promises.push(appChatsManager.editTitle(id, this.nameInputField.value));
}
if(this.descriptionInputField.isValid()) {
promises.push(appChatsManager.editAbout(id, this.descriptionInputField.value));
}
if(this.editPeer.uploadAvatar) {
promises.push(this.editPeer.uploadAvatar().then(inputFile => {
return appChatsManager.editPhoto(id, inputFile);
}));
}
Promise.race(promises).finally(() => {
this.editPeer.nextBtn.removeAttribute('disabled');
this.close();
});
}, {listenerSetter: this.listenerSetter});
}
/* if(appChatsManager.hasRights(-this.peerId, 'change_type')) {
const channelTypeRow = new Row({
titleLangKey: 'ChannelType',
subtitleLangKey: 'TypePrivate',
clickable: true,
icon: 'lock'
});
section.content.append(channelTypeRow.container);
}
if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
const discussionRow = new Row({
titleLangKey: 'PeerInfo.Discussion',
subtitleLangKey: 'PeerInfo.Discussion.Add',
clickable: true,
icon: 'message'
});
section.content.append(discussionRow.container);
}
const administratorsRow = new Row({
titleLangKey: 'PeerInfo.Administrators',
subtitle: '' + chatFull.admins_count,
icon: 'admin',
clickable: true
});
section.content.append(administratorsRow.container);
if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
const signMessagesCheckboxField = new CheckboxField({
text: 'PeerInfo.SignMessages',
checked: false
});
section.content.append(signMessagesCheckboxField.label);
} */
this.scrollable.append(section.container);
}
/* {
const section = new SettingSection({
});
const subscribersRow = new Row({
titleLangKey: 'PeerInfo.Subscribers',
icon: 'newgroup',
clickable: true
});
subscribersRow.subtitle.append(i18n('Subscribers', [numberThousandSplitter(335356)]));
section.content.append(subscribersRow.container);
this.scrollable.append(section.container);
} */
if(appChatsManager.hasRights(-this.peerId, 'delete_chat')) {
const section = new SettingSection({
});
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'PeerInfo.DeleteChannel'});
attachClickEvent(btnDelete, () => {
new PopupPeer('popup-delete-channel', {
peerId: this.peerId,
titleLangKey: 'ChannelDeleteMenu',
descriptionLangKey: 'AreYouSureDeleteAndExitChannel',
buttons: addCancelButton([{
langKey: 'ChannelDeleteMenu',
callback: () => {
const toggle = toggleDisability([btnDelete], true);
},
isDanger: true
}, {
langKey: 'DeleteChannelForAll',
callback: () => {
const toggle = toggleDisability([btnDelete], true);
appChatsManager.deleteChannel(-this.peerId).then(() => {
this.close();
}, () => {
toggle();
});
},
isDanger: true
}])
}).show();
}, {listenerSetter: this.listenerSetter});
section.content.append(btnDelete);
this.scrollable.append(section.container);
}
}
}

164
src/components/sidebarRight/tabs/editGroup.ts → src/components/sidebarRight/tabs/editChat.ts

@ -13,15 +13,17 @@ import Button from "../../button"; @@ -13,15 +13,17 @@ import Button from "../../button";
import appChatsManager, { ChatRights } from "../../../lib/appManagers/appChatsManager";
import appProfileManager from "../../../lib/appManagers/appProfileManager";
import { attachClickEvent, toggleDisability } from "../../../helpers/dom";
import { ChatFull } from "../../../layer";
import AppGroupTypeTab from "./groupType";
import { Chat } from "../../../layer";
import AppChatTypeTab from "./chatType";
import rootScope from "../../../lib/rootScope";
import AppGroupPermissionsTab from "./groupPermissions";
import { i18n } from "../../../lib/langPack";
import { i18n, LangPackKey } from "../../../lib/langPack";
import PopupDeleteDialog from "../../popups/deleteDialog";
import { addCancelButton } from "../../popups";
import PopupPeer from "../../popups/peer";
export default class AppEditGroupTab extends SliderSuperTab {
private groupNameInputField: InputField;
export default class AppEditChatTab extends SliderSuperTab {
private chatNameInputField: InputField;
private descriptionInputField: InputField;
private editPeer: EditPeer;
public chatId: number;
@ -33,9 +35,13 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -33,9 +35,13 @@ export default class AppEditGroupTab extends SliderSuperTab {
this.container.classList.add('edit-peer-container', 'edit-group-container');
this.setTitle('Edit');
const chatFull = await appProfileManager.getChatFull(this.chatId, true);
const chat: Chat.chat | Chat.channel = appChatsManager.getChat(this.chatId);
const isBroadcast = appChatsManager.isBroadcast(this.chatId);
const isChannel = appChatsManager.isChannel(this.chatId);
{
const section = new SettingSection({noDelimiter: true});
const inputFields: InputField[] = [];
@ -43,26 +49,23 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -43,26 +49,23 @@ export default class AppEditGroupTab extends SliderSuperTab {
const inputWrapper = document.createElement('div');
inputWrapper.classList.add('input-wrapper');
this.groupNameInputField = new InputField({
label: 'CreateGroup.NameHolder',
name: 'group-name',
this.chatNameInputField = new InputField({
label: isBroadcast ? 'Channel.ChannelNameHolder' : 'CreateGroup.NameHolder',
name: 'chat-name',
maxLength: 255
});
this.descriptionInputField = new InputField({
label: 'DescriptionPlaceholder',
name: 'group-description',
name: 'chat-description',
maxLength: 255
});
const chat = appChatsManager.getChat(this.chatId);
this.groupNameInputField.setOriginalValue(chat.title);
this.chatNameInputField.setOriginalValue(chat.title);
this.descriptionInputField.setOriginalValue(chatFull.about);
inputWrapper.append(this.groupNameInputField.container, this.descriptionInputField.container);
inputWrapper.append(this.chatNameInputField.container, this.descriptionInputField.container);
inputFields.push(this.groupNameInputField, this.descriptionInputField);
inputFields.push(this.chatNameInputField, this.descriptionInputField);
this.editPeer = new EditPeer({
peerId: -this.chatId,
@ -74,29 +77,37 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -74,29 +77,37 @@ export default class AppEditGroupTab extends SliderSuperTab {
section.content.append(this.editPeer.avatarEdit.container, inputWrapper);
if(appChatsManager.hasRights(this.chatId, 'change_type')) {
const groupTypeRow = new Row({
titleLangKey: 'GroupType',
const chatTypeRow = new Row({
titleLangKey: isBroadcast ? 'ChannelType' : 'GroupType',
clickable: () => {
const tab = new AppGroupTypeTab(this.slider);
tab.peerId = -this.chatId;
const tab = new AppChatTypeTab(this.slider);
tab.chatId = this.chatId;
tab.chatFull = chatFull;
tab.open();
this.listenerSetter.add(tab.eventListener, 'destroy', setGroupTypeSubtitle);
this.listenerSetter.add(tab.eventListener, 'destroy', setChatTypeSubtitle);
},
icon: 'lock'
});
const setGroupTypeSubtitle = () => {
groupTypeRow.subtitle.textContent = '';
groupTypeRow.subtitle.append(i18n(chat.username ? 'TypePublicGroup' : 'TypePrivateGroup'));
const setChatTypeSubtitle = () => {
chatTypeRow.subtitle.textContent = '';
let key: LangPackKey;
if(isBroadcast) {
key = (chat as Chat.channel).username ? 'TypePublic' : 'TypePrivate';
} else {
key = (chat as Chat.channel).username ? 'TypePublicGroup' : 'TypePrivateGroup';
}
chatTypeRow.subtitle.append(i18n(key));
};
setGroupTypeSubtitle();
section.content.append(groupTypeRow.container);
setChatTypeSubtitle();
section.content.append(chatTypeRow.container);
}
if(appChatsManager.hasRights(this.chatId, 'change_permissions')) {
if(appChatsManager.hasRights(this.chatId, 'change_permissions') && !isBroadcast) {
const flags = [
'send_messages',
'send_media',
@ -149,8 +160,8 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -149,8 +160,8 @@ export default class AppEditGroupTab extends SliderSuperTab {
let promises: Promise<any>[] = [];
const id = this.chatId;
if(this.groupNameInputField.isValid()) {
promises.push(appChatsManager.editTitle(id, this.groupNameInputField.value));
if(this.chatNameInputField.isValid()) {
promises.push(appChatsManager.editTitle(id, this.chatNameInputField.value));
}
if(this.descriptionInputField.isValid()) {
@ -168,6 +179,36 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -168,6 +179,36 @@ export default class AppEditGroupTab extends SliderSuperTab {
this.close();
});
}, {listenerSetter: this.listenerSetter});
/*
if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
const discussionRow = new Row({
titleLangKey: 'PeerInfo.Discussion',
subtitleLangKey: 'PeerInfo.Discussion.Add',
clickable: true,
icon: 'message'
});
section.content.append(discussionRow.container);
}
const administratorsRow = new Row({
titleLangKey: 'PeerInfo.Administrators',
subtitle: '' + chatFull.admins_count,
icon: 'admin',
clickable: true
});
section.content.append(administratorsRow.container);
if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
const signMessagesCheckboxField = new CheckboxField({
text: 'PeerInfo.SignMessages',
checked: false
});
section.content.append(signMessagesCheckboxField.label);
} */
}
/* {
@ -176,12 +217,13 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -176,12 +217,13 @@ export default class AppEditGroupTab extends SliderSuperTab {
});
const membersRow = new Row({
titleLangKey: 'GroupMembers',
subtitle: '2 500',
titleLangKey: isBroadcast ? 'PeerInfo.Subscribers' : 'GroupMembers',
icon: 'newgroup',
clickable: true
});
membersRow.subtitle.append(i18n('Subscribers', [numberThousandSplitter(335356)]));
section.content.append(membersRow.container);
if(appChatsManager.hasRights(this.chatId, 'change_permissions')) {
@ -203,17 +245,45 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -203,17 +245,45 @@ export default class AppEditGroupTab extends SliderSuperTab {
if(appChatsManager.hasRights(this.chatId, 'delete_chat')) {
const section = new SettingSection({});
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: 'DeleteMega'});
const btnDelete = Button('btn-primary btn-transparent danger', {icon: 'delete', text: isBroadcast ? 'PeerInfo.DeleteChannel' : 'DeleteMega'});
attachClickEvent(btnDelete, () => {
new PopupDeleteDialog(-this.chatId, undefined, (promise) => {
const toggle = toggleDisability([btnDelete], true);
promise.then(() => {
this.close();
}, () => {
toggle();
if(isBroadcast) {
new PopupPeer('popup-delete-channel', {
peerId: -this.chatId,
titleLangKey: 'ChannelDeleteMenu',
descriptionLangKey: 'AreYouSureDeleteAndExitChannel',
buttons: addCancelButton([{
langKey: 'ChannelDeleteMenu',
callback: () => {
const toggle = toggleDisability([btnDelete], true);
},
isDanger: true
}, {
langKey: 'DeleteChannelForAll',
callback: () => {
const toggle = toggleDisability([btnDelete], true);
appChatsManager.deleteChannel(this.chatId).then(() => {
this.close();
}, () => {
toggle();
});
},
isDanger: true
}])
}).show();
} else {
new PopupDeleteDialog(-this.chatId, undefined, (promise) => {
const toggle = toggleDisability([btnDelete], true);
promise.then(() => {
this.close();
}, () => {
toggle();
});
});
});
}
}, {listenerSetter: this.listenerSetter});
section.content.append(btnDelete);
@ -221,13 +291,15 @@ export default class AppEditGroupTab extends SliderSuperTab { @@ -221,13 +291,15 @@ export default class AppEditGroupTab extends SliderSuperTab {
this.scrollable.append(section.container);
}
// ! this one will fire earlier than tab's closeAfterTimeout (destroy) event and listeners will be erased, so destroy won't fire
this.listenerSetter.add(rootScope, 'dialog_migrate', ({migrateFrom, migrateTo}) => {
if(-this.chatId === migrateFrom) {
this.chatId = -migrateTo;
this._init();
}
});
if(!isChannel) {
// ! this one will fire earlier than tab's closeAfterTimeout (destroy) event and listeners will be erased, so destroy won't fire
this.listenerSetter.add(rootScope, 'dialog_migrate', ({migrateFrom, migrateTo}) => {
if(-this.chatId === migrateFrom) {
this.chatId = -migrateTo;
this._init();
}
});
}
}
protected init() {

15
src/components/sidebarRight/tabs/sharedMedia.ts

@ -19,9 +19,8 @@ import { attachClickEvent, replaceContent, cancelEvent } from "../../../helpers/ @@ -19,9 +19,8 @@ import { attachClickEvent, replaceContent, cancelEvent } from "../../../helpers/
import appSidebarRight from "..";
import { TransitionSlider } from "../../transition";
import appNotificationsManager from "../../../lib/appManagers/appNotificationsManager";
import AppEditGroupTab from "./editGroup";
import AppEditChatTab from "./editChat";
import PeerTitle from "../../peerTitle";
import AppEditChannelTab from "./editChannel";
import AppEditContactTab from "./editContact";
import appChatsManager, { Channel } from "../../../lib/appManagers/appChatsManager";
import { Chat, Message, MessageAction, ChatFull, Photo } from "../../../layer";
@ -854,17 +853,15 @@ export default class AppSharedMediaTab extends SliderSuperTab { @@ -854,17 +853,15 @@ export default class AppSharedMediaTab extends SliderSuperTab {
});
attachClickEvent(this.editBtn, (e) => {
let tab: AppEditGroupTab | AppEditChannelTab | AppEditContactTab;
if(appPeersManager.isAnyGroup(this.peerId)) {
tab = new AppEditGroupTab(appSidebarRight);
} else if(this.peerId > 0) {
tab = new AppEditContactTab(appSidebarRight);
let tab: AppEditChatTab | AppEditContactTab;
if(this.peerId < 0) {
tab = new AppEditChatTab(appSidebarRight);
} else {
tab = new AppEditChannelTab(appSidebarRight);
tab = new AppEditContactTab(appSidebarRight);
}
if(tab) {
if(tab instanceof AppEditGroupTab) {
if(tab instanceof AppEditChatTab) {
tab.chatId = -this.peerId;
} else {
tab.peerId = this.peerId;

Loading…
Cancel
Save