From 19502f9aaa88dc6ea89a792cc6a1933895e1ddec Mon Sep 17 00:00:00 2001 From: enahum Date: Wed, 13 Sep 2017 12:00:33 -0300 Subject: [PATCH] RN-344 open push notifications faster (#899) --- app/actions/views/channel.js | 5 +++-- app/actions/views/root.js | 22 +++++++++++----------- app/components/root/root.js | 16 ++++------------ package.json | 2 +- yarn.lock | 8 ++++---- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index f36b9d35d..77505f679 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -39,7 +39,7 @@ export function loadChannelsIfNecessary(teamId) { export function loadProfilesAndTeamMembersForDMSidebar(teamId) { return async (dispatch, getState) => { const state = getState(); - const {currentUserId} = state.entities.users; + const {currentUserId, profilesInChannel} = state.entities.users; const {channels, myMembers} = state.entities.channels; const {myPreferences} = state.entities.preferences; const {membersInTeam} = state.entities.teams; @@ -96,7 +96,8 @@ export function loadProfilesAndTeamMembersForDMSidebar(teamId) { } for (const [key, pref] of gmPrefs) { - if (pref.value === 'true') { + //only load the profiles in channels if we don't already have them + if (pref.value === 'true' && !profilesInChannel[key]) { loadProfilesForChannels.push(key); } } diff --git a/app/actions/views/root.js b/app/actions/views/root.js index 3bc34650a..e60dfb8ba 100644 --- a/app/actions/views/root.js +++ b/app/actions/views/root.js @@ -4,15 +4,13 @@ import {ViewTypes} from 'app/constants'; import { handleSelectChannel, - loadChannelsIfNecessary, - loadProfilesAndTeamMembersForDMSidebar, setChannelDisplayName } from 'app/actions/views/channel'; import {handleTeamChange, selectFirstAvailableTeam} from 'app/actions/views/select_team'; import {General} from 'mattermost-redux/constants'; import {getClientConfig, getLicenseConfig} from 'mattermost-redux/actions/general'; -import {markChannelAsRead, viewChannel} from 'mattermost-redux/actions/channels'; +import {getChannelAndMyMember, markChannelAsRead, viewChannel} from 'mattermost-redux/actions/channels'; export function loadConfigAndLicense() { return async (dispatch, getState) => { @@ -42,28 +40,30 @@ export function goToNotification(notification) { const state = getState(); const {data} = notification; const {currentTeamId, teams} = state.entities.teams; - const {currentChannelId} = state.entities.channels; + const {channels, currentChannelId, myMembers} = state.entities.channels; 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; + const teamId = data.team_id || currentTeamId; dispatch(setChannelDisplayName('')); - if (teamId) { + if (teamId && teamId !== currentTeamId) { handleTeamChange(teams[teamId], false)(dispatch, getState); - await loadChannelsIfNecessary(teamId)(dispatch, getState); - } else { + } else if (!teamId) { await selectFirstAvailableTeam()(dispatch, getState); - teamId = state.entities.team.currentTeamId; } - viewChannel(channelId)(dispatch, getState); - loadProfilesAndTeamMembersForDMSidebar(teamId)(dispatch, getState); + if (!channels[channelId] || !myMembers[channelId]) { + getChannelAndMyMember(channelId)(dispatch, getState); + } if (channelId !== currentChannelId) { handleSelectChannel(channelId)(dispatch, getState); } + + viewChannel(channelId)(dispatch, getState); + markChannelAsRead(channelId, currentChannelId)(dispatch, getState); }; } diff --git a/app/components/root/root.js b/app/components/root/root.js index a093d814a..47b58ec08 100644 --- a/app/components/root/root.js +++ b/app/components/root/root.js @@ -99,18 +99,10 @@ export default class Root extends PureComponent { }); }; - handleNotificationTapped = () => { - const {navigator, theme} = this.props; - - navigator.resetTo({ - screen: 'Channel', - animated: true, - navigatorStyle: { - navBarHidden: true, - statusBarHidden: false, - statusBarHideWithNavBar: false, - screenBackgroundColor: theme.centerChannelBg - } + handleNotificationTapped = async () => { + const {navigator} = this.props; + navigator.popToRoot({ + animated: false }); }; diff --git a/package.json b/package.json index 243a63888..99402e468 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "react-native-keyboard-aware-scroll-view": "0.2.8", "react-native-linear-gradient": "2.0.0", "react-native-local-auth": "enahum/react-native-local-auth.git", - "react-native-navigation": "1.1.131", + "react-native-navigation": "1.1.216", "react-native-notifications": "enahum/react-native-notifications.git", "react-native-orientation": "enahum/react-native-orientation.git", "react-native-passcode-status": "1.1.0", diff --git a/yarn.lock b/yarn.lock index 3bb54ea90..6e041eed0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3713,7 +3713,7 @@ makeerror@1.0.x: mattermost-redux@mattermost/mattermost-redux#master: version "0.0.1" - resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/1afaf513717108b609c4dc677cf49d474624e0ca" + resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/51f9ab2b2e163bbca75213fa44b2a3a96f916c9f" dependencies: deep-equal "1.0.1" harmony-reflect "1.5.1" @@ -4645,9 +4645,9 @@ react-native-mock@^0.2.7: react-timer-mixin "^0.13.3" warning "^2.1.0" -react-native-navigation@1.1.131: - version "1.1.131" - resolved "https://registry.yarnpkg.com/react-native-navigation/-/react-native-navigation-1.1.131.tgz#79b0583def2310e93305048f7149ad1970666f51" +react-native-navigation@1.1.216: + version "1.1.216" + resolved "https://registry.yarnpkg.com/react-native-navigation/-/react-native-navigation-1.1.216.tgz#aa0771fdfa8e37caf57f8470067e807b0cbc2de1" dependencies: lodash "4.x.x"