Added closing declined conversation requests if theyre open. Return to regular inbox on clear all.

pull/2222/head
warrickct 4 years ago
parent af4457f68f
commit 065b8ab533

@ -10,6 +10,7 @@ import {
import { MessageDirection } from '../../models/messageType'; import { MessageDirection } from '../../models/messageType';
import { getConversationController } from '../../session/conversations'; import { getConversationController } from '../../session/conversations';
import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils'; import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils';
import { clearConversationFocus } from '../../state/ducks/conversations';
import { updateConfirmModal } from '../../state/ducks/modalDialog'; import { updateConfirmModal } from '../../state/ducks/modalDialog';
import { getSelectedConversation } from '../../state/selectors/conversations'; import { getSelectedConversation } from '../../state/selectors/conversations';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
@ -55,9 +56,11 @@ export const ConversationMessageRequestButtons = () => {
cancelText: window.i18n('cancel'), cancelText: window.i18n('cancel'),
message: window.i18n('declineRequestMessage'), message: window.i18n('declineRequestMessage'),
onClickOk: async () => { onClickOk: async () => {
await declineConversation(selectedConversation.id, false); const { id } = selectedConversation;
await blockConvoById(selectedConversation.id); await declineConversation(id, false);
await blockConvoById(id);
await forceSyncConfigurationNowIfNeeded(); await forceSyncConfigurationNowIfNeeded();
await clearConversationFocus();
}, },
onClickCancel: () => { onClickCancel: () => {
dispatch(updateConfirmModal(null)); dispatch(updateConfirmModal(null));

@ -81,6 +81,7 @@ const Section = (props: { type: SectionType }) => {
// Show Path Indicator Modal // Show Path Indicator Modal
dispatch(onionPathModal({})); dispatch(onionPathModal({}));
} else { } else {
// message section
dispatch(clearSearch()); dispatch(clearSearch());
dispatch(showLeftPaneSection(type)); dispatch(showLeftPaneSection(type));
dispatch(setOverlayMode(undefined)); dispatch(setOverlayMode(undefined));

@ -3,16 +3,19 @@ import React from 'react';
import { SpacerLG } from '../../basic/Text'; import { SpacerLG } from '../../basic/Text';
import { useDispatch, useSelector } from 'react-redux'; 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 { MemoConversationListItemWithDetails } from '../conversation-list-item/ConversationListItem';
import styled from 'styled-components'; import styled from 'styled-components';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../../basic/SessionButton'; 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 { getConversationController } from '../../../session/conversations';
import { forceSyncConfigurationNowIfNeeded } from '../../../session/utils/syncUtils'; import { forceSyncConfigurationNowIfNeeded } from '../../../session/utils/syncUtils';
import { BlockedNumberController } from '../../../util'; import { BlockedNumberController } from '../../../util';
import useKey from 'react-use/lib/useKey'; 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'; import { updateConfirmModal } from '../../../state/ducks/modalDialog';
export const OverlayMessageRequest = () => { export const OverlayMessageRequest = () => {
@ -21,8 +24,9 @@ export const OverlayMessageRequest = () => {
function closeOverlay() { function closeOverlay() {
dispatch(setOverlayMode(undefined)); dispatch(setOverlayMode(undefined));
} }
const hasRequests = useSelector(getConversationRequests).length > 0; const convoRequestCount = useSelector(getConversationRequests).length;
const messageRequests = useSelector(getConversationRequests); const messageRequests = useSelector(getConversationRequests);
const selectedConversation = useSelector(getSelectedConversation);
const buttonText = window.i18n('clearAll'); const buttonText = window.i18n('clearAll');
@ -30,7 +34,7 @@ export const OverlayMessageRequest = () => {
* Blocks all message request conversations and synchronizes across linked devices * Blocks all message request conversations and synchronizes across linked devices
* @returns void * @returns void
*/ */
async function handleBlockAllRequestsClick(convoRequests: Array<ReduxConversationType>) { async function handleClearAllRequestsClick(convoRequests: Array<ReduxConversationType>) {
const { i18n } = window; const { i18n } = window;
const title = i18n('clearAllConfirmationTitle'); const title = i18n('clearAllConfirmationTitle');
const message = i18n('clearAllConfirmationBody'); const message = i18n('clearAllConfirmationBody');
@ -48,10 +52,10 @@ export const OverlayMessageRequest = () => {
return; return;
} }
let syncRequired = false; let newConvosBlocked = [];
const convoController = getConversationController(); const convoController = getConversationController();
await Promise.all( await Promise.all(
convoRequests.map(async convo => { (newConvosBlocked = convoRequests.filter(async convo => {
const { id } = convo; const { id } = convo;
const convoModel = convoController.get(id); const convoModel = convoController.get(id);
if (!convoModel.isBlocked()) { if (!convoModel.isBlocked()) {
@ -60,13 +64,24 @@ export const OverlayMessageRequest = () => {
} }
await convoModel.setIsApproved(false); 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(); 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 ( return (
<div className="module-left-pane-overlay"> <div className="module-left-pane-overlay">
{hasRequests ? ( {convoRequestCount ? (
<> <>
<MessageRequestList /> <MessageRequestList />
<SpacerLG /> <SpacerLG />
@ -83,7 +98,7 @@ export const OverlayMessageRequest = () => {
buttonType={SessionButtonType.BrandOutline} buttonType={SessionButtonType.BrandOutline}
text={buttonText} text={buttonText}
onClick={async () => { onClick={async () => {
await handleBlockAllRequestsClick(messageRequests); await handleClearAllRequestsClick(messageRequests);
}} }}
/> />
</> </>

@ -696,7 +696,12 @@ const conversationsSlice = createSlice({
firstUnreadMessageId: undefined, firstUnreadMessageId: undefined,
}; };
}, },
/**
* Closes any existing conversation and returns state to the placeholder screen
*/
resetConversationExternal(state: ConversationsStateType) {
return { ...getEmptyConversationState(), conversationLookup: state.conversationLookup };
},
openConversationExternal( openConversationExternal(
state: ConversationsStateType, state: ConversationsStateType,
action: PayloadAction<{ 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: { export async function openConversationToSpecificMessage(args: {
conversationKey: string; conversationKey: string;
messageIdToNavigateTo: string; messageIdToNavigateTo: string;

Loading…
Cancel
Save