[MM-11492] Add protection in accessing ".team_id" field when it's immediately accessed after the object is created (#1963)

* add protection in accessing ".team_id" field when it's immediately accessed after the object is created.

* remove lastChannelId since lastChannel is being checked already
This commit is contained in:
Saturnino Abril 2018-08-03 22:52:43 +08:00 committed by Elias Nahum
parent 102faceb2b
commit 2fe9d8842a
3 changed files with 14 additions and 6 deletions

View file

@ -259,8 +259,11 @@ export function selectInitialChannel(teamId) {
const isGMVisible = lastChannel && lastChannel.type === General.GM_CHANNEL &&
isGroupChannelVisible(myPreferences, lastChannel);
if (lastChannelId && myMembers[lastChannelId] &&
(lastChannel.team_id === teamId || isDMVisible || isGMVisible)) {
if (
myMembers[lastChannelId] &&
lastChannel &&
(lastChannel.team_id === teamId || isDMVisible || isGMVisible)
) {
handleSelectChannel(lastChannelId)(dispatch, getState);
markChannelAsRead(lastChannelId)(dispatch, getState);
return;

View file

@ -55,10 +55,15 @@ export function loadFromPushNotification(notification) {
const {data} = notification;
const {currentTeamId, teams, myMembers: myTeamMembers} = state.entities.teams;
const {currentChannelId, channels} = state.entities.channels;
const channelId = data ? data.channel_id : '';
// when the notification does not have a team id is because its from a DM or GM
const teamId = data.team_id || currentTeamId;
let channelId = '';
let teamId = currentTeamId;
if (data) {
channelId = data.channel_id;
// when the notification does not have a team id is because its from a DM or GM
teamId = data.team_id || currentTeamId;
}
// load any missing data
const loading = [];

View file

@ -22,7 +22,7 @@ function makeMapStateToProps() {
return function mapStateToProps(state, ownProps) {
const post = getPost(state, ownProps.postId);
const channelId = post ? post.channel_id : '';
const channel = getChannel(state, channelId);
const channel = getChannel(state, channelId) || {};
const teamId = channel.team_id;
const channelIsArchived = channel.delete_at !== 0;