diff --git a/ts/components/conversation/ConversationRequestButtons.tsx b/ts/components/conversation/ConversationRequestButtons.tsx index 7ff0eaac5..2c19ea1c3 100644 --- a/ts/components/conversation/ConversationRequestButtons.tsx +++ b/ts/components/conversation/ConversationRequestButtons.tsx @@ -10,6 +10,7 @@ import { import { MessageDirection } from '../../models/messageType'; import { getConversationController } from '../../session/conversations'; import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils'; +import { clearConversationFocus } from '../../state/ducks/conversations'; import { updateConfirmModal } from '../../state/ducks/modalDialog'; import { getSelectedConversation } from '../../state/selectors/conversations'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton'; @@ -55,9 +56,11 @@ export const ConversationMessageRequestButtons = () => { cancelText: window.i18n('cancel'), message: window.i18n('declineRequestMessage'), onClickOk: async () => { - await declineConversation(selectedConversation.id, false); - await blockConvoById(selectedConversation.id); + const { id } = selectedConversation; + await declineConversation(id, false); + await blockConvoById(id); await forceSyncConfigurationNowIfNeeded(); + await clearConversationFocus(); }, onClickCancel: () => { dispatch(updateConfirmModal(null)); diff --git a/ts/components/leftpane/ActionsPanel.tsx b/ts/components/leftpane/ActionsPanel.tsx index 990ee501b..e30b3ede6 100644 --- a/ts/components/leftpane/ActionsPanel.tsx +++ b/ts/components/leftpane/ActionsPanel.tsx @@ -81,6 +81,7 @@ const Section = (props: { type: SectionType }) => { // Show Path Indicator Modal dispatch(onionPathModal({})); } else { + // message section dispatch(clearSearch()); dispatch(showLeftPaneSection(type)); dispatch(setOverlayMode(undefined)); diff --git a/ts/components/leftpane/overlay/OverlayMessageRequest.tsx b/ts/components/leftpane/overlay/OverlayMessageRequest.tsx index f11fc3f82..9d3c6086c 100644 --- a/ts/components/leftpane/overlay/OverlayMessageRequest.tsx +++ b/ts/components/leftpane/overlay/OverlayMessageRequest.tsx @@ -3,16 +3,19 @@ import React from 'react'; import { SpacerLG } from '../../basic/Text'; import { useDispatch, useSelector } from 'react-redux'; -import { getConversationRequests } from '../../../state/selectors/conversations'; +import { + getConversationRequests, + getSelectedConversation, +} from '../../../state/selectors/conversations'; import { MemoConversationListItemWithDetails } from '../conversation-list-item/ConversationListItem'; import styled from 'styled-components'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../../basic/SessionButton'; -import { setOverlayMode } from '../../../state/ducks/section'; +import { SectionType, setOverlayMode, showLeftPaneSection } from '../../../state/ducks/section'; import { getConversationController } from '../../../session/conversations'; import { forceSyncConfigurationNowIfNeeded } from '../../../session/utils/syncUtils'; import { BlockedNumberController } from '../../../util'; import useKey from 'react-use/lib/useKey'; -import { ReduxConversationType } from '../../../state/ducks/conversations'; +import { clearConversationFocus, ReduxConversationType } from '../../../state/ducks/conversations'; import { updateConfirmModal } from '../../../state/ducks/modalDialog'; export const OverlayMessageRequest = () => { @@ -21,8 +24,9 @@ export const OverlayMessageRequest = () => { function closeOverlay() { dispatch(setOverlayMode(undefined)); } - const hasRequests = useSelector(getConversationRequests).length > 0; + const convoRequestCount = useSelector(getConversationRequests).length; const messageRequests = useSelector(getConversationRequests); + const selectedConversation = useSelector(getSelectedConversation); const buttonText = window.i18n('clearAll'); @@ -30,7 +34,7 @@ export const OverlayMessageRequest = () => { * Blocks all message request conversations and synchronizes across linked devices * @returns void */ - async function handleBlockAllRequestsClick(convoRequests: Array) { + async function handleClearAllRequestsClick(convoRequests: Array) { const { i18n } = window; const title = i18n('clearAllConfirmationTitle'); const message = i18n('clearAllConfirmationBody'); @@ -48,10 +52,10 @@ export const OverlayMessageRequest = () => { return; } - let syncRequired = false; + let newConvosBlocked = []; const convoController = getConversationController(); await Promise.all( - convoRequests.map(async convo => { + (newConvosBlocked = convoRequests.filter(async convo => { const { id } = convo; const convoModel = convoController.get(id); if (!convoModel.isBlocked()) { @@ -60,13 +64,24 @@ export const OverlayMessageRequest = () => { } await convoModel.setIsApproved(false); - syncRequired = true; - }) + // if we're looking at the convo to decline, close the convo + if (selectedConversation?.id === id) { + await clearConversationFocus(); + } + return true; + })) ); - if (syncRequired) { + if (newConvosBlocked) { await forceSyncConfigurationNowIfNeeded(); } + + // if no more requests, return to placeholder screen + if (convoRequestCount === newConvosBlocked.length) { + dispatch(setOverlayMode(undefined)); + dispatch(showLeftPaneSection(SectionType.Message)); + await clearConversationFocus(); + } }, }) ); @@ -74,7 +89,7 @@ export const OverlayMessageRequest = () => { return (
- {hasRequests ? ( + {convoRequestCount ? ( <> @@ -83,7 +98,7 @@ export const OverlayMessageRequest = () => { buttonType={SessionButtonType.BrandOutline} text={buttonText} onClick={async () => { - await handleBlockAllRequestsClick(messageRequests); + await handleClearAllRequestsClick(messageRequests); }} /> diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 6b9db1bf0..b3b8bfbd6 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -696,7 +696,12 @@ const conversationsSlice = createSlice({ firstUnreadMessageId: undefined, }; }, - + /** + * Closes any existing conversation and returns state to the placeholder screen + */ + resetConversationExternal(state: ConversationsStateType) { + return { ...getEmptyConversationState(), conversationLookup: state.conversationLookup }; + }, openConversationExternal( state: ConversationsStateType, action: PayloadAction<{ @@ -973,6 +978,10 @@ export async function openConversationWithMessages(args: { ); } +export async function clearConversationFocus() { + window.inboxStore?.dispatch(actions.resetConversationExternal()); +} + export async function openConversationToSpecificMessage(args: { conversationKey: string; messageIdToNavigateTo: string;