diff options
-rw-r--r-- | webapp/components/post_view/post_view_controller.jsx | 24 | ||||
-rw-r--r-- | webapp/stores/post_store.jsx | 13 | ||||
-rw-r--r-- | webapp/utils/async_client.jsx | 5 |
3 files changed, 31 insertions, 11 deletions
diff --git a/webapp/components/post_view/post_view_controller.jsx b/webapp/components/post_view/post_view_controller.jsx index 58f8eff74..9ff986b43 100644 --- a/webapp/components/post_view/post_view_controller.jsx +++ b/webapp/components/post_view/post_view_controller.jsx @@ -50,6 +50,9 @@ export default class PostViewController extends React.Component { statuses = Object.assign({}, UserStore.getStatuses()); } + // If we haven't received a page time then we aren't done loading the posts yet + const loading = PostStore.getLatestPostFromPageTime(channel.id) === 0; + this.state = { channel, postList: PostStore.filterPosts(channel.id, joinLeaveEnabled), @@ -59,6 +62,7 @@ export default class PostViewController extends React.Component { atTop: PostStore.getVisibilityAtTop(channel.id), lastViewed, ownNewMessage: false, + loading, scrollType: ScrollTypes.NEW_MESSAGE, displayNameType: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', 'false'), displayPostsInCenter: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.CHANNEL_DISPLAY_MODE, Preferences.CHANNEL_DISPLAY_MODE_DEFAULT) === Preferences.CHANNEL_DISPLAY_MODE_CENTERED, @@ -113,11 +117,19 @@ export default class PostViewController extends React.Component { onPostsChange() { const joinLeaveEnabled = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'join_leave', true); + const loading = PostStore.getLatestPostFromPageTime(this.state.channel.id) === 0; - this.setState({ + const newState = { postList: PostStore.filterPosts(this.state.channel.id, joinLeaveEnabled), - atTop: PostStore.getVisibilityAtTop(this.state.channel.id) - }); + atTop: PostStore.getVisibilityAtTop(this.state.channel.id), + loading + }; + + if (this.state.loading && !loading) { + newState.scrollType = ScrollTypes.NEW_MESSAGE; + } + + this.setState(newState); } onStatusChange() { @@ -219,6 +231,10 @@ export default class PostViewController extends React.Component { return true; } + if (nextState.loading !== this.state.loading) { + return true; + } + if (nextState.atTop !== this.state.atTop) { return true; } @@ -292,7 +308,7 @@ export default class PostViewController extends React.Component { render() { let content; - if (this.state.postList == null) { + if (this.state.postList == null || this.state.loading) { content = ( <LoadingScreen position='absolute' diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx index 0d838a3df..62283dacd 100644 --- a/webapp/stores/post_store.jsx +++ b/webapp/stores/post_store.jsx @@ -198,11 +198,16 @@ class PostStoreClass extends EventEmitter { return; } - if (checkLatest && newPosts.order.length >= 1) { + if (checkLatest) { const currentLatest = this.latestPageTime[id] || 0; - const newLatest = newPosts.posts[newPosts.order[0]].create_at || 0; - if (newLatest > currentLatest) { - this.latestPageTime[id] = newLatest; + if (newPosts.order.length >= 1) { + const newLatest = newPosts.posts[newPosts.order[0]].create_at || 0; + if (newLatest > currentLatest) { + this.latestPageTime[id] = newLatest; + } + } else if (currentLatest === 0) { + // Mark that an empty page was received + this.latestPageTime[id] = 1; } } diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx index 74064169f..729160fe4 100644 --- a/webapp/utils/async_client.jsx +++ b/webapp/utils/async_client.jsx @@ -609,14 +609,13 @@ export function getPosts(id) { } const postList = PostStore.getAllPosts(channelId); + const latestPostTime = PostStore.getLatestPostFromPageTime(id); - if ($.isEmptyObject(postList) || postList.order.length < Constants.POST_CHUNK_SIZE) { + if ($.isEmptyObject(postList) || postList.order.length < Constants.POST_CHUNK_SIZE || latestPostTime === 0) { getPostsPage(channelId, Constants.POST_CHUNK_SIZE); return; } - const latestPostTime = PostStore.getLatestPostFromPageTime(id); - callTracker['getPosts_' + channelId] = utils.getTimestamp(); Client.getPosts( |