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
This commit is contained in:
parent
22b71797ce
commit
4574a54241
4 changed files with 15 additions and 10 deletions
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue