From e26be5554aa18a63f9efaab99b0aa452de916cbe Mon Sep 17 00:00:00 2001 From: enahum Date: Wed, 29 Mar 2017 15:32:02 -0300 Subject: [PATCH] PLT 6062 - Fixing Push Notifications (#418) * PLT-6062 Don't show in-app notification if current channel * PLT-6131 make drawer titles all caps * PLT-6027 fix handle Push notifications for DM/GM --- app/actions/views/root.js | 16 +++++--- .../channel_drawer_list.js | 9 ++--- app/components/push_notification/index.js | 3 +- .../push_notification/push_notification.js | 38 +++++++++++-------- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/app/actions/views/root.js b/app/actions/views/root.js index c445159f9..c695024cd 100644 --- a/app/actions/views/root.js +++ b/app/actions/views/root.js @@ -47,20 +47,24 @@ export function clearNotification() { export function goToNotification(notification) { return async (dispatch, getState) => { + const state = getState(); const {data} = notification; - let teamId = data.team_id; + const {currentTeamId, teams} = state.entities.teams; + const channelId = data.channel_id; + + // if the notification does not have a team id is because its from a DM or GM + let teamId = data.team_id || currentTeamId; + if (teamId) { - const {teams} = getState().entities.teams; await handleTeamChange(teams[teamId])(dispatch, getState); - loadChannelsIfNecessary(teamId)(dispatch, getState); + await loadChannelsIfNecessary(teamId)(dispatch, getState); } else { await selectFirstAvailableTeam()(dispatch, getState); - teamId = getState().entities.teams.currentTeamId; + teamId = currentTeamId; } - const channelId = data.channel_id; viewChannel(teamId, channelId)(dispatch, getState); - loadProfilesAndTeamMembersForDMSidebar(teamId)(dispatch, getState); + await loadProfilesAndTeamMembersForDMSidebar(teamId)(dispatch, getState); await handleSelectChannel(channelId)(dispatch, getState); goToChannelView()(dispatch, getState); markChannelAsRead(teamId, channelId)(dispatch, getState); diff --git a/app/components/channel_drawer_list/channel_drawer_list.js b/app/components/channel_drawer_list/channel_drawer_list.js index 1407736b7..bf996565e 100644 --- a/app/components/channel_drawer_list/channel_drawer_list.js +++ b/app/components/channel_drawer_list/channel_drawer_list.js @@ -255,15 +255,14 @@ class ChannelDrawerList extends Component { }; renderTitle = (styles, id, defaultMessage, action, bottomDivider) => { + const {formatMessage} = this.props.intl; return ( {this.renderDivider(styles, 0)} - + + {formatMessage({id, defaultMessage}).toUpperCase()} + {action && this.renderSectionAction(styles, action)} {bottomDivider && this.renderDivider(styles, 16)} diff --git a/app/components/push_notification/index.js b/app/components/push_notification/index.js index 507018895..c82a71871 100644 --- a/app/components/push_notification/index.js +++ b/app/components/push_notification/index.js @@ -11,13 +11,14 @@ import {getUnreads} from 'mattermost-redux/selectors/entities/channels'; import PushNotification from './push_notification'; function mapStateToProps(state, ownProps) { - const {currentTeamId} = state.entities.teams; + const {currentTeamId, teams} = state.entities.teams; const {currentChannelId} = state.entities.channels; return { ...ownProps, currentTeamId, currentChannelId, + teams, ...getUnreads(state) }; } diff --git a/app/components/push_notification/push_notification.js b/app/components/push_notification/push_notification.js index 05077a6d3..1920ddeb9 100644 --- a/app/components/push_notification/push_notification.js +++ b/app/components/push_notification/push_notification.js @@ -16,6 +16,7 @@ export default class PushNotification extends PureComponent { static propTypes = { currentTeamId: PropTypes.string, currentChannelId: PropTypes.string, + teams: PropTypes.object, actions: PropTypes.shape({ goToNotification: PropTypes.func.isRequired, queueNotification: PropTypes.func.isRequired, @@ -23,6 +24,10 @@ export default class PushNotification extends PureComponent { }).isRequired }; + static defaultProps: { + teams: {} + }; + constructor(props) { super(props); @@ -88,9 +93,9 @@ export default class PushNotification extends PureComponent { }; onNotificationTapped = (notification) => { - const {currentTeamId, currentChannelId} = this.props; + const {currentTeamId, currentChannelId, teams} = this.props; - if (currentTeamId && currentChannelId) { + if (currentTeamId && currentChannelId && Object.keys(teams).length) { // this means that the store has the necessary data this.props.actions.goToNotification(notification); } else { @@ -99,20 +104,23 @@ export default class PushNotification extends PureComponent { }; handleInAppNotification = (notification) => { - const {message} = notification; + const {data, message} = notification; + const {currentChannelId} = this.props; - MessageBarManager.showAlert({ - alertType: 'info', - avatar: icon, - avatarStyle: {borderRadius: 10, width: 20, height: 20}, - message, - stylesheetInfo: {backgroundColor: changeOpacity('#000', 0.9)}, - messageStyle: {color: 'white', fontSize: 13}, - viewTopInset: 15, - viewBottomInset: 15, - duration: 5000, - onTapped: () => this.onNotificationTapped(notification) - }); + if (data.channel_id !== currentChannelId) { + MessageBarManager.showAlert({ + alertType: 'info', + avatar: icon, + avatarStyle: {borderRadius: 10, width: 20, height: 20}, + message, + stylesheetInfo: {backgroundColor: changeOpacity('#000', 0.9)}, + messageStyle: {color: 'white', fontSize: 13}, + viewTopInset: 15, + viewBottomInset: 15, + duration: 5000, + onTapped: () => this.onNotificationTapped(notification) + }); + } }; render() {