From 4574a54241e969a0ef0f83e8ebc79579c0401c35 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 20 Jun 2017 09:32:55 -0400 Subject: [PATCH] RN-219 Attempting to fix missing posts (#653) * RN-219 Changed loadPostsIfNecessary to get since latest Post.CreateAt * RN-219 Changed post list refresh to always get the latest page of posts * Updated yarn.lock --- app/actions/views/channel.js | 13 ++++++++----- app/components/post_list/index.js | 6 ++++-- app/components/post_list/post_list.js | 4 ++-- yarn.lock | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index 83e3e2d42..e51602f8a 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -27,6 +27,7 @@ import { isDirectChannel, isGroupChannel } from 'mattermost-redux/utils/channel_utils'; +import {getLastCreateAt} from 'mattermost-redux/utils/post_utils'; import {getPreferencesByCategory} from 'mattermost-redux/utils/preference_utils'; export function loadChannelsIfNecessary(teamId) { @@ -138,17 +139,19 @@ export function loadProfilesAndTeamMembersForDMSidebar(teamId) { export function loadPostsIfNecessary(channel) { return async (dispatch, getState) => { const state = getState(); - const {channelsLastFetch} = state.internal; - const lastFetchTime = channelsLastFetch[channel.id] || 0; - const {postsInChannel} = state.entities.posts; + const {posts, postsInChannel} = state.entities.posts; + const postsIds = postsInChannel[channel.id]; // Get the first page of posts if it appears we haven't gotten it yet, like the webapp - if (!postsIds || postsIds.length < Posts.POST_CHUNK_SIZE || !lastFetchTime) { + if (!postsIds || postsIds.length < Posts.POST_CHUNK_SIZE) { return getPosts(channel.id)(dispatch, getState); } - return getPostsSince(channel.id, lastFetchTime)(dispatch, getState); + const postsForChannel = postsIds.map((id) => posts[id]); + const latestPostTime = getLastCreateAt(postsForChannel); + + return getPostsSince(channel.id, latestPostTime)(dispatch, getState); }; } diff --git a/app/components/post_list/index.js b/app/components/post_list/index.js index 26d1c333a..fdd6d39d0 100644 --- a/app/components/post_list/index.js +++ b/app/components/post_list/index.js @@ -4,9 +4,11 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {loadPostsIfNecessary, setChannelRefreshing} from 'app/actions/views/channel'; +import {setChannelRefreshing} from 'app/actions/views/channel'; import {getTheme} from 'app/selectors/preferences'; +import {getPosts} from 'mattermost-redux/actions/posts'; + import PostList from './post_list'; function mapStateToProps(state, ownProps) { @@ -23,7 +25,7 @@ function mapStateToProps(state, ownProps) { function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ - loadPostsIfNecessary, + getPosts, setChannelRefreshing }, dispatch) }; diff --git a/app/components/post_list/post_list.js b/app/components/post_list/post_list.js index 97e2208ab..0992ae6d8 100644 --- a/app/components/post_list/post_list.js +++ b/app/components/post_list/post_list.js @@ -24,7 +24,7 @@ const LOAD_MORE_POSTS = 'load-more-posts'; export default class PostList extends Component { static propTypes = { actions: PropTypes.shape({ - loadPostsIfNecessary: PropTypes.func.isRequired, + getPosts: PropTypes.func.isRequired, setChannelRefreshing: PropTypes.func.isRequired }).isRequired, channel: PropTypes.object, @@ -96,7 +96,7 @@ export default class PostList extends Component { if (Object.keys(channel).length) { actions.setChannelRefreshing(true); - actions.loadPostsIfNecessary(channel); + actions.getPosts(channel.id); } }; diff --git a/yarn.lock b/yarn.lock index bb478bf6d..5e1b71108 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3645,7 +3645,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/fe5182358d2e2f0897b4fd5c80cba96e85061d96" + resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/723745e8cef00be940620239f8791eaefa4062ce" dependencies: deep-equal "1.0.1" harmony-reflect "1.5.1"