MM-21068 Notify when attempting to enter private channel/group via explicit link (#3759)

This commit is contained in:
Amit Uttam 2020-01-14 00:57:06 -03:00 committed by Miguel Alatzar
parent 2951245d68
commit f3b0e4aa28
4 changed files with 39 additions and 3 deletions

View file

@ -406,9 +406,14 @@ export function handleSelectChannelByName(channelName, teamName) {
const {teams: currentTeams, currentTeamId} = state.entities.teams;
const currentTeam = currentTeams[currentTeamId];
const currentTeamName = currentTeam?.name;
const {data: channel} = await dispatch(getChannelByNameAndTeamName(teamName || currentTeamName, channelName));
const response = await dispatch(getChannelByNameAndTeamName(teamName || currentTeamName, channelName));
const {error, data: channel} = response;
const currentChannelId = getCurrentChannelId(state);
if (error) {
return {error};
}
if (teamName && teamName !== currentTeamName) {
const team = getTeamByName(state, teamName);
dispatch(selectTeam(team));
@ -417,6 +422,8 @@ export function handleSelectChannelByName(channelName, teamName) {
if (channel && currentChannelId !== channel.id) {
dispatch(handleSelectChannel(channel.id));
}
return null;
};
}

View file

@ -152,7 +152,7 @@ describe('Actions.Views.Channel', () => {
test('handleSelectChannelByName failure from null currentTeamName', async () => {
const failStoreObj = {...storeObj};
failStoreObj.entities.teams.teams.currentTeamId = 'not-in-current-teams';
store = mockStore(storeObj);
store = mockStore(failStoreObj);
await store.dispatch(handleSelectChannelByName(currentChannelName, null));
@ -164,6 +164,23 @@ describe('Actions.Views.Channel', () => {
expect(storeBatchActions).toBe(false);
});
test('handleSelectChannelByName failure from no permission to channel', async () => {
actions.getChannelByNameAndTeamName = jest.fn(() => {
return {
type: 'MOCK_ERROR',
error: {
message: "Can't get to channel.",
},
};
});
await store.dispatch(handleSelectChannelByName(currentChannelName, currentTeamName));
const storeActions = store.getActions();
const receivedChannel = storeActions.some((action) => action.type === MOCK_RECEIVE_CHANNEL_TYPE);
expect(receivedChannel).toBe(false);
});
test('loadPostsIfNecessaryWithRetry for the first time', async () => {
store = mockStore(storeObj);

View file

@ -12,6 +12,8 @@ import {DeepLinkTypes} from 'app/constants';
import {getCurrentServerUrl} from 'app/init/credentials';
import mattermostManaged from 'app/mattermost_managed';
import BottomSheet from 'app/utils/bottom_sheet';
import {alertErrorWithFallback} from 'app/utils/general';
import {t} from 'app/utils/i18n';
import {preventDoubleTap} from 'app/utils/tap';
import {matchDeepLink, normalizeProtocol} from 'app/utils/url';
@ -56,7 +58,16 @@ export default class MarkdownLink extends PureComponent {
if (match) {
if (match.type === DeepLinkTypes.CHANNEL) {
this.props.actions.handleSelectChannelByName(match.channelName, match.teamName);
const error = await this.props.actions.handleSelectChannelByName(match.channelName, match.teamName);
if (error) {
const linkFailedMessage = {
id: t('mobile.server_link.private_channel.error'),
defaultMessage: 'You are not a member of this private channel.',
};
alertErrorWithFallback(this.context.intl, {}, linkFailedMessage);
}
} else if (match.type === DeepLinkTypes.PERMALINK) {
onPermalinkPress(match.postId, match.teamName);
}

View file

@ -445,6 +445,7 @@
"mobile.select_team.no_teams": "There are no available teams for you to join.",
"mobile.server_link.error.text": "The link could not be found on this server.",
"mobile.server_link.error.title": "Link Error",
"mobile.server_link.private_channel.error": "You are not a member of this private channel.",
"mobile.server_upgrade.button": "OK",
"mobile.server_upgrade.description": "\nA server upgrade is required to use the Mattermost app. Please ask your System Administrator for details.\n",
"mobile.server_upgrade.title": "Server upgrade required",