From 9dd8db8d61c7bbf4238e34e56023081cc222cc6f Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Sun, 20 Feb 2022 22:15:49 +0200 Subject: [PATCH] Restrict toggling some public permissions --- .../sidebarRight/tabs/groupPermissions.ts | 18 ++++++++++++++---- src/lang.ts | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/sidebarRight/tabs/groupPermissions.ts b/src/components/sidebarRight/tabs/groupPermissions.ts index 2f70977e..6cd64caf 100644 --- a/src/components/sidebarRight/tabs/groupPermissions.ts +++ b/src/components/sidebarRight/tabs/groupPermissions.ts @@ -54,10 +54,11 @@ export class ChatPermissions { 'send_messages': ['send_media', 'send_stickers', 'send_polls', 'embed_links'] }; - const chat: Chat.chat = appChatsManager.getChat(options.chatId); + const chat: Chat.chat | Chat.channel = appChatsManager.getChat(options.chatId); const defaultBannedRights = chat.default_banned_rights; const rights = options.participant ? appChatsManager.combineParticipantBannedRights(options.chatId, options.participant.banned_rights) : defaultBannedRights; + const restrictionText: LangPackKey = options.participant ? 'UserRestrictionsDisabled' : 'EditCantEditPermissionsPublic'; for(const info of this.v) { const mainFlag = info.flags[0]; info.checkboxField = new CheckboxField({ @@ -67,8 +68,17 @@ export class ChatPermissions { withRipple: true }); - // @ts-ignore - if(options.participant && defaultBannedRights.pFlags[mainFlag]) { + if(( + options.participant && + defaultBannedRights.pFlags[mainFlag as keyof typeof defaultBannedRights['pFlags']] + ) || ( + (chat as Chat.channel).username && + ( + info.flags.includes('pin_messages') || + info.flags.includes('change_info') + ) + ) + ) { info.checkboxField.input.disabled = true; /* options.listenerSetter.add(info.checkboxField.input)('change', (e) => { @@ -82,7 +92,7 @@ export class ChatPermissions { }); */ attachClickEvent(info.checkboxField.label, (e) => { - toast(I18n.format('UserRestrictionsDisabled', true)); + toast(I18n.format(restrictionText, true)); }, {listenerSetter: options.listenerSetter}); } diff --git a/src/lang.ts b/src/lang.ts index b4986e40..03a7a204 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -680,6 +680,7 @@ const lang = { "SendMessageAsTitle": "Send message as...", "Devices": "Devices", "LanguageName": "English", + "EditCantEditPermissionsPublic": "This permission is not available in public groups.", // * macos "AccountSettings.Filters": "Chat Folders",