diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index a906c0b3d..a2834502e 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -666,6 +666,7 @@ export function selectAllowedMessageActionsSlow( return {}; } + const chatFullInfo = selectChatFullInfo(global, message.chatId); const isPrivate = isUserId(chat.id); const isChatWithSelf = selectIsChatWithSelf(global, message.chatId); const isBasicGroup = isChatBasicGroup(chat); @@ -684,18 +685,35 @@ export function selectAllowedMessageActionsSlow( const isBoostMessage = message.content.action?.type === 'boostApply'; const isMonoforum = chat.isMonoforum; - const hasChatPinPermission = (chat.isCreator - || (!isChannel && !isUserRightBanned(chat, 'pinMessages')) - || getHasAdminRight(chat, 'pinMessages')); + // https://github.com/telegramdesktop/tdesktop/blob/6627de646022af1394134974477109cd1439e1bb/Telegram/SourceFiles/data/data_peer_values.cpp#L367C2-L372C3 + const canPinMessage = (() => { + if (isPrivate || chat.isCreator) return true; - const hasPinPermission = isPrivate || hasChatPinPermission; + if (isChannel) { + return getHasAdminRight(chat, 'editMessages'); + } + + const hasPinMessageRight = getHasAdminRight(chat, 'pinMessages'); + const isPinMessageRightBanned = isUserRightBanned(chat, 'pinMessages', chatFullInfo); + + if (isSuperGroup) { + const hasUsernameOrGeo = chat.hasUsername || chat.hasGeo; + return (hasPinMessageRight || !hasUsernameOrGeo) && !isPinMessageRightBanned; + } + + if (isBasicGroup) { + return !chat.isForbidden && !chat.isNotJoined && hasPinMessageRight && !isPinMessageRightBanned; + } + + return hasPinMessageRight; + })(); // https://github.com/telegramdesktop/tdesktop/blob/335095a332607c41a8d20b47e61f5bbd66366d4b/Telegram/SourceFiles/data/data_peer.cpp#L653 const canEditMessagesIndefinitely = (() => { if (content.todo) return true; if (isPrivate) return isChatWithSelf; if (isBasicGroup) return false; - if (isSuperGroup) return hasChatPinPermission; + if (isSuperGroup) return canPinMessage; if (isChannel) return chat.isCreator || getHasAdminRight(chat, 'editMessages'); return false; })(); @@ -720,7 +738,7 @@ export function selectAllowedMessageActionsSlow( const canReplyGlobally = canReply || (!isSavedDialog && !isLocal && !isServiceNotification && (isSuperGroup || isBasicGroup || isChatChannel(chat))); - let canPin = !isLocal && !isServiceNotification && !isAction && hasPinPermission && !isSavedDialog; + let canPin = !isLocal && !isServiceNotification && !isAction && canPinMessage && !isSavedDialog; let canUnpin = false; const pinnedMessageIds = selectPinnedIds(global, chat.id, threadId);