Edit channel & group respect rights
This commit is contained in:
parent
3a256f20f1
commit
774dcce528
@ -25,6 +25,8 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
|
|
||||||
{
|
{
|
||||||
const section = new SettingSection({noDelimiter: true});
|
const section = new SettingSection({noDelimiter: true});
|
||||||
|
|
||||||
|
if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
|
||||||
const inputFields: InputField[] = [];
|
const inputFields: InputField[] = [];
|
||||||
|
|
||||||
const inputWrapper = document.createElement('div');
|
const inputWrapper = document.createElement('div');
|
||||||
@ -56,28 +58,7 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
});
|
});
|
||||||
this.content.append(this.editPeer.nextBtn);
|
this.content.append(this.editPeer.nextBtn);
|
||||||
|
|
||||||
const groupTypeRow = new Row({
|
section.content.append(this.editPeer.avatarEdit.container, inputWrapper);
|
||||||
title: 'Channel Type',
|
|
||||||
subtitle: 'Private',
|
|
||||||
clickable: true,
|
|
||||||
icon: 'lock'
|
|
||||||
});
|
|
||||||
|
|
||||||
const administratorsRow = new Row({
|
|
||||||
title: 'Administrators',
|
|
||||||
subtitle: '5',
|
|
||||||
icon: 'admin',
|
|
||||||
clickable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
const signMessagesCheckboxField = new CheckboxField({
|
|
||||||
text: 'Sign Messages',
|
|
||||||
checked: false
|
|
||||||
});
|
|
||||||
|
|
||||||
section.content.append(this.editPeer.avatarEdit.container, inputWrapper, groupTypeRow.container, administratorsRow.container, signMessagesCheckboxField.label);
|
|
||||||
|
|
||||||
this.scrollable.append(section.container);
|
|
||||||
|
|
||||||
attachClickEvent(this.editPeer.nextBtn, () => {
|
attachClickEvent(this.editPeer.nextBtn, () => {
|
||||||
this.editPeer.nextBtn.disabled = true;
|
this.editPeer.nextBtn.disabled = true;
|
||||||
@ -106,6 +87,49 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
}, {listenerSetter: this.listenerSetter});
|
}, {listenerSetter: this.listenerSetter});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(appChatsManager.hasRights(-this.peerId, 'change_type')) {
|
||||||
|
const channelTypeRow = new Row({
|
||||||
|
title: 'Channel Type',
|
||||||
|
subtitle: 'Private',
|
||||||
|
clickable: true,
|
||||||
|
icon: 'lock'
|
||||||
|
});
|
||||||
|
|
||||||
|
section.content.append(channelTypeRow.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(appChatsManager.hasRights(-this.peerId, 'change_info')) {
|
||||||
|
const discussionRow = new Row({
|
||||||
|
title: 'Discussion',
|
||||||
|
subtitle: 'Add',
|
||||||
|
clickable: true,
|
||||||
|
icon: 'message'
|
||||||
|
});
|
||||||
|
|
||||||
|
section.content.append(discussionRow.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
const administratorsRow = new Row({
|
||||||
|
title: '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: 'Sign Messages',
|
||||||
|
checked: false
|
||||||
|
});
|
||||||
|
|
||||||
|
section.content.append(signMessagesCheckboxField.label);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scrollable.append(section.container);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const section = new SettingSection({
|
const section = new SettingSection({
|
||||||
|
|
||||||
@ -123,7 +147,7 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
this.scrollable.append(section.container);
|
this.scrollable.append(section.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if(appChatsManager.hasRights(-this.peerId, 'delete_chat')) {
|
||||||
const section = new SettingSection({
|
const section = new SettingSection({
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -133,7 +157,7 @@ export default class AppEditChannelTab extends SliderSuperTab {
|
|||||||
attachClickEvent(btnDelete, () => {
|
attachClickEvent(btnDelete, () => {
|
||||||
new PopupPeer('popup-delete-channel', {
|
new PopupPeer('popup-delete-channel', {
|
||||||
peerId: this.peerId,
|
peerId: this.peerId,
|
||||||
title: 'Delete Group?',
|
title: 'Delete Channel?',
|
||||||
description: `Are you sure you want to delete this channel? All subscribers will be removed and all messages will be lost.`,
|
description: `Are you sure you want to delete this channel? All subscribers will be removed and all messages will be lost.`,
|
||||||
buttons: addCancelButton([{
|
buttons: addCancelButton([{
|
||||||
text: 'DELETE',
|
text: 'DELETE',
|
||||||
|
@ -57,8 +57,9 @@ 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);
|
section.content.append(this.editPeer.avatarEdit.container, inputWrapper);
|
||||||
|
|
||||||
|
if(appChatsManager.hasRights(-this.peerId, 'change_type')) {
|
||||||
const groupTypeRow = new Row({
|
const groupTypeRow = new Row({
|
||||||
title: 'Group Type',
|
title: 'Group Type',
|
||||||
subtitle: 'Private',
|
subtitle: 'Private',
|
||||||
@ -66,6 +67,10 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
icon: 'lock'
|
icon: 'lock'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
section.content.append(groupTypeRow.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(appChatsManager.hasRights(-this.peerId, 'change_permissions')) {
|
||||||
const permissionsRow = new Row({
|
const permissionsRow = new Row({
|
||||||
title: 'Permissions',
|
title: 'Permissions',
|
||||||
subtitle: '8/8',
|
subtitle: '8/8',
|
||||||
@ -73,6 +78,9 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
clickable: true
|
clickable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
section.content.append(permissionsRow.container);
|
||||||
|
}
|
||||||
|
|
||||||
const administratorsRow = new Row({
|
const administratorsRow = new Row({
|
||||||
title: 'Administrators',
|
title: 'Administrators',
|
||||||
subtitle: '' + ((chatFull as ChatFull.channelFull).admins_count || 1),
|
subtitle: '' + ((chatFull as ChatFull.channelFull).admins_count || 1),
|
||||||
@ -80,7 +88,7 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
clickable: true
|
clickable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
section.content.append(this.editPeer.avatarEdit.container, inputWrapper, groupTypeRow.container, permissionsRow.container, administratorsRow.container);
|
section.content.append(administratorsRow.container);
|
||||||
|
|
||||||
this.scrollable.append(section.container);
|
this.scrollable.append(section.container);
|
||||||
|
|
||||||
@ -123,6 +131,9 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
clickable: true
|
clickable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
section.content.append(membersRow.container);
|
||||||
|
|
||||||
|
if(appChatsManager.hasRights(-this.peerId, 'change_permissions')) {
|
||||||
const showChatHistoryCheckboxField = new CheckboxField({
|
const showChatHistoryCheckboxField = new CheckboxField({
|
||||||
text: 'Show chat history for new members'
|
text: 'Show chat history for new members'
|
||||||
});
|
});
|
||||||
@ -131,12 +142,13 @@ export default class AppEditGroupTab extends SliderSuperTab {
|
|||||||
showChatHistoryCheckboxField.value = true;
|
showChatHistoryCheckboxField.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
section.content.append(membersRow.container, showChatHistoryCheckboxField.label);
|
section.content.append(showChatHistoryCheckboxField.label);
|
||||||
|
}
|
||||||
|
|
||||||
this.scrollable.append(section.container);
|
this.scrollable.append(section.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(appChatsManager.isChannel(-this.peerId)) {
|
if(appChatsManager.isChannel(-this.peerId) && appChatsManager.hasRights(-this.peerId, 'delete_chat')) {
|
||||||
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'});
|
||||||
|
@ -19,6 +19,8 @@ import AppEditGroupTab from "./editGroup";
|
|||||||
import PeerTitle from "../../peerTitle";
|
import PeerTitle from "../../peerTitle";
|
||||||
import AppEditChannelTab from "./editChannel";
|
import AppEditChannelTab from "./editChannel";
|
||||||
import AppEditContactTab from "./editContact";
|
import AppEditContactTab from "./editContact";
|
||||||
|
import appChatsManager from "../../../lib/appManagers/appChatsManager";
|
||||||
|
import { Chat } from "../../../layer";
|
||||||
|
|
||||||
let setText = (text: string, el: HTMLDivElement) => {
|
let setText = (text: string, el: HTMLDivElement) => {
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
@ -207,7 +209,7 @@ export default class AppSharedMediaTab implements SliderTab {
|
|||||||
|
|
||||||
const peerId = this.peerId;
|
const peerId = this.peerId;
|
||||||
if(needClear) {
|
if(needClear) {
|
||||||
this.profileElements.subtitle.innerHTML = '';
|
this.profileElements.subtitle.innerHTML = ''; // ! HERE U CAN FIND WHITESPACE
|
||||||
}
|
}
|
||||||
|
|
||||||
appImManager.getPeerStatus(this.peerId).then((subtitle) => {
|
appImManager.getPeerStatus(this.peerId).then((subtitle) => {
|
||||||
@ -215,7 +217,7 @@ export default class AppSharedMediaTab implements SliderTab {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.profileElements.subtitle.innerHTML = subtitle;
|
this.profileElements.subtitle.innerHTML = subtitle || '';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -368,7 +370,16 @@ export default class AppSharedMediaTab implements SliderTab {
|
|||||||
dialog: true
|
dialog: true
|
||||||
}).element);
|
}).element);
|
||||||
|
|
||||||
|
if(peerId > 0) {
|
||||||
|
if(peerId !== rootScope.myId && appUsersManager.isContact(peerId)) {
|
||||||
this.editBtn.style.display = '';
|
this.editBtn.style.display = '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const chat: Chat = appChatsManager.getChat(-peerId);
|
||||||
|
if(chat._ === 'chat' || (chat as Chat.channel).admin_rights) {
|
||||||
|
this.editBtn.style.display = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.setPeerStatus(true);
|
this.setPeerStatus(true);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import appUsersManager from "./appUsersManager";
|
|||||||
|
|
||||||
export type Channel = Chat.channel;
|
export type Channel = Chat.channel;
|
||||||
|
|
||||||
export type ChatRights = 'send' | 'edit_title' | 'edit_photo' | 'invite' | 'pin' | 'deleteRevoke' | 'delete';
|
export type ChatRights = 'send' | 'change_info' | 'change_permissions' | 'change_type' | 'pin_messages' | 'deleteRevoke' | 'delete_chat';
|
||||||
|
|
||||||
export type UserTyping = Partial<{userId: number, action: SendMessageAction, timeout: number}>;
|
export type UserTyping = Partial<{userId: number, action: SendMessageAction, timeout: number}>;
|
||||||
|
|
||||||
@ -172,13 +172,13 @@ export class AppChatsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public hasRights(id: number, action: ChatRights, flag?: keyof ChatBannedRights['pFlags']) {
|
public hasRights(id: number, action: ChatRights, flag?: keyof ChatBannedRights['pFlags']) {
|
||||||
const chat = this.getChat(id);
|
const chat: Chat = this.getChat(id);
|
||||||
if(chat._ === 'chatEmpty') return false;
|
if(chat._ === 'chatEmpty') return false;
|
||||||
|
|
||||||
if(chat._ === 'chatForbidden' ||
|
if(chat._ === 'chatForbidden' ||
|
||||||
chat._ === 'channelForbidden' ||
|
chat._ === 'channelForbidden' ||
|
||||||
chat.pFlags.kicked ||
|
(chat as Chat.chat).pFlags.kicked ||
|
||||||
(chat.pFlags.left && !chat.pFlags.megagroup)) {
|
(chat.pFlags.left && !(chat as Chat.channel).pFlags.megagroup)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,19 +186,23 @@ export class AppChatsManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rights = chat.admin_rights || chat.banned_rights || chat.default_banned_rights;
|
const rights = chat.admin_rights || (chat as Chat.channel).banned_rights || chat.default_banned_rights;
|
||||||
let myFlags: {[flag in keyof ChatBannedRights['pFlags'] | keyof ChatAdminRights['pFlags']]: true};
|
if(!rights) {
|
||||||
if(rights) myFlags = rights.pFlags;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let myFlags: Partial<{[flag in keyof ChatBannedRights['pFlags'] | keyof ChatAdminRights['pFlags']]: true}> = {};
|
||||||
|
if(rights) myFlags = rights.pFlags as any;
|
||||||
|
|
||||||
switch(action) {
|
switch(action) {
|
||||||
// good
|
// good
|
||||||
case 'send': {
|
case 'send': {
|
||||||
if(flag && myFlags && myFlags[flag]) {
|
if(flag && myFlags[flag]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chat._ === 'channel') {
|
if(chat._ === 'channel') {
|
||||||
if((!chat.pFlags.megagroup && !myFlags?.post_messages)) {
|
if((!chat.pFlags.megagroup && !myFlags.post_messages)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,49 +210,27 @@ export class AppChatsManager {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// good
|
// * revoke foreign messages
|
||||||
case 'deleteRevoke': {
|
case 'deleteRevoke': {
|
||||||
if(chat._ === 'channel') {
|
return !!myFlags.delete_messages;
|
||||||
return !!myFlags?.delete_messages;
|
}
|
||||||
} else if(!chat.pFlags.admin) {
|
|
||||||
|
case 'pin_messages': {
|
||||||
|
return rights._ === 'chatAdminRights' ? myFlags[action] || !!myFlags.post_messages : !myFlags[action];
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'change_info': {
|
||||||
|
return rights._ === 'chatAdminRights' ? myFlags[action] : !myFlags[action];
|
||||||
|
}
|
||||||
|
|
||||||
|
// * only creator can do that
|
||||||
|
case 'change_type':
|
||||||
|
case 'delete_chat': {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case 'change_permissions': {
|
||||||
}
|
return rights._ === 'chatAdminRights' && myFlags['ban_users'];
|
||||||
|
|
||||||
// good
|
|
||||||
case 'pin': {
|
|
||||||
if(chat._ === 'channel') {
|
|
||||||
return chat.admin_rights ? !!myFlags.pin_messages || !!myFlags.post_messages : myFlags && !myFlags.pin_messages;
|
|
||||||
} else {
|
|
||||||
if(myFlags?.pin_messages && !chat.pFlags.admin) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'edit_title':
|
|
||||||
case 'edit_photo':
|
|
||||||
case 'invite': {
|
|
||||||
if(chat._ === 'channel') {
|
|
||||||
if(chat.pFlags.megagroup) {
|
|
||||||
if(!(action === 'invite' && chat.pFlags.democracy)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(chat.pFlags.admins_enabled &&
|
|
||||||
!chat.pFlags.admin) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export class AppPeersManager {
|
|||||||
} */
|
} */
|
||||||
|
|
||||||
public canPinMessage(peerId: number) {
|
public canPinMessage(peerId: number) {
|
||||||
return peerId > 0 || appChatsManager.hasRights(-peerId, 'pin');
|
return peerId > 0 || appChatsManager.hasRights(-peerId, 'pin_messages');
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPeerPhoto(peerId: number) {
|
public getPeerPhoto(peerId: number) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user