From 93211b1bf95dacd62f8b84e06b6e15599eae7d66 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 26 Mar 2024 10:23:25 +1100 Subject: [PATCH] fix: add checks to deal with non server deletable messages --- .../conversation/SessionConversation.tsx | 21 +++++++++++++------ ts/state/smart/SessionConversation.ts | 6 +++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ts/components/conversation/SessionConversation.tsx b/ts/components/conversation/SessionConversation.tsx index bfe76d023..bdf4a06d3 100644 --- a/ts/components/conversation/SessionConversation.tsx +++ b/ts/components/conversation/SessionConversation.tsx @@ -53,11 +53,14 @@ import { LightboxGallery, MediaItemType } from '../lightbox/LightboxGallery'; import { NoMessageInConversation } from './SubtleNotification'; import { ConversationHeaderWithDetails } from './header/ConversationHeader'; +import { + deleteMessagesById, + deleteMessagesByIdForEveryone, +} from '../../interactions/conversations/unsendingInteractions'; import { isAudio } from '../../types/MIME'; import { HTMLDirection } from '../../util/i18n'; import { NoticeBanner } from '../NoticeBanner'; import { SessionSpinner } from '../basic/SessionSpinner'; -import { deleteMessagesByIdForEveryone } from '../../interactions/conversations/unsendingInteractions'; import { RightPanel, StyledRightPanelContainer } from './right-panel/RightPanel'; const DEFAULT_JPEG_QUALITY = 0.85; @@ -85,6 +88,7 @@ interface Props { stagedAttachments: Array; isSelectedConvoInitialLoadingInProgress: boolean; + isPublic: boolean; } const StyledSpinnerContainer = styled.div` @@ -345,6 +349,7 @@ export class SessionConversation extends React.Component { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private onKeyDown(event: any) { const selectionMode = !!this.props.selectedMessages.length; + const { selectedConversationKey, selectedMessages, isPublic } = this.props; if (event.target.classList.contains('conversation-content')) { switch (event.key) { @@ -355,11 +360,15 @@ export class SessionConversation extends React.Component { break; case 'Backspace': case 'Delete': - if (selectionMode) { - void deleteMessagesByIdForEveryone( - this.props.selectedMessages, - this.props.selectedConversationKey - ); + if (selectionMode && this.props.selectedConversationKey) { + if (isPublic) { + void deleteMessagesByIdForEveryone(selectedMessages, selectedConversationKey); + } else { + void deleteMessagesById( + this.props.selectedMessages, + this.props.selectedConversationKey + ); + } } break; default: diff --git a/ts/state/smart/SessionConversation.ts b/ts/state/smart/SessionConversation.ts index 9941d8137..aa0a54001 100644 --- a/ts/state/smart/SessionConversation.ts +++ b/ts/state/smart/SessionConversation.ts @@ -12,7 +12,10 @@ import { getSortedMessagesOfSelectedConversation, isRightPanelShowing, } from '../selectors/conversations'; -import { getSelectedConversationKey } from '../selectors/selectedConversation'; +import { + getSelectedConversationIsPublic, + getSelectedConversationKey, +} from '../selectors/selectedConversation'; import { getStagedAttachmentsForCurrentConversation } from '../selectors/stagedAttachments'; import { getTheme } from '../selectors/theme'; import { getOurDisplayNameInProfile, getOurNumber } from '../selectors/user'; @@ -36,6 +39,7 @@ const mapStateToProps = (state: StateType, ownProps: SmartSessionConversationOwn hasOngoingCallWithFocusedConvo: getHasOngoingCallWithFocusedConvo(state), isSelectedConvoInitialLoadingInProgress: getIsSelectedConvoInitialLoadingInProgress(state), htmlDirection: ownProps.htmlDirection, + isPublic: getSelectedConversationIsPublic(state), }; };