summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-07-12 17:36:45 -0400
committerSaturnino Abril <saturnino.abril@gmail.com>2017-07-13 06:36:45 +0900
commitdf3290c4cf93101b5104e7395d9a0af208eff513 (patch)
tree99c70c37c53303bea602c9c872e4b12a9e635912 /webapp
parent259ad46f30d0fac2f7c5c14f3b76b2170f7e90c7 (diff)
downloadchat-df3290c4cf93101b5104e7395d9a0af208eff513.tar.gz
chat-df3290c4cf93101b5104e7395d9a0af208eff513.tar.bz2
chat-df3290c4cf93101b5104e7395d9a0af208eff513.zip
PLT-7093/PLT-7096 Updates to new message below indicator (#6912)
* Updates to new message below indicator * Fixes per feedback
Diffstat (limited to 'webapp')
-rw-r--r--webapp/components/post_view/post_list.jsx47
1 files changed, 33 insertions, 14 deletions
diff --git a/webapp/components/post_view/post_list.jsx b/webapp/components/post_view/post_list.jsx
index ba20622f9..c42c62377 100644
--- a/webapp/components/post_view/post_list.jsx
+++ b/webapp/components/post_view/post_list.jsx
@@ -110,7 +110,7 @@ export default class PostList extends React.PureComponent {
atEnd: false,
unViewedCount: 0,
isScrolling: false,
- lastViewed: Number.MAX_SAFE_INTEGER
+ lastViewed: props.lastViewedAt
};
}
@@ -146,24 +146,19 @@ export default class PostList extends React.PureComponent {
this.hasScrolledToFocusedPost = false;
this.hasScrolledToNewMessageSeparator = false;
this.atBottom = false;
- this.setState({atEnd: false});
+ this.setState({atEnd: false, lastViewed: nextProps.lastViewedAt});
if (nextChannel.id) {
this.loadPosts(nextChannel.id);
}
- return;
}
- if (!this.atBottom && this.props.posts !== nextProps.posts && this.hasScrolledToNewMessageSeparator) {
- const unViewedCount = nextProps.posts.reduce((count, post) => {
- if (post.create_at > this.state.lastViewed &&
- post.user_id !== nextProps.currentUserId &&
- post.state !== Constants.POST_DELETED) {
- return count + 1;
- }
- return count;
- }, 0);
- this.setState({unViewedCount});
+ const nextPosts = nextProps.posts || [];
+ const posts = this.props.posts || [];
+ const hasNewPosts = (posts.length === 0 && nextPosts.length > 0) || (posts.length > 0 && nextPosts.length > 0 && posts[0].id !== nextPosts[0].id);
+
+ if (!this.checkBottom() && hasNewPosts) {
+ this.setUnreadsBelow(nextPosts, nextProps.currentUserId);
}
}
}
@@ -205,6 +200,9 @@ export default class PostList extends React.PureComponent {
if (messageSeparator && !this.hasScrolledToNewMessageSeparator) {
const element = ReactDOM.findDOMNode(messageSeparator);
element.scrollIntoView();
+ if (!this.checkBottom()) {
+ this.setUnreadsBelow(posts, this.props.currentUserId);
+ }
return;
} else if (postList && !this.hasScrolledToNewMessageSeparator) {
postList.scrollTop = postList.scrollHeight;
@@ -244,6 +242,18 @@ export default class PostList extends React.PureComponent {
}
}
+ setUnreadsBelow = (posts, currentUserId) => {
+ const unViewedCount = posts.reduce((count, post) => {
+ if (post.create_at > this.state.lastViewed &&
+ post.user_id !== currentUserId &&
+ post.state !== Constants.POST_DELETED) {
+ return count + 1;
+ }
+ return count;
+ }, 0);
+ this.setState({unViewedCount});
+ }
+
handleScrollStop = () => {
this.setState({
isScrolling: false
@@ -251,6 +261,15 @@ export default class PostList extends React.PureComponent {
}
checkBottom = () => {
+ if (!this.refs.postlist) {
+ return false;
+ }
+
+ // No scroll bar so we're at the bottom
+ if (this.refs.postlist.scrollHeight <= this.refs.postlist.clientHeight) {
+ return true;
+ }
+
return this.refs.postlist.clientHeight + this.refs.postlist.scrollTop >= this.refs.postlist.scrollHeight - CLOSE_TO_BOTTOM_SCROLL_MARGIN;
}
@@ -323,7 +342,7 @@ export default class PostList extends React.PureComponent {
});
}
- if (this.atBottom) {
+ if (this.checkBottom()) {
this.setState({
lastViewed: new Date().getTime(),
unViewedCount: 0,