summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-07-05 16:28:32 -0400
committerenahum <nahumhbl@gmail.com>2017-07-05 16:28:32 -0400
commit04e364f4f7f9e132c9929f44851a5608a5c0bf21 (patch)
tree5d821e69c2a8db7254f9c6afa13bf3f4955a3736 /webapp
parentd59cac0314b4cec2c2dd5dca305928e2b363928a (diff)
downloadchat-04e364f4f7f9e132c9929f44851a5608a5c0bf21.tar.gz
chat-04e364f4f7f9e132c9929f44851a5608a5c0bf21.tar.bz2
chat-04e364f4f7f9e132c9929f44851a5608a5c0bf21.zip
Do not scroll center channel to bottom when posting in RHS (#6852)
Diffstat (limited to 'webapp')
-rw-r--r--webapp/actions/global_actions.jsx5
-rw-r--r--webapp/components/create_post.jsx3
-rw-r--r--webapp/components/post_view/post_list.jsx23
3 files changed, 16 insertions, 15 deletions
diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx
index 2ab2692c0..33a1c8432 100644
--- a/webapp/actions/global_actions.jsx
+++ b/webapp/actions/global_actions.jsx
@@ -551,8 +551,9 @@ export function redirectUserToDefaultTeam() {
}
}
-export function postListScrollChange() {
+export function postListScrollChange(forceScrollToBottom = false) {
AppDispatcher.handleViewAction({
- type: EventTypes.POST_LIST_SCROLL_CHANGE
+ type: EventTypes.POST_LIST_SCROLL_CHANGE,
+ value: forceScrollToBottom
});
}
diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx
index 56f392292..4a2cf5302 100644
--- a/webapp/components/create_post.jsx
+++ b/webapp/components/create_post.jsx
@@ -261,7 +261,8 @@ export default class CreatePost extends React.Component {
});
}
- PostActions.createPost(post, this.state.fileInfos, null,
+ PostActions.createPost(post, this.state.fileInfos,
+ () => GlobalActions.postListScrollChange(true),
(err) => {
if (err.id === 'api.post.create_post.root_id.app_error') {
// this should never actually happen since you can't reply from this textbox
diff --git a/webapp/components/post_view/post_list.jsx b/webapp/components/post_view/post_list.jsx
index a0aed8152..13cc28da3 100644
--- a/webapp/components/post_view/post_list.jsx
+++ b/webapp/components/post_view/post_list.jsx
@@ -117,12 +117,12 @@ export default class PostList extends React.PureComponent {
this.loadPosts(this.props.channel.id, this.props.focusedPostId);
GlobalEventEmitter.addListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize);
- window.addEventListener('resize', this.handleResize);
+ window.addEventListener('resize', () => this.handleResize());
}
componentWillUnmount() {
GlobalEventEmitter.removeListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize);
- window.removeEventListener('resize', this.handleResize);
+ window.removeEventListener('resize', () => this.handleResize());
}
componentWillReceiveProps(nextProps) {
@@ -210,20 +210,18 @@ export default class PostList extends React.PureComponent {
}
if (postList && prevPosts && posts && posts[0] && prevPosts[0]) {
- // A new message was posted, so scroll to bottom if it was from current user
- // or if user was already scrolled close to bottom
+ // A new message was posted, so scroll to bottom if user
+ // was already scrolled close to bottom
let doScrollToBottom = false;
- if (posts[0].id !== prevPosts[0].id && posts[0].pending_post_id !== prevPosts[0].pending_post_id) {
+ const postId = posts[0].id;
+ const prevPostId = prevPosts[0].id;
+ const pendingPostId = posts[0].pending_post_id;
+ if (postId !== prevPostId && pendingPostId !== prevPostId) {
// If already scrolled to bottom
if (this.wasAtBottom()) {
doScrollToBottom = true;
}
- // If new post was by current user
- if (posts[0].user_id === this.props.currentUserId) {
- doScrollToBottom = true;
- }
-
// If new post was ephemeral
if (Utils.isPostEphemeral(posts[0])) {
doScrollToBottom = true;
@@ -252,10 +250,11 @@ export default class PostList extends React.PureComponent {
return this.previousClientHeight + this.previousScrollTop >= this.previousScrollHeight - CLOSE_TO_BOTTOM_SCROLL_MARGIN;
}
- handleResize = () => {
+ handleResize = (forceScrollToBottom) => {
const postList = this.refs.postlist;
+ const doScrollToBottom = this.wasAtBottom() || forceScrollToBottom;
- if (postList && this.wasAtBottom()) {
+ if (postList && doScrollToBottom) {
postList.scrollTop = postList.scrollHeight;
this.previousScrollHeight = postList.scrollHeight;