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

This commit is contained in:
warrickct 2022-02-25 09:58:35 +11:00
parent af4457f68f
commit 065b8ab533
4 changed files with 43 additions and 15 deletions

View File

@ -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));

View File

@ -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));

View File

@ -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<ReduxConversationType>) {
async function handleClearAllRequestsClick(convoRequests: Array<ReduxConversationType>) {
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 (
<div className="module-left-pane-overlay">
{hasRequests ? (
{convoRequestCount ? (
<>
<MessageRequestList />
<SpacerLG />
@ -83,7 +98,7 @@ export const OverlayMessageRequest = () => {
buttonType={SessionButtonType.BrandOutline}
text={buttonText}
onClick={async () => {
await handleBlockAllRequestsClick(messageRequests);
await handleClearAllRequestsClick(messageRequests);
}}
/>
</>

View File

@ -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;