add extra protection to those channel/object followed immediately by accessing its "channel_id" field (#1960)

This commit is contained in:
Saturnino Abril 2018-08-02 01:04:58 +08:00 committed by Elias Nahum
parent 1783bf9731
commit 3a70e5c43f
6 changed files with 11 additions and 9 deletions

View file

@ -55,7 +55,7 @@ export function loadFromPushNotification(notification) {
const {data} = notification;
const {currentTeamId, teams, myMembers: myTeamMembers} = state.entities.teams;
const {currentChannelId, channels} = state.entities.channels;
const channelId = data.channel_id;
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;

View file

@ -32,7 +32,7 @@ import PostBody from './post_body';
const POST_TIMEOUT = 20000;
function mapStateToProps(state, ownProps) {
const post = getPost(state, ownProps.postId);
const post = getPost(state, ownProps.postId) || {};
const channel = getChannel(state, post.channel_id) || {};
const channelIsArchived = channel ? channel.delete_at !== 0 : false;
const teamId = channel.team_id;

View file

@ -21,7 +21,8 @@ function makeMapStateToProps() {
const getReactionsForPostSelector = makeGetReactionsForPost();
return function mapStateToProps(state, ownProps) {
const post = getPost(state, ownProps.postId);
const channel = getChannel(state, post.channel_id) || {};
const channelId = post ? post.channel_id : '';
const channel = getChannel(state, channelId);
const teamId = channel.team_id;
const channelIsArchived = channel.delete_at !== 0;
@ -33,12 +34,12 @@ function makeMapStateToProps() {
} else if (hasNewPermissions(state)) {
canAddReaction = haveIChannelPermission(state, {
team: teamId,
channel: post.channel_id,
channel: channelId,
permission: Permissions.ADD_REACTION,
});
canRemoveReaction = haveIChannelPermission(state, {
team: teamId,
channel: post.channel_id,
channel: channelId,
permission: Permissions.REMOVE_REACTION,
});
}

View file

@ -51,7 +51,7 @@ export default class Root extends PureComponent {
const {data} = notification;
const {currentChannelId, navigator} = this.props;
if (data.channel_id !== currentChannelId) {
if (data && data.channel_id !== currentChannelId) {
navigator.showInAppNotification({
screen: 'Notification',
position: 'top',

View file

@ -269,8 +269,9 @@ export default class Permalink extends PureComponent {
}
if (!channelId) {
focusChannelId = post.data.posts[focusedPostId].channel_id;
if (!this.props.myMembers[focusChannelId]) {
const focusedPost = post.data.posts[focusedPostId];
focusChannelId = focusedPost ? focusedPost.channel_id : '';
if (focusChannelId && !this.props.myMembers[focusChannelId]) {
const {data: channel} = await actions.getChannel(focusChannelId);
if (channel && channel.type === General.OPEN_CHANNEL) {
await actions.joinChannel(currentUserId, channel.team_id, channel.id);

View file

@ -13,7 +13,7 @@ function makeMapStateToProps() {
const getChannel = makeGetChannel();
return (state, ownProps) => {
const post = getPost(state, ownProps.postId);
const channel = getChannel(state, {id: post.channel_id});
const channel = post ? getChannel(state, {id: post.channel_id}) : null;
return {
displayName: channel ? channel.display_name : '',