Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent users blocked from concierge from sending messages #2932

Merged
merged 13 commits into from
Jun 23, 2021
Merged
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const CONST = {
},
},
NVP: {
BLOCKED_FROM_CONCIERGE: 'private_blockedFromConcierge',
PAYPAL_ME_ADDRESS: 'expensify_payPalMeAddress',
PRIORITY_MODE: 'priorityMode',
TIMEZONE: 'timeZone',
Expand Down
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export default {
// Contains the user preference for the LHN priority mode
NVP_PRIORITY_MODE: 'nvp_priorityMode',

// Contains the users's block expiration (if they have one)
NVP_BLOCKED_FROM_CONCIERGE: 'private_blockedFromConcierge',

// SDK token used to communicate with Plaid API
PLAID_LINK_TOKEN: 'plaidLinkToken',

Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default {
sendAttachment: 'Send Attachment',
addAttachment: 'Add Attachment',
writeSomething: 'Write something...',
blockedFromConcierge: 'Communication is barred',
youAppearToBeOffline: 'You appear to be offline.',
fileUploadFailed: 'Upload Failed. File is not supported.',
},
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
sendAttachment: 'Enviar adjunto',
addAttachment: 'Agregar Archivo Adjunto',
writeSomething: 'Escribe algo...',
blockedFromConcierge: 'Comunicación no permitida',
youAppearToBeOffline: 'Parece que estás desconectado.',
},
reportActionContextMenu: {
Expand Down
22 changes: 21 additions & 1 deletion src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import lodashGet from 'lodash/get';
import Onyx from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import {PUBLIC_DOMAINS as COMMON_PUBLIC_DOMAINS} from 'expensify-common/lib/CONST';
import moment from 'moment';
import ONYXKEYS from '../../ONYXKEYS';
import * as API from '../API';
import CONST from '../../CONST';
Expand Down Expand Up @@ -63,7 +64,7 @@ function getBetas() {
function getUserDetails() {
API.Get({
returnValueList: 'account, loginList, nameValuePairs',
name: CONST.NVP.PAYPAL_ME_ADDRESS,
nvpNames: `${CONST.NVP.BLOCKED_FROM_CONCIERGE}, ${CONST.NVP.PAYPAL_ME_ADDRESS}`,
})
.then((response) => {
// Update the User onyx key
Expand All @@ -74,6 +75,10 @@ function getUserDetails() {
// Update the nvp_payPalMeAddress NVP
const payPalMeAddress = lodashGet(response, `nameValuePairs.${CONST.NVP.PAYPAL_ME_ADDRESS}`, '');
Onyx.merge(ONYXKEYS.NVP_PAYPAL_ME_ADDRESS, payPalMeAddress);

// Update the blockedFromConcierge NVP
const blockedFromConcierge = lodashGet(response, `nameValuePairs.${CONST.NVP.BLOCKED_FROM_CONCIERGE}`, '');
Onyx.merge(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, blockedFromConcierge);
});
}

Expand Down Expand Up @@ -174,6 +179,20 @@ function validateLogin(accountID, validateCode) {
});
}

/**
* Checks if the expiresAt date of a user's ban is before right now
*
* @param {String} expiresAt
* @returns {boolean}
*/
function isBlockedFromConcierge(expiresAt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method pretty much just compares a date with now, could it be generalized and moved to DateUtils?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that I'm just using the super simple one liner you gave below, i don't think we need to put it in dateUtils

if (!expiresAt) {
return false;
}

return moment().isBefore(moment(expiresAt), 'day');
}

/**
* Fetch the public domain info for the current user.
*
Expand Down Expand Up @@ -225,5 +244,6 @@ export {
setExpensifyNewsStatus,
setSecondaryLogin,
validateLogin,
isBlockedFromConcierge,
getDomainInfo,
};
29 changes: 26 additions & 3 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import withLocalize, {withLocalizePropTypes} from '../../../components/withLocal
import Permissions from '../../../libs/Permissions';
import Navigation from '../../../libs/Navigation/Navigation';
import ROUTES from '../../../ROUTES';
import * as User from '../../../libs/actions/User';
import ReportActionPropTypes from './ReportActionPropTypes';
import {canEditReportAction} from '../../../libs/reportUtils';
import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager';
Expand Down Expand Up @@ -97,6 +98,11 @@ const propTypes = {
isOffline: PropTypes.bool,
}),

// The NVP describing a user's block status
blockedFromConcierge: PropTypes.shape({
// The date that the user will be unblocked
expiresAt: PropTypes.string,
}),
...windowDimensionsPropTypes,
...withLocalizePropTypes,
};
Expand All @@ -107,6 +113,7 @@ const defaultProps = {
report: {},
reportActions: {},
network: {isOffline: false},
blockedFromConcierge: {},
};

class ReportActionCompose extends React.Component {
Expand Down Expand Up @@ -390,6 +397,17 @@ class ReportActionCompose extends React.Component {

// Prevents focusing and showing the keyboard while the drawer is covering the chat.
const isComposeDisabled = this.props.isDrawerOpen && this.props.isSmallScreenWidth;
const isConciergeChat = this.props.report.participants
&& this.props.report.participants.includes(CONST.EMAIL.CONCIERGE);
let isBlockedFromConcierge = false;
if (isConciergeChat && this.props.blockedFromConcierge) {
isBlockedFromConcierge = User.isBlockedFromConcierge(this.props.blockedFromConcierge.expiresAt);
}

const inputPlaceholder = isBlockedFromConcierge
? this.props.translate('reportActionCompose.blockedFromConcierge')
: this.props.translate('reportActionCompose.writeSomething');

return (
<View style={[styles.chatItemCompose]}>
<View style={[
Expand Down Expand Up @@ -420,6 +438,7 @@ class ReportActionCompose extends React.Component {
}}
style={styles.chatItemAttachButton}
underlayColor={themeColors.componentBG}
disabled={isBlockedFromConcierge}
>
<Icon src={Plus} />
</TouchableOpacity>
Expand Down Expand Up @@ -478,7 +497,7 @@ class ReportActionCompose extends React.Component {
multiline
ref={this.setTextInputRef}
textAlignVertical="top"
placeholder={this.props.translate('reportActionCompose.writeSomething')}
placeholder={inputPlaceholder}
placeholderTextColor={themeColors.placeholderText}
onChangeText={this.updateComment}
onKeyPress={this.triggerHotkeyActions}
Expand All @@ -503,7 +522,7 @@ class ReportActionCompose extends React.Component {
onPasteFile={file => displayFileInModal({file})}
shouldClear={this.state.textInputShouldClear}
onClear={() => this.setTextInputShouldClear(false)}
isDisabled={isComposeDisabled}
isDisabled={isComposeDisabled || isBlockedFromConcierge}
selection={this.state.selection}
onSelectionChange={this.onSelectionChange}
/>
Expand Down Expand Up @@ -542,6 +561,7 @@ class ReportActionCompose extends React.Component {
ref={el => this.emojiPopoverAnchor = el}
onLayout={this.measureEmojiPopoverAnchorPosition}
onPress={this.showEmojiPicker}
disabled={isBlockedFromConcierge}
>
{({hovered, pressed}) => (
<Icon
Expand All @@ -556,7 +576,7 @@ class ReportActionCompose extends React.Component {
? styles.buttonDisable : styles.buttonSuccess]}
onPress={this.submitForm}
underlayColor={themeColors.componentBG}
disabled={this.state.isCommentEmpty}
disabled={this.state.isCommentEmpty || isBlockedFromConcierge}
>
<Icon src={Send} fill={themeColors.componentBG} />
</TouchableOpacity>
Expand Down Expand Up @@ -612,5 +632,8 @@ export default compose(
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
},
blockedFromConcierge: {
key: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE,
},
}),
)(ReportActionCompose);