Message Context Menu: Fix canPinMessage for channels (#6247)

This commit is contained in:
Alexander Zinchuk 2025-09-19 14:35:24 +02:00
parent ab7f66ddce
commit c2badd4a4b

View File

@ -666,6 +666,7 @@ export function selectAllowedMessageActionsSlow<T extends GlobalState>(
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<T extends GlobalState>(
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<T extends GlobalState>(
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);