update local UI for blocking all conversations. Removing some unused vars

pull/2222/head
warrickct 3 years ago
parent a90960c502
commit 18a739b05b

@ -420,14 +420,7 @@ class CompositionBoxInner extends React.Component<Props, State> {
return i18n('sendMessage'); return i18n('sendMessage');
}; };
const { const { isKickedFromGroup, left, isPrivate, isBlocked } = this.props.selectedConversation;
isKickedFromGroup,
left,
isPrivate,
isBlocked,
didApproveMe,
isApproved,
} = this.props.selectedConversation;
const messagePlaceHolder = makeMessagePlaceHolderText(); const messagePlaceHolder = makeMessagePlaceHolderText();
const { typingEnabled } = this.props; const { typingEnabled } = this.props;
const neverMatchingRegex = /($a)/; const neverMatchingRegex = /($a)/;

@ -12,36 +12,31 @@ 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';
/** /**
* 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() { async function handleBlockAllRequestsClick(convoRequests: Array<ReduxConversationType>) {
// block all convo requests. Force sync if there were changes.
window?.log?.info('Blocking all conversations'); window?.log?.info('Blocking all conversations');
const conversations = getConversationController().getConversations(); if (!convoRequests) {
window?.log?.info('No conversation requests to block.');
if (!conversations) {
window?.log?.info('No message requests to block.');
return; return;
} }
const convoRequestsToBlock = conversations.filter(
c => c.isPrivate() && c.get('active_at') && c.get('isApproved')
);
let syncRequired = false; let syncRequired = false;
const convoController = getConversationController();
if (!convoRequestsToBlock) { await Promise.all(
window?.log?.info('No conversation requests to block.'); convoRequests.map(async convo => {
return; const { id } = convo;
const convoModel = convoController.get(id);
if (!convoModel.isBlocked()) {
await BlockedNumberController.block(id);
convoModel.commit();
} }
await convoModel.setIsApproved(false);
await Promise.all(
convoRequestsToBlock.map(async convo => {
await BlockedNumberController.block(convo.id);
await convo.setIsApproved(false);
syncRequired = true; syncRequired = true;
}) })
); );
@ -58,6 +53,7 @@ export const OverlayMessageRequest = () => {
dispatch(setOverlayMode(undefined)); dispatch(setOverlayMode(undefined));
} }
const hasRequests = useSelector(getConversationRequests).length > 0; const hasRequests = useSelector(getConversationRequests).length > 0;
const messageRequests = useSelector(getConversationRequests);
const buttonText = window.i18n('clearAll'); const buttonText = window.i18n('clearAll');
@ -71,8 +67,8 @@ export const OverlayMessageRequest = () => {
buttonColor={SessionButtonColor.Danger} buttonColor={SessionButtonColor.Danger}
buttonType={SessionButtonType.BrandOutline} buttonType={SessionButtonType.BrandOutline}
text={buttonText} text={buttonText}
onClick={() => { onClick={async () => {
void handleBlockAllRequestsClick(); await handleBlockAllRequestsClick(messageRequests);
}} }}
/> />
</> </>

Loading…
Cancel
Save