Show confirm modal for at here mentions (#5678)
This commit is contained in:
parent
e301c9d5d1
commit
5260e252a4
4 changed files with 51 additions and 10 deletions
|
|
@ -329,12 +329,13 @@ export default class DraftInput extends PureComponent {
|
|||
const notificationsToChannel = enableConfirmNotificationsToChannel && useChannelMentions;
|
||||
const notificationsToGroups = enableConfirmNotificationsToChannel && useGroupMentions;
|
||||
const toAllOrChannel = DraftUtils.textContainsAtAllAtChannel(value);
|
||||
const groupMentions = (!toAllOrChannel && notificationsToGroups) ? DraftUtils.groupsMentionedInText(groupsWithAllowReference, value) : [];
|
||||
const toHere = DraftUtils.textContainsAtHere(value);
|
||||
const groupMentions = (!toAllOrChannel && !toHere && notificationsToGroups) ? DraftUtils.groupsMentionedInText(groupsWithAllowReference, value) : [];
|
||||
|
||||
if (value.indexOf('/') === 0) {
|
||||
this.sendCommand(value);
|
||||
} else if (notificationsToChannel && membersCount > NOTIFY_ALL_MEMBERS && toAllOrChannel) {
|
||||
this.showSendToAllOrChannelAlert(membersCount, value);
|
||||
} else if (notificationsToChannel && membersCount > NOTIFY_ALL_MEMBERS && (toAllOrChannel || toHere)) {
|
||||
this.showSendToAllOrChannelOrHereAlert(membersCount, value, toHere && !toAllOrChannel);
|
||||
} else if (groupMentions.length > 0) {
|
||||
const {groupMentionsSet, memberNotifyCount, channelTimezoneCount} = DraftUtils.mapGroupMentions(channelMemberCountsByGroup, groupMentions);
|
||||
if (memberNotifyCount > 0) {
|
||||
|
|
@ -364,11 +365,11 @@ export default class DraftInput extends PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
showSendToAllOrChannelAlert = (membersCount, msg) => {
|
||||
showSendToAllOrChannelOrHereAlert = (membersCount, msg, atHere) => {
|
||||
const {formatMessage} = this.context.intl;
|
||||
const {channelTimezoneCount} = this.state;
|
||||
const {isTimezoneEnabled} = this.props;
|
||||
const notifyAllMessage = DraftUtils.buildChannelWideMentionMessage(formatMessage, membersCount, isTimezoneEnabled, channelTimezoneCount);
|
||||
const notifyAllMessage = DraftUtils.buildChannelWideMentionMessage(formatMessage, membersCount, isTimezoneEnabled, channelTimezoneCount, atHere);
|
||||
const cancel = () => {
|
||||
this.setInputValue(msg);
|
||||
this.setState({sendingMessage: false});
|
||||
|
|
|
|||
|
|
@ -110,6 +110,31 @@ describe('DraftInput', () => {
|
|||
expect(Alert.alert).toHaveBeenCalledWith('Confirm sending notifications to entire channel', expect.anything(), expect.anything());
|
||||
});
|
||||
|
||||
test('should send an alert when sending a message with a @here mention', () => {
|
||||
const wrapper = shallowWithIntl(
|
||||
<DraftInput
|
||||
{...baseProps}
|
||||
ref={ref}
|
||||
/>,
|
||||
);
|
||||
const message = '@here';
|
||||
const instance = wrapper.instance();
|
||||
expect(instance.input).toEqual({current: null});
|
||||
instance.input = {
|
||||
current: {
|
||||
getValue: () => message,
|
||||
setValue: jest.fn(),
|
||||
changeDraft: jest.fn(),
|
||||
resetTextInput: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
instance.handleSendMessage();
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(Alert.alert).toBeCalled();
|
||||
expect(Alert.alert).toHaveBeenCalledWith('Confirm sending notifications to entire channel', expect.anything(), expect.anything());
|
||||
});
|
||||
|
||||
test('should send an alert when sending a message with a group mention with group with count more than NOTIFY_ALL', () => {
|
||||
const wrapper = shallowWithIntl(
|
||||
<DraftInput
|
||||
|
|
|
|||
|
|
@ -109,14 +109,18 @@ export function alertSlashCommandFailed(formatMessage, error) {
|
|||
);
|
||||
}
|
||||
|
||||
export function buildChannelWideMentionMessage(formatMessage, membersCount, isTimezoneEnabled, channelTimezoneCount) {
|
||||
export function buildChannelWideMentionMessage(formatMessage, membersCount, isTimezoneEnabled, channelTimezoneCount, atHere) {
|
||||
let notifyAllMessage = '';
|
||||
if (isTimezoneEnabled && channelTimezoneCount) {
|
||||
const msgID = atHere ? t('mobile.post_textbox.entire_channel_here.message.with_timezones') : t('mobile.post_textbox.entire_channel.message.with_timezones');
|
||||
const atHereMsg = 'By using @here you are about to send notifications up to {totalMembers, number} {totalMembers, plural, one {person} other {people}} in {timezones, number} {timezones, plural, one {timezone} other {timezones}}. Are you sure you want to do this?';
|
||||
const atAllOrChannelMsg = 'By using @all or @channel you are about to send notifications to {totalMembers, number} {totalMembers, plural, one {person} other {people}} in {timezones, number} {timezones, plural, one {timezone} other {timezones}}. Are you sure you want to do this?';
|
||||
|
||||
notifyAllMessage = (
|
||||
formatMessage(
|
||||
{
|
||||
id: 'mobile.post_textbox.entire_channel.message.with_timezones',
|
||||
defaultMessage: 'By using @all or @channel you are about to send notifications to {totalMembers, number} {totalMembers, plural, one {person} other {people}} in {timezones, number} {timezones, plural, one {timezone} other {timezones}}. Are you sure you want to do this?',
|
||||
id: msgID,
|
||||
defaultMessage: atHere ? atHereMsg : atAllOrChannelMsg,
|
||||
},
|
||||
{
|
||||
totalMembers: membersCount - 1,
|
||||
|
|
@ -125,11 +129,15 @@ export function buildChannelWideMentionMessage(formatMessage, membersCount, isTi
|
|||
)
|
||||
);
|
||||
} else {
|
||||
const msgID = atHere ? t('mobile.post_textbox.entire_channel_here.message') : t('mobile.post_textbox.entire_channel.message');
|
||||
const atHereMsg = 'By using @here you are about to send notifications to up to {totalMembers, number} {totalMembers, plural, one {person} other {people}}. Are you sure you want to do this?';
|
||||
const atAllOrChannelMsg = 'By using @all or @channel you are about to send notifications to {totalMembers, number} {totalMembers, plural, one {person} other {people}}. Are you sure you want to do this?';
|
||||
|
||||
notifyAllMessage = (
|
||||
formatMessage(
|
||||
{
|
||||
id: 'mobile.post_textbox.entire_channel.message',
|
||||
defaultMessage: 'By using @all or @channel you are about to send notifications to {totalMembers, number} {totalMembers, plural, one {person} other {people}}. Are you sure you want to do this?',
|
||||
id: msgID,
|
||||
defaultMessage: atHere ? atHereMsg : atAllOrChannelMsg,
|
||||
},
|
||||
{
|
||||
totalMembers: membersCount - 1,
|
||||
|
|
@ -257,6 +265,11 @@ export const textContainsAtAllAtChannel = (text) => {
|
|||
return (/(?:\B|\b_+)@(channel|all)(?!(\.|-|_)*[^\W_])/i).test(textWithoutCode);
|
||||
};
|
||||
|
||||
export const textContainsAtHere = (text) => {
|
||||
const textWithoutCode = text.replace(CODE_REGEX, '');
|
||||
return (/(?:\B|\b_+)@(here)(?!(\.|-|_)*[^\W_])/i).test(textWithoutCode);
|
||||
};
|
||||
|
||||
export const badDeepLink = (intl) => {
|
||||
const {formatMessage} = intl;
|
||||
Alert.alert(
|
||||
|
|
|
|||
|
|
@ -482,6 +482,8 @@
|
|||
"mobile.post_pre_header.flagged": "Saved",
|
||||
"mobile.post_pre_header.pinned": "Pinned",
|
||||
"mobile.post_pre_header.pinned_flagged": "Pinned and Saved",
|
||||
"mobile.post_textbox.entire_channel_here.message": "By using @here you are about to send notifications to up to {totalMembers, number} {totalMembers, plural, one {person} other {people}}. Are you sure you want to do this?",
|
||||
"mobile.post_textbox.entire_channel_here.message.with_timezones": "By using @here you are about to send notifications up to {totalMembers, number} {totalMembers, plural, one {person} other {people}} in {timezones, number} {timezones, plural, one {timezone} other {timezones}}. Are you sure you want to do this?",
|
||||
"mobile.post_textbox.entire_channel.cancel": "Cancel",
|
||||
"mobile.post_textbox.entire_channel.confirm": "Confirm",
|
||||
"mobile.post_textbox.entire_channel.message": "By using @all or @channel you are about to send notifications to {totalMembers, number} {totalMembers, plural, one {person} other {people}}. Are you sure you want to do this?",
|
||||
|
|
|
|||
Loading…
Reference in a new issue