Skip to content

Commit

Permalink
MM-14800 Fix missing messages when switching to a team not previously…
Browse files Browse the repository at this point in the history
… loaded (mattermost#2562)

* Check that this.props.posts is not null when loading more posts

* Fix isChannelLoading to prevent race condition while switching teams

* Remove unnecesary variable
  • Loading branch information
enahum authored and saturninoabril committed Mar 29, 2019
1 parent b820709 commit 3537b03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 12 additions & 7 deletions components/post_view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {withRouter} from 'react-router-dom';
import {getPosts, getPostsAfter, getPostsBefore, getPostThread} from 'mattermost-redux/actions/posts';
import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {makeGetPostsAroundPost, makeGetPostsInChannel} from 'mattermost-redux/selectors/entities/posts';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {getCurrentUserId, getUser} from 'mattermost-redux/selectors/entities/users';
import {getTeamByName} from 'mattermost-redux/selectors/entities/teams';

import {increasePostVisibility} from 'actions/post_actions.jsx';
Expand All @@ -21,17 +21,18 @@ import PostList from './post_list.jsx';
// This function is added as a fail safe for the channel sync issue we have.
// When the user switches to a team for the first time we show the channel of previous team and then settle for the right channel after that
// This causes the scroll correction etc an issue because post_list is not mounted for new channel instead it is updated
const isChannelLoading = (params, channel, team) => {
const isChannelLoading = (params, channel, team, teammate) => {
if (params.postid) {
return false;
}

if (channel && team) {
if (channel.type !== Constants.DM_CHANNEL && channel.type !== Constants.GM_CHANNEL) {
if (channel.name !== params.identifier) {
return true;
}
if (channel.type !== Constants.DM_CHANNEL && channel.name !== params.identifier) {
return true;
} else if (channel.type === Constants.DM_CHANNEL && teammate && params.identifier !== `@${teammate.username}`) {
return true;
}

if (channel.team_id && channel.team_id !== team.id) {
return true;
}
Expand Down Expand Up @@ -59,8 +60,12 @@ function makeMapStateToProps() {

const channel = getChannel(state, ownProps.channelId);
const team = getTeamByName(state, ownProps.match.params.team);
let teammate;
if (channel.type === Constants.DM_CHANNEL && channel.teammate_id) {
teammate = getUser(state, channel.teammate_id);
}

const channelLoading = isChannelLoading(ownProps.match.params, channel, team);
const channelLoading = isChannelLoading(ownProps.match.params, channel, team, teammate);
const lastViewedAt = state.views.channel.lastChannelViewTime[ownProps.channelId];
const {postIds, postsObjById} = preparePostIdsForPostList(state, {posts, lastViewedAt, indicateNewMessages: true});

Expand Down
3 changes: 2 additions & 1 deletion components/post_view/post_list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export default class PostList extends React.PureComponent {

this.loadingPosts = false;
this.extraPagesLoaded = 0;

const channelIntroMessage = PostListRowListIds.CHANNEL_INTRO_MESSAGE;
const isMobile = Utils.isMobile();
this.state = {
Expand Down Expand Up @@ -260,7 +261,7 @@ export default class PostList extends React.PureComponent {
}
} else {
this.loadingPosts = false;
if (this.mounted) {
if (this.mounted && this.props.posts) {
const atEnd = !moreToLoad && this.props.posts.length < this.props.postVisibility;
const newState = {
atEnd,
Expand Down

0 comments on commit 3537b03

Please sign in to comment.