Add confirmation dialog for clear all message requests.

This commit is contained in:
warrickct 2022-02-24 15:11:10 +11:00
parent 79c1c52034
commit 5888fecda4
3 changed files with 51 additions and 32 deletions

View file

@ -476,5 +476,7 @@
"noMediaUntilApproved": "You cannot send attachments until the conversation is approved",
"mustBeApproved": "This conversation must be accepted to use this feature",
"youHaveANewFriendRequest": "You have a new friend request",
"clearAllConfirmationTitle": "Clear All Message Requests",
"clearAllConfirmationBody": "Are you sure you want to clear all message requests?",
"openMessageRequestInboxDescription": "View your Message Request inbox"
}

View file

@ -13,38 +13,7 @@ import { forceSyncConfigurationNowIfNeeded } from '../../../session/utils/syncUt
import { BlockedNumberController } from '../../../util';
import useKey from 'react-use/lib/useKey';
import { ReduxConversationType } from '../../../state/ducks/conversations';
/**
* Blocks all message request conversations and synchronizes across linked devices
* @returns void
*/
async function handleBlockAllRequestsClick(convoRequests: Array<ReduxConversationType>) {
window?.log?.info('Blocking all conversations');
if (!convoRequests) {
window?.log?.info('No conversation requests to block.');
return;
}
let syncRequired = false;
const convoController = getConversationController();
await Promise.all(
convoRequests.map(async convo => {
const { id } = convo;
const convoModel = convoController.get(id);
if (!convoModel.isBlocked()) {
await BlockedNumberController.block(id);
await convoModel.commit();
}
await convoModel.setIsApproved(false);
syncRequired = true;
})
);
if (syncRequired) {
await forceSyncConfigurationNowIfNeeded();
}
}
import { updateConfirmModal } from '../../../state/ducks/modalDialog';
export const OverlayMessageRequest = () => {
useKey('Escape', closeOverlay);
@ -57,6 +26,52 @@ export const OverlayMessageRequest = () => {
const buttonText = window.i18n('clearAll');
/**
* Blocks all message request conversations and synchronizes across linked devices
* @returns void
*/
async function handleBlockAllRequestsClick(convoRequests: Array<ReduxConversationType>) {
const { i18n } = window;
const title = i18n('clearAllConfirmationTitle');
const message = i18n('clearAllConfirmationBody');
const onClose = dispatch(updateConfirmModal(null));
dispatch(
updateConfirmModal({
title,
message,
onClose,
onClickOk: async () => {
window?.log?.info('Blocking all conversations');
if (!convoRequests) {
window?.log?.info('No conversation requests to block.');
return;
}
let syncRequired = false;
const convoController = getConversationController();
await Promise.all(
convoRequests.map(async convo => {
const { id } = convo;
const convoModel = convoController.get(id);
if (!convoModel.isBlocked()) {
await BlockedNumberController.block(id);
await convoModel.commit();
}
await convoModel.setIsApproved(false);
syncRequired = true;
})
);
if (syncRequired) {
await forceSyncConfigurationNowIfNeeded();
}
},
})
);
}
return (
<div className="module-left-pane-overlay">
{hasRequests ? (

View file

@ -479,4 +479,6 @@ export type LocalizerKeys =
| 'noMediaUntilApproved'
| 'mustBeApproved'
| 'youHaveANewFriendRequest'
| 'clearAllConfirmationTitle'
| 'clearAllConfirmationBody'
| 'reportIssue';