From bc6edd77749754b65f76afd3e49d832ef1df8459 Mon Sep 17 00:00:00 2001 From: warrickct Date: Mon, 14 Feb 2022 14:47:54 +1100 Subject: [PATCH] Adding unhiding of message request banner when receiving a new convo request. --- _locales/en/messages.json | 4 ++-- ts/components/leftpane/LeftPane.tsx | 4 ++-- .../leftpane/MessageRequestsBanner.tsx | 6 +++--- .../overlay/OverlayMessageRequest.tsx | 5 +---- .../settings/section/CategoryAppearance.tsx | 1 - .../settings/section/CategoryPrivacy.tsx | 8 ++++---- ts/models/conversation.ts | 4 ++-- ts/receiver/contentMessage.ts | 19 +++++++++++-------- ts/state/createStore.ts | 2 +- ts/state/ducks/userConfig.tsx | 16 ++++++++++++---- ts/state/selectors/conversations.ts | 11 +++-------- ts/state/selectors/userConfig.ts | 4 ++-- ts/types/LocalizerKeys.ts | 4 ++-- 13 files changed, 45 insertions(+), 43 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 0b3c920e5..9aced49f5 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -439,7 +439,7 @@ "messageRequests": "Message Requests", "requestsSubtitle": "Pending Requests", "requestsPlaceholder": "No requests", - "messageRequestsDescription": "Always show the Message Request inbox", + "hideRequestBannerDescription": "Hide the Message Request banner until you receive a new message request.", "incomingCallFrom": "Incoming call from '$name$'", "ringing": "Ringing...", "establishingConnection": "Establishing connection...", @@ -472,7 +472,7 @@ "messageRequestAcceptedOursNoName": "You have accepted the message request", "declineRequestMessage": "Are you sure you want to decline this message request?", "respondingToRequestWarning": "Sending a message to this user will automatically accept their message request and reveal your Session ID.", - "alwaysShowMessageRequests": "Always show Message Requests", + "hideRequestBanner": "Hide Message Request Banner", "openMessageRequestInbox": "View Message Requests", "openMessageRequestInboxDescription": "View your Message Request inbox" } diff --git a/ts/components/leftpane/LeftPane.tsx b/ts/components/leftpane/LeftPane.tsx index 48a6290d5..bc5af6e99 100644 --- a/ts/components/leftpane/LeftPane.tsx +++ b/ts/components/leftpane/LeftPane.tsx @@ -6,7 +6,7 @@ import { SessionTheme } from '../../state/ducks/SessionTheme'; import { getLeftPaneLists } from '../../state/selectors/conversations'; import { getQuery, getSearchResults, isSearching } from '../../state/selectors/search'; import { getFocusedSection, getOverlayMode } from '../../state/selectors/section'; -import { getIsMessageRequestsEnabled } from '../../state/selectors/userConfig'; +import { getHideMessageRequestBanner } from '../../state/selectors/userConfig'; import { ActionsPanel } from './ActionsPanel'; import { LeftPaneContactSection } from './LeftPaneContactSection'; import { LeftPaneMessageSection } from './LeftPaneMessageSection'; @@ -29,7 +29,7 @@ const InnerLeftPaneMessageSection = () => { const searchResults = showSearch ? useSelector(getSearchResults) : undefined; const lists = showSearch ? undefined : useSelector(getLeftPaneLists); - const messageRequestsEnabled = useSelector(getIsMessageRequestsEnabled); + const messageRequestsEnabled = useSelector(getHideMessageRequestBanner); const overlayMode = useSelector(getOverlayMode); return ( diff --git a/ts/components/leftpane/MessageRequestsBanner.tsx b/ts/components/leftpane/MessageRequestsBanner.tsx index 9cb6e90f9..284f2bb2d 100644 --- a/ts/components/leftpane/MessageRequestsBanner.tsx +++ b/ts/components/leftpane/MessageRequestsBanner.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { useSelector } from 'react-redux'; import styled from 'styled-components'; import { getConversationRequests } from '../../state/selectors/conversations'; -import { getIsMessageRequestsEnabled } from '../../state/selectors/userConfig'; +import { getHideMessageRequestBanner } from '../../state/selectors/userConfig'; import { SessionIcon, SessionIconSize, SessionIconType } from '../icon'; const StyledMessageRequestBanner = styled.div` @@ -85,9 +85,9 @@ export const CirclularIcon = (props: { iconType: SessionIconType; iconSize: Sess export const MessageRequestsBanner = (props: { handleOnClick: () => any }) => { const { handleOnClick } = props; const conversationRequests = useSelector(getConversationRequests); - const showRequestBannerEnabled = useSelector(getIsMessageRequestsEnabled); + const hideRequestBanner = useSelector(getHideMessageRequestBanner); - if (!conversationRequests.length || !showRequestBannerEnabled) { + if (!conversationRequests.length || hideRequestBanner) { return null; } diff --git a/ts/components/leftpane/overlay/OverlayMessageRequest.tsx b/ts/components/leftpane/overlay/OverlayMessageRequest.tsx index fbcd4c7de..11576ae68 100644 --- a/ts/components/leftpane/overlay/OverlayMessageRequest.tsx +++ b/ts/components/leftpane/overlay/OverlayMessageRequest.tsx @@ -11,7 +11,6 @@ import { setOverlayMode } from '../../../state/ducks/section'; import { getConversationController } from '../../../session/conversations'; import { forceSyncConfigurationNowIfNeeded } from '../../../session/utils/syncUtils'; import { BlockedNumberController } from '../../../util'; -import { getIsMessageRequestsEnabled } from '../../../state/selectors/userConfig'; import useKey from 'react-use/lib/useKey'; /** @@ -59,8 +58,6 @@ export const OverlayMessageRequest = () => { dispatch(setOverlayMode(undefined)); } - const messageRequestSetting = useSelector(getIsMessageRequestsEnabled); - const buttonText = window.i18n('clearAll'); return ( @@ -73,7 +70,7 @@ export const OverlayMessageRequest = () => { buttonType={SessionButtonType.BrandOutline} text={buttonText} onClick={() => { - void handleBlockAllRequestsClick(messageRequestSetting); + void handleBlockAllRequestsClick(); }} /> diff --git a/ts/components/settings/section/CategoryAppearance.tsx b/ts/components/settings/section/CategoryAppearance.tsx index 200b6d5ab..4903380f4 100644 --- a/ts/components/settings/section/CategoryAppearance.tsx +++ b/ts/components/settings/section/CategoryAppearance.tsx @@ -5,7 +5,6 @@ import { useDispatch, useSelector } from 'react-redux'; import useUpdate from 'react-use/lib/useUpdate'; import { createOrUpdateItem, - fillWithTestData, hasLinkPreviewPopupBeenDisplayed, } from '../../../data/data'; import { ToastUtils } from '../../../session/utils'; diff --git a/ts/components/settings/section/CategoryPrivacy.tsx b/ts/components/settings/section/CategoryPrivacy.tsx index c1746868e..45c85e837 100644 --- a/ts/components/settings/section/CategoryPrivacy.tsx +++ b/ts/components/settings/section/CategoryPrivacy.tsx @@ -7,7 +7,7 @@ import { CallManager } from '../../../session/utils'; import { sessionPassword, updateConfirmModal } from '../../../state/ducks/modalDialog'; import { SectionType, setOverlayMode, showLeftPaneSection } from '../../../state/ducks/section'; import { toggleMessageRequests } from '../../../state/ducks/userConfig'; -import { getIsMessageRequestsEnabled } from '../../../state/selectors/userConfig'; +import { getHideMessageRequestBanner } from '../../../state/selectors/userConfig'; import { SessionButtonColor } from '../../basic/SessionButton'; import { PasswordAction } from '../../dialog/SessionPasswordDialog'; @@ -115,9 +115,9 @@ export const SettingsCategoryPrivacy = (props: { onClickToggle={() => { dispatch(toggleMessageRequests()); }} - title={window.i18n('alwaysShowMessageRequests')} - description={window.i18n('messageRequestsDescription')} - active={useSelector(getIsMessageRequestsEnabled)} + title={window.i18n('hideRequestBanner')} + description={window.i18n('hideRequestBannerDescription')} + active={useSelector(getHideMessageRequestBanner)} /> diff --git a/ts/state/ducks/userConfig.tsx b/ts/state/ducks/userConfig.tsx index 8f6fcd9f3..da2974879 100644 --- a/ts/state/ducks/userConfig.tsx +++ b/ts/state/ducks/userConfig.tsx @@ -7,13 +7,13 @@ import { createSlice } from '@reduxjs/toolkit'; export interface UserConfigState { audioAutoplay: boolean; showRecoveryPhrasePrompt: boolean; - messageRequests: boolean; + hideMessageRequests: boolean; } export const initialUserConfigState = { audioAutoplay: false, showRecoveryPhrasePrompt: true, - messageRequests: false, + hideMessageRequests: false, }; const userConfigSlice = createSlice({ @@ -27,11 +27,19 @@ const userConfigSlice = createSlice({ state.showRecoveryPhrasePrompt = false; }, toggleMessageRequests: state => { - state.messageRequests = !state.messageRequests; + state.hideMessageRequests = !state.hideMessageRequests; + }, + showMessageRequestBanner: state => { + state.hideMessageRequests = false; }, }, }); const { actions, reducer } = userConfigSlice; -export const { toggleAudioAutoplay, disableRecoveryPhrasePrompt, toggleMessageRequests } = actions; +export const { + toggleAudioAutoplay, + disableRecoveryPhrasePrompt, + toggleMessageRequests, + showMessageRequestBanner, +} = actions; export const userConfigReducer = reducer; diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index b670c21c8..2fc7dd444 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -18,7 +18,7 @@ import { ConversationTypeEnum } from '../../models/conversation'; import { LocalizerType } from '../../types/Util'; import { ConversationHeaderTitleProps } from '../../components/conversation/ConversationHeader'; import _ from 'lodash'; -import { getIsMessageRequestsEnabled } from './userConfig'; +import { getHideMessageRequestBanner } from './userConfig'; import { ReplyingToMessageProps } from '../../components/conversation/composition/CompositionBox'; import { MessageAttachmentSelectorProps } from '../../components/conversation/message/message-content/MessageAttachment'; import { MessageAuthorSelectorProps } from '../../components/conversation/message/message-content/MessageAuthorText'; @@ -444,7 +444,7 @@ const _getConversationRequests = ( export const getConversationRequests = createSelector( getSortedConversations, - getIsMessageRequestsEnabled, + getHideMessageRequestBanner, _getConversationRequests ); @@ -473,15 +473,10 @@ const _getPrivateContactsPubkeys = ( */ export const getPrivateContactsPubkeys = createSelector( getSortedConversations, - getIsMessageRequestsEnabled, _getPrivateContactsPubkeys ); -export const getLeftPaneLists = createSelector( - getSortedConversations, - getIsMessageRequestsEnabled, - _getLeftPaneLists -); +export const getLeftPaneLists = createSelector(getSortedConversations, _getLeftPaneLists); export const getMe = createSelector( [getConversationLookup, getOurNumber], diff --git a/ts/state/selectors/userConfig.ts b/ts/state/selectors/userConfig.ts index 39dd45eba..ac3ce005d 100644 --- a/ts/state/selectors/userConfig.ts +++ b/ts/state/selectors/userConfig.ts @@ -14,7 +14,7 @@ export const getShowRecoveryPhrasePrompt = createSelector( (state: UserConfigState): boolean => state.showRecoveryPhrasePrompt ); -export const getIsMessageRequestsEnabled = createSelector( +export const getHideMessageRequestBanner = createSelector( getUserConfig, - (state: UserConfigState): boolean => state.messageRequests + (state: UserConfigState): boolean => state.hideMessageRequests ); diff --git a/ts/types/LocalizerKeys.ts b/ts/types/LocalizerKeys.ts index bab3caa5c..be3fbb858 100644 --- a/ts/types/LocalizerKeys.ts +++ b/ts/types/LocalizerKeys.ts @@ -50,7 +50,7 @@ export type LocalizerKeys = | 'viewMenuToggleDevTools' | 'fileSizeWarning' | 'openGroupURL' - | 'messageRequestsDescription' + | 'hideRequestBannerDescription' | 'hideMenuBarDescription' | 'search' | 'pickClosedGroupMember' @@ -473,5 +473,5 @@ export type LocalizerKeys = | 'declineRequestMessage' | 'openMessageRequestInbox' | 'openMessageRequestInboxDescription' - | 'alwaysShowMessageRequests' + | 'hideRequestBanner' | 'reportIssue';