From c769b536aeab8427723bff4b4c215f919329c40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Tue, 16 Apr 2019 23:34:02 +0200 Subject: [PATCH] Creating the concept of RedirectChannel and use it before the DefaultChannel when we are redirecting the user (#2674) * Creating the concept of RedirectChannel and use it before the DefaultChannel when we are redirecting the user * upgrading to the last mattermost-redux version --- app/actions/views/channel.js | 14 ++++++++++---- package-lock.json | 4 ++-- package.json | 2 +- share_extension/android/actions/index.js | 8 +++++--- share_extension/common/selectors/index.js | 8 -------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index b927f69b7..08a8e064e 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -24,8 +24,14 @@ import {savePreferences} from 'mattermost-redux/actions/preferences'; import {getTeamMembersByIds} from 'mattermost-redux/actions/teams'; import {getProfilesInChannel} from 'mattermost-redux/actions/users'; import {General, Preferences} from 'mattermost-redux/constants'; -import {getChannel, getCurrentChannelId, getMyChannelMember} from 'mattermost-redux/selectors/entities/channels'; import {getPostIdsInChannel} from 'mattermost-redux/selectors/entities/posts'; +import { + getChannel, + getCurrentChannelId, + getMyChannelMember, + getRedirectChannelNameForTeam, + getChannelByName as getChannelByNameSelector, +} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentTeamId, getTeamByName} from 'mattermost-redux/selectors/entities/teams'; import { @@ -330,16 +336,16 @@ export function selectPenultimateChannel(teamId) { export function selectDefaultChannel(teamId) { return (dispatch, getState) => { - const {channels} = getState().entities.channels; + const state = getState(); - const channel = Object.values(channels).find((c) => c.team_id === teamId && c.name === General.DEFAULT_CHANNEL); + const channel = getChannelByNameSelector(state, getRedirectChannelNameForTeam(state, teamId)); let channelId; if (channel) { channelId = channel.id; } else { // Handle case when the default channel cannot be found // so we need to get the first available channel of the team - const channelsInTeam = Object.values(channels).filter((c) => c.team_id === teamId); + const channelsInTeam = Object.values(state.entities.channels).filter((c) => c.team_id === teamId); const firstChannel = channelsInTeam.length ? channelsInTeam[0].id : {id: ''}; channelId = firstChannel.id; diff --git a/package-lock.json b/package-lock.json index 813bb392e..29f1dac66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9730,8 +9730,8 @@ "integrity": "sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==" }, "mattermost-redux": { - "version": "github:mattermost/mattermost-redux#29e65f58b0fb536e6923b270aa848208986f01ab", - "from": "github:mattermost/mattermost-redux#29e65f58b0fb536e6923b270aa848208986f01ab", + "version": "github:mattermost/mattermost-redux#477150436ac1871d0d63954c4f4f4d16ff692483", + "from": "github:mattermost/mattermost-redux#477150436ac1871d0d63954c4f4f4d16ff692483", "requires": { "deep-equal": "1.0.1", "eslint-plugin-header": "3.0.0", diff --git a/package.json b/package.json index 008b6cd2e..973949a90 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "intl": "1.2.5", "jail-monkey": "2.0.0", "jsc-android": "236355.1.1", - "mattermost-redux": "github:mattermost/mattermost-redux#29e65f58b0fb536e6923b270aa848208986f01ab", + "mattermost-redux": "github:mattermost/mattermost-redux#477150436ac1871d0d63954c4f4f4d16ff692483", "mime-db": "1.38.0", "moment-timezone": "0.5.23", "prop-types": "15.7.2", diff --git a/share_extension/android/actions/index.js b/share_extension/android/actions/index.js index 631972ac3..6030752f8 100644 --- a/share_extension/android/actions/index.js +++ b/share_extension/android/actions/index.js @@ -2,18 +2,20 @@ // See LICENSE.txt for license information. import {fetchMyChannelsAndMembers} from 'mattermost-redux/actions/channels'; +import {getRedirectChannelNameForTeam, getChannelByName} from 'mattermost-redux/selectors/entities/channels'; import {loadProfilesAndTeamMembersForDMSidebar} from 'app/actions/views/channel'; import {ViewTypes} from 'app/constants'; -import {getDefaultChannelForTeam} from 'share_extension/common/selectors'; export function getTeamChannels(teamId) { return async (dispatch, getState) => { await dispatch(fetchMyChannelsAndMembers(teamId)); dispatch(loadProfilesAndTeamMembersForDMSidebar(teamId)); - const defaultChannel = getDefaultChannelForTeam(getState(), teamId); - return defaultChannel.id; + const state = getState(); + const redirectChannel = getChannelByName(state, getRedirectChannelNameForTeam(state, teamId)); + + return redirectChannel.id; }; } diff --git a/share_extension/common/selectors/index.js b/share_extension/common/selectors/index.js index 59c51b64d..fda071ea5 100644 --- a/share_extension/common/selectors/index.js +++ b/share_extension/common/selectors/index.js @@ -25,14 +25,6 @@ import { } from 'mattermost-redux/utils/channel_utils'; import {createIdsSelector} from 'mattermost-redux/utils/helpers'; -export const getDefaultChannelForTeam = createSelector( - getAllChannels, - (state, teamId) => teamId, - (channels, teamId) => { - return Object.values(channels).find((c) => c.team_id === teamId && c.name === General.DEFAULT_CHANNEL); - } -); - export const getChannelIdsForExtensionTeam = createIdsSelector( (state) => state.views.extension.selectedTeamId, getChannelsInTeam,