From 3bde858a64aa67326caa88dfc1d12d9a888e65d0 Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Thu, 21 Jun 2018 08:43:17 -0400 Subject: [PATCH] =?UTF-8?q?MM-10717:=20Update=20longpress=20buttons=20when?= =?UTF-8?q?=20add=20reaction,=20edit=20post,=20or=20d=E2=80=A6=20(#1779)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MM-10717: Update longpress buttons when add reaction, edit post, or delete post permissions change. * MM-10717: Makes tooltip actions prop required. * MM-10717: Switches all direct access of 'config' and 'license' to use selectors. --- app/actions/views/account_notifications.js | 3 ++- app/actions/views/login.js | 4 ++- app/actions/views/select_team.js | 3 ++- .../channels_list/list/index.js | 4 ++- app/components/post/index.js | 4 ++- app/components/post_body/index.js | 26 +++++++++++++++++-- app/components/post_header/index.js | 3 ++- app/components/post_profile_picture/index.js | 3 ++- app/components/tooltip.js | 10 ++++++- app/screens/about/index.js | 4 ++- app/screens/channel_info/index.js | 4 ++- app/screens/entry/index.js | 3 ++- app/screens/login/index.js | 4 ++- app/screens/login_options/index.js | 4 ++- app/screens/more_channels/index.js | 4 ++- app/screens/notification/index.js | 5 ++-- app/screens/select_server/index.js | 4 ++- app/screens/settings/general/index.js | 4 +-- .../settings/notification_settings/index.js | 4 ++- app/screens/user_profile/index.js | 3 ++- .../android/extension_post/index.js | 4 ++- 21 files changed, 83 insertions(+), 24 deletions(-) diff --git a/app/actions/views/account_notifications.js b/app/actions/views/account_notifications.js index 120548b3b..6c6a8ac88 100644 --- a/app/actions/views/account_notifications.js +++ b/app/actions/views/account_notifications.js @@ -4,11 +4,12 @@ import {updateMe} from 'mattermost-redux/actions/users'; import {Preferences} from 'mattermost-redux/constants'; import {savePreferences} from 'mattermost-redux/actions/preferences'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; export function handleUpdateUserNotifyProps(notifyProps) { return async (dispatch, getState) => { const state = getState(); - const config = state.entities.general.config; + const config = getConfig(state); const {currentUserId} = state.entities.users; const {interval, user_id: userId, ...otherProps} = notifyProps; diff --git a/app/actions/views/login.js b/app/actions/views/login.js index 860bca5d1..dbe1f076a 100644 --- a/app/actions/views/login.js +++ b/app/actions/views/login.js @@ -8,6 +8,7 @@ import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; import {ViewTypes} from 'app/constants'; import {app} from 'app/mattermost'; +import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; export function handleLoginIdChanged(loginId) { return async (dispatch, getState) => { @@ -30,7 +31,8 @@ export function handlePasswordChanged(password) { export function handleSuccessfulLogin() { return async (dispatch, getState) => { const state = getState(); - const {config, license} = state.entities.general; + const config = getConfig(state); + const license = getLicense(state); const token = Client4.getToken(); const url = Client4.getUrl(); const deviceToken = state.entities.general.deviceToken; diff --git a/app/actions/views/select_team.js b/app/actions/views/select_team.js index 4f6694a23..3e7d69f71 100644 --- a/app/actions/views/select_team.js +++ b/app/actions/views/select_team.js @@ -11,6 +11,7 @@ import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels' import {NavigationTypes} from 'app/constants'; import {setChannelDisplayName} from './channel'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; export function handleTeamChange(teamId, selectChannel = true) { return async (dispatch, getState) => { @@ -40,7 +41,7 @@ export function selectDefaultTeam() { return async (dispatch, getState) => { const state = getState(); - const {ExperimentalPrimaryTeam} = state.entities.general.config; + const {ExperimentalPrimaryTeam} = getConfig(state); const {teams: allTeams, myMembers} = state.entities.teams; const teams = Object.keys(myMembers).map((key) => allTeams[key]); diff --git a/app/components/channel_drawer/channels_list/list/index.js b/app/components/channel_drawer/channels_list/list/index.js index edde53767..6157b4682 100644 --- a/app/components/channel_drawer/channels_list/list/index.js +++ b/app/components/channel_drawer/channels_list/list/index.js @@ -16,11 +16,13 @@ import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getTheme, getFavoritesPreferences} from 'mattermost-redux/selectors/entities/preferences'; import {showCreateOption} from 'mattermost-redux/utils/channel_utils'; import {isAdmin as checkIsAdmin, isSystemAdmin as checkIsSystemAdmin} from 'mattermost-redux/utils/user_utils'; +import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import List from './list'; function mapStateToProps(state) { - const {config, license} = state.entities.general; + const config = getConfig(state); + const license = getLicense(state); const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; const unreadChannelIds = getSortedUnreadChannelIds(state); const favoriteChannelIds = getSortedFavoriteChannelIds(state); diff --git a/app/components/post/index.js b/app/components/post/index.js index bf1a3cc34..6aafa6274 100644 --- a/app/components/post/index.js +++ b/app/components/post/index.js @@ -12,6 +12,7 @@ import {getMyPreferences, getTheme} from 'mattermost-redux/selectors/entities/pr import {getCurrentTeamUrl, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {canDeletePost, canEditPost, isPostFlagged} from 'mattermost-redux/utils/post_utils'; import {isAdmin as checkIsAdmin, isSystemAdmin as checkIsSystemAdmin} from 'mattermost-redux/utils/user_utils'; +import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import {insertToDraft, setPostTooltipVisible} from 'app/actions/views/channel'; import {addReaction} from 'app/actions/views/emoji'; @@ -22,7 +23,8 @@ import Post from './post'; function mapStateToProps(state, ownProps) { const post = getPost(state, ownProps.postId); - const {config, license} = state.entities.general; + const config = getConfig(state); + const license = getLicense(state); const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; const myPreferences = getMyPreferences(state); const currentUserId = getCurrentUserId(state); diff --git a/app/components/post_body/index.js b/app/components/post_body/index.js index cdb23d2d0..d62b84571 100644 --- a/app/components/post_body/index.js +++ b/app/components/post_body/index.js @@ -9,18 +9,23 @@ import { General, Posts, } from 'mattermost-redux/constants'; -import {getChannel, canManageChannelMembers} from 'mattermost-redux/selectors/entities/channels'; +import {getChannel, canManageChannelMembers, getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; -import {hasNewPermissions} from 'mattermost-redux/selectors/entities/general'; +import {hasNewPermissions, getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; +import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; +import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import Permissions from 'mattermost-redux/constants/permissions'; import { isEdited, isPostEphemeral, isSystemMessage, + canEditPost, + canDeletePost, } from 'mattermost-redux/utils/post_utils'; +import {isAdmin as checkIsAdmin, isSystemAdmin as checkIsSystemAdmin} from 'mattermost-redux/utils/user_utils'; import PostBody from './post_body'; @@ -52,6 +57,21 @@ function mapStateToProps(state, ownProps) { const isUserCanManageMembers = canManageChannelMembers(state); const isEphemeralPost = isPostEphemeral(post); + const config = getConfig(state); + const license = getLicense(state); + const currentUserId = getCurrentUserId(state); + const currentTeamId = getCurrentTeamId(state); + const currentChannelId = getCurrentChannelId(state); + const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; + const isAdmin = checkIsAdmin(roles); + const isSystemAdmin = checkIsSystemAdmin(roles); + let canDelete = false; + let canEdit = false; + if (post) { + canDelete = canDeletePost(state, config, license, currentTeamId, currentChannelId, currentUserId, post, isAdmin, isSystemAdmin); + canEdit = canEditPost(state, config, license, currentTeamId, currentChannelId, currentUserId, post); + } + let isPostAddChannelMember = false; if ( channel && @@ -79,6 +99,8 @@ function mapStateToProps(state, ownProps) { message: post.message, theme: getTheme(state), canAddReaction, + canDelete, + canEdit, }; } diff --git a/app/components/post_header/index.js b/app/components/post_header/index.js index bbff47f49..35ff9a708 100644 --- a/app/components/post_header/index.js +++ b/app/components/post_header/index.js @@ -9,13 +9,14 @@ import {getBool, getTeammateNameDisplaySetting, getTheme} from 'mattermost-redux import {getUser} from 'mattermost-redux/selectors/entities/users'; import {isPostPendingOrFailed, isSystemMessage} from 'mattermost-redux/utils/post_utils'; import {displayUsername} from 'mattermost-redux/utils/user_utils'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; import PostHeader from './post_header'; function makeMapStateToProps() { const getCommentCountForPost = makeGetCommentCountForPost(); return function mapStateToProps(state, ownProps) { - const {config} = state.entities.general; + const config = getConfig(state); const post = getPost(state, ownProps.postId); const commentedOnUser = getUser(state, ownProps.commentedOnUserId); const user = getUser(state, post.user_id) || {}; diff --git a/app/components/post_profile_picture/index.js b/app/components/post_profile_picture/index.js index 243e5d17b..e2ae12456 100644 --- a/app/components/post_profile_picture/index.js +++ b/app/components/post_profile_picture/index.js @@ -7,11 +7,12 @@ import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {isSystemMessage} from 'mattermost-redux/utils/post_utils'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; import PostProfilePicture from './post_profile_picture'; function mapStateToProps(state, ownProps) { - const {config} = state.entities.general; + const config = getConfig(state); const post = getPost(state, ownProps.postId); return { diff --git a/app/components/tooltip.js b/app/components/tooltip.js index 5e92bf858..0ddac3047 100644 --- a/app/components/tooltip.js +++ b/app/components/tooltip.js @@ -5,12 +5,13 @@ import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import RNToolTip from 'react-native-tooltip'; -import {setToolTipVisible} from 'app/utils/tooltip'; +import {setToolTipVisible, getToolTipVisible} from 'app/utils/tooltip'; export default class ToolTip extends PureComponent { static propTypes = { onHide: PropTypes.func, onShow: PropTypes.func, + actions: PropTypes.array.isRequired, }; handleHide = () => { @@ -39,6 +40,13 @@ export default class ToolTip extends PureComponent { } }; + componentDidUpdate(prevProps) { + if (prevProps.actions.length !== this.props.actions.length && getToolTipVisible()) { + this.refs.toolTip.hideMenu(); + setTimeout(() => this.refs.toolTip.showMenu(), 1); + } + } + render() { return ( { }; function mapStateToProps(state) { - const {config} = state.entities.general; + const config = getConfig(state); return { config, diff --git a/app/screens/login/index.js b/app/screens/login/index.js index ebc571444..5170cfdbd 100644 --- a/app/screens/login/index.js +++ b/app/screens/login/index.js @@ -6,6 +6,7 @@ import {connect} from 'react-redux'; import LoginActions from 'app/actions/views/login'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; +import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import {checkMfa, login} from 'mattermost-redux/actions/users'; @@ -13,7 +14,8 @@ import Login from './login.js'; function mapStateToProps(state) { const {checkMfa: checkMfaRequest, login: loginRequest} = state.requests.users; - const {config, license} = state.entities.general; + const config = getConfig(state); + const license = getLicense(state); return { ...state.views.login, checkMfaRequest, diff --git a/app/screens/login_options/index.js b/app/screens/login_options/index.js index 46e45b83c..bb885e5bd 100644 --- a/app/screens/login_options/index.js +++ b/app/screens/login_options/index.js @@ -4,11 +4,13 @@ import {connect} from 'react-redux'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; +import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import LoginOptions from './login_options'; function mapStateToProps(state) { - const {config, license} = state.entities.general; + const config = getConfig(state); + const license = getLicense(state); return { config, license, diff --git a/app/screens/more_channels/index.js b/app/screens/more_channels/index.js index 1360f6e4a..096e644cc 100644 --- a/app/screens/more_channels/index.js +++ b/app/screens/more_channels/index.js @@ -14,6 +14,7 @@ import {isAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; import {handleSelectChannel, setChannelDisplayName} from 'app/actions/views/channel'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; +import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import MoreChannels from './more_channels'; @@ -31,7 +32,8 @@ function mapStateToProps(state) { const {currentUserId} = state.entities.users; const {currentTeamId} = state.entities.teams; const {getChannels: requestStatus} = state.requests.channels; - const {config, license} = state.entities.general; + const config = getConfig(state); + const license = getLicense(state); const roles = getCurrentUserRoles(state); const channels = joinableChannels(state); diff --git a/app/screens/notification/index.js b/app/screens/notification/index.js index 123e4829c..7674cf74a 100644 --- a/app/screens/notification/index.js +++ b/app/screens/notification/index.js @@ -10,6 +10,7 @@ import {getDimensions} from 'app/selectors/device'; import {getChannel} from 'mattermost-redux/selectors/entities/channels'; import {getTeammateNameDisplaySetting, getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {getUser} from 'mattermost-redux/selectors/entities/users'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; import Notification from './notification'; @@ -26,9 +27,9 @@ function mapStateToProps(state, ownProps) { if (data.channel_id) { channel = getChannel(state, data.channel_id); } - + const config = getConfig(state); return { - config: state.entities.general.config, + config, channel, deviceWidth, user, diff --git a/app/screens/select_server/index.js b/app/screens/select_server/index.js index c453c58cd..386e7fca5 100644 --- a/app/screens/select_server/index.js +++ b/app/screens/select_server/index.js @@ -13,11 +13,13 @@ import {loadConfigAndLicense} from 'app/actions/views/root'; import {handleServerUrlChanged} from 'app/actions/views/select_server'; import getClientUpgrade from 'app/selectors/client_upgrade'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; +import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import SelectServer from './select_server'; function mapStateToProps(state) { - const {config, license} = state.entities.general; + const config = getConfig(state); + const license = getLicense(state); const {currentVersion, latestVersion, minVersion} = getClientUpgrade(state); return { diff --git a/app/screens/settings/general/index.js b/app/screens/settings/general/index.js index d9bcff056..4278e4f06 100644 --- a/app/screens/settings/general/index.js +++ b/app/screens/settings/general/index.js @@ -6,7 +6,7 @@ import {connect} from 'react-redux'; import {clearErrors} from 'mattermost-redux/actions/errors'; import {getCurrentUrl} from 'mattermost-redux/selectors/entities/general'; -import {getJoinableTeams} from 'mattermost-redux/selectors/entities/teams'; +import {getJoinableTeams, getConfig} from 'mattermost-redux/selectors/entities/teams'; import {purgeOfflineStore} from 'app/actions/views/root'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; @@ -15,7 +15,7 @@ import {removeProtocol} from 'app/utils/url'; import Settings from './settings'; function mapStateToProps(state) { - const {config} = state.entities.general; + const config = getConfig(state); return { config, diff --git a/app/screens/settings/notification_settings/index.js b/app/screens/settings/notification_settings/index.js index 40a308efc..d2491fa91 100644 --- a/app/screens/settings/notification_settings/index.js +++ b/app/screens/settings/notification_settings/index.js @@ -8,12 +8,14 @@ import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; import {getMyPreferences, getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {handleUpdateUserNotifyProps} from 'app/actions/views/account_notifications'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; import NotificationSettings from './notification_settings'; function mapStateToProps(state) { + const config = getConfig(state); return { - config: state.entities.general.config, + config, currentUser: getCurrentUser(state), myPreferences: getMyPreferences(state), updateMeRequest: state.requests.users.updateMe, diff --git a/app/screens/user_profile/index.js b/app/screens/user_profile/index.js index c33bd5a88..d6bde6368 100644 --- a/app/screens/user_profile/index.js +++ b/app/screens/user_profile/index.js @@ -10,11 +10,12 @@ import {makeDirectChannel} from 'app/actions/views/more_dms'; import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; import {getTeammateNameDisplaySetting, getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; import UserProfile from './user_profile'; function mapStateToProps(state, ownProps) { - const {config} = state.entities.general; + const config = getConfig(state); const {createChannel: createChannelRequest} = state.requests.channels; return { diff --git a/share_extension/android/extension_post/index.js b/share_extension/android/extension_post/index.js index 170e281c0..7e62aa5cc 100644 --- a/share_extension/android/extension_post/index.js +++ b/share_extension/android/extension_post/index.js @@ -6,13 +6,15 @@ import {connect} from 'react-redux'; import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getAllowedServerMaxFileSize} from 'app/utils/file'; import ExtensionPost from './extension_post'; function mapStateToProps(state) { - const {config, credentials} = state.entities.general; + const config = getConfig(state); + const {credentials} = state.entities.general; const {token, url} = credentials; return {