Delete Message Modal: Hotfix for delete selected message (#4803)

This commit is contained in:
Alexander Zinchuk 2024-08-06 20:06:10 +02:00
parent 51e978af60
commit 527e4644e2
2 changed files with 13 additions and 14 deletions

View File

@ -17,7 +17,7 @@ import {
getHasAdminRight,
getPrivateChatUserId,
getUserFirstOrLastName, getUserFullName,
isChatBasicGroup, isChatChannel,
isChatBasicGroup,
isChatSuperGroup, isOwnMessage,
isUserId,
} from '../../global/helpers';
@ -52,7 +52,6 @@ export type OwnProps = {
type StateProps = {
chat?: ApiChat;
isChannel?: boolean;
isGroup?: boolean;
isSuperGroup?: boolean;
sender: ApiPeer | undefined;
@ -75,7 +74,6 @@ type StateProps = {
const DeleteMessageModal: FC<OwnProps & StateProps> = ({
isOpen,
chat,
isChannel,
isGroup,
isSuperGroup,
sender,
@ -226,7 +224,7 @@ const DeleteMessageModal: FC<OwnProps & StateProps> = ({
: [message!.id];
if (isSchedule) {
deleteScheduledMessages({ messageIds });
} else if (!isOwn && (isChannel || isGroup || isSuperGroup)) {
} else if (!isOwn && (chosenSpanOption || chosenDeleteOption || chosenBanOption) && (isGroup || isSuperGroup)) {
if (chosenSpanOption) {
const filteredMessageIdList = filterMessageIdByUserId(chosenSpanOption, messageIdList!);
if (filteredMessageIdList && filteredMessageIdList.length) {
@ -367,7 +365,7 @@ const DeleteMessageModal: FC<OwnProps & StateProps> = ({
>
<div className={buildClassName(styles.mainContainer, 'custom-scroll')}>
{renderHeader()}
{(shouldShowAdditionalOptions && !canDeleteForAll && !isSchedule && (isChannel || isGroup || isSuperGroup)) && (
{(shouldShowAdditionalOptions && !canDeleteForAll && !isSchedule && (isGroup || isSuperGroup)) && (
<>
<p className={styles.actionTitle}>{lang('DeleteAdditionalActions')}</p>
{renderAdditionalActionOptions()}
@ -438,7 +436,6 @@ export default memo(withGlobal<OwnProps>(
&& selectAllowedMessageActions(global, deleteMessageModal.message, threadId)) || {};
const adminMembersById = chatFullInfo && chatFullInfo?.adminMembersById;
const messageIdList = chat && selectCurrentMessageIds(global, chat.id, threadId!, type!);
const isChannel = Boolean(chat) && isChatChannel(chat);
const isGroup = Boolean(chat) && isChatBasicGroup(chat);
const isSuperGroup = Boolean(chat) && isChatSuperGroup(chat);
const sender = deleteMessageModal && chat && deleteMessageModal.message
@ -457,7 +454,6 @@ export default memo(withGlobal<OwnProps>(
return {
chat,
isChannel,
isGroup,
isSuperGroup,
currentUserId: global.currentUserId,

View File

@ -15,8 +15,7 @@ import {
getPrivateChatUserId,
getUserFirstOrLastName,
getUserFullName,
isChatBasicGroup,
isChatChannel,
isChatBasicGroup, isChatChannel,
isChatSuperGroup,
isUserId,
} from '../../global/helpers';
@ -60,8 +59,8 @@ export type OwnProps = {
type StateProps = {
chat?: ApiChat;
isChannel?: boolean;
isGroup?: boolean;
isChannel?: boolean;
isSuperGroup?: boolean;
selectedMessageIds?: number[];
canDeleteForAll?: boolean;
@ -117,9 +116,12 @@ const DeleteSelectedMessageModal: FC<OwnProps & StateProps> = ({
const [isAdditionalOptionsVisible, setIsAdditionalOptionsVisible] = useState(false);
const senderList = useMemo(() => {
if (isChannel) {
return undefined;
}
return selectSendersFromSelectedMessages(getGlobal(), chat);
// eslint-disable-next-line react-hooks-static-deps/exhaustive-deps
}, [chat, isOpen]);
}, [chat, isChannel, isOpen]);
const isSenderOwner = useMemo(() => {
if (!senderList) {
@ -245,7 +247,8 @@ const DeleteSelectedMessageModal: FC<OwnProps & StateProps> = ({
const handleDeleteMessageForSelf = useLastCallback(() => {
if (isSchedule) {
deleteScheduledMessages({ messageIds: selectedMessageIds! });
} else if (!isSenderOwner && (isChannel || isSuperGroup)) {
} else if (!isSenderOwner
&& (chosenSpanOption || chosenDeleteOption || chosenBanOption) && (isGroup || isSuperGroup)) {
if (chosenSpanOption) {
const userIdList = chosenSpanOption.filter((option) => !Number.isNaN(Number(option)));
const filteredMessageIdList = filterMessageIdByUserId(userIdList, selectedMessageIds!);
@ -392,7 +395,7 @@ const DeleteSelectedMessageModal: FC<OwnProps & StateProps> = ({
<div className={styles.main}>
{renderHeader()}
{!showAdditionalOptions && <p>{lang('AreYouSureDeleteFewMessages')}</p>}
{(showAdditionalOptions && !canDeleteForAll && !isSchedule && (isChannel || isGroup || isSuperGroup)) && (
{(showAdditionalOptions && !canDeleteForAll && !isSchedule && (isGroup || isSuperGroup)) && (
<>
<p className={styles.actionTitle}>{oldLang('DeleteAdditionalActions')}</p>
{renderAdditionalActionOptions()}
@ -458,8 +461,8 @@ export default memo(withGlobal<OwnProps>(
return {
chat,
isChannel,
isGroup,
isChannel,
isSuperGroup,
selectedMessageIds,
currentUserId: global.currentUserId,