diff options
author | enahum <nahumhbl@gmail.com> | 2016-06-09 15:28:57 -0300 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-06-09 11:28:57 -0700 |
commit | 18c53e03ebaf1021c5b8429ef7bce09e5de0c4a6 (patch) | |
tree | ccaa7bd967f50d005e517401abcfc59536fa18c9 /webapp | |
parent | f1eefd99e6e40621ace005afcb1c08c6a69a744e (diff) | |
download | chat-18c53e03ebaf1021c5b8429ef7bce09e5de0c4a6.tar.gz chat-18c53e03ebaf1021c5b8429ef7bce09e5de0c4a6.tar.bz2 chat-18c53e03ebaf1021c5b8429ef7bce09e5de0c4a6.zip |
PLT-3221 Remove async call to get posts when creating a comment and editing a post (#3300)
PLT-3203 Commenting on the RHS while in permalink view makes the message not show up in the RHS
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/actions/global_actions.jsx | 18 | ||||
-rw-r--r-- | webapp/components/create_comment.jsx | 18 | ||||
-rw-r--r-- | webapp/components/post_view/components/post_list.jsx | 8 | ||||
-rw-r--r-- | webapp/components/post_view/post_focus_view_controller.jsx | 1 | ||||
-rw-r--r-- | webapp/stores/post_store.jsx | 13 | ||||
-rw-r--r-- | webapp/utils/constants.jsx | 1 |
6 files changed, 33 insertions, 26 deletions
diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx index 0b264a9b3..ca3bf6362 100644 --- a/webapp/actions/global_actions.jsx +++ b/webapp/actions/global_actions.jsx @@ -134,6 +134,7 @@ export function doFocusPost(channelId, postId, data) { AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_FOCUSED_POST, postId, + channelId, post_list: data }); AsyncClient.getChannels(true); @@ -208,25 +209,25 @@ export function emitPostFocusRightHandSideFromSearch(post, isMentionSearch) { export function emitLoadMorePostsEvent() { const id = ChannelStore.getCurrentId(); - loadMorePostsTop(id); + loadMorePostsTop(id, false); } export function emitLoadMorePostsFocusedTopEvent() { const id = PostStore.getFocusedPostId(); - loadMorePostsTop(id); + loadMorePostsTop(id, true); } -export function loadMorePostsTop(id) { +export function loadMorePostsTop(id, isFocusPost) { const earliestPostId = PostStore.getEarliestPost(id).id; if (PostStore.requestVisibilityIncrease(id, Constants.POST_CHUNK_SIZE)) { - AsyncClient.getPostsBefore(earliestPostId, 0, Constants.POST_CHUNK_SIZE); + AsyncClient.getPostsBefore(earliestPostId, 0, Constants.POST_CHUNK_SIZE, isFocusPost); } } export function emitLoadMorePostsFocusedBottomEvent() { const id = PostStore.getFocusedPostId(); const latestPostId = PostStore.getLatestPost(id).id; - AsyncClient.getPostsAfter(latestPostId, 0, Constants.POST_CHUNK_SIZE); + AsyncClient.getPostsAfter(latestPostId, 0, Constants.POST_CHUNK_SIZE, !!id); } export function emitPostRecievedEvent(post, msg) { @@ -259,6 +260,13 @@ export function emitUserPostedEvent(post) { }); } +export function emitUserCommentedEvent(post) { + AppDispatcher.handleServerAction({ + type: ActionTypes.CREATE_COMMENT, + post + }); +} + export function emitPostDeletedEvent(post) { AppDispatcher.handleServerAction({ type: ActionTypes.POST_DELETED, diff --git a/webapp/components/create_comment.jsx b/webapp/components/create_comment.jsx index 73758e73c..454d8bf43 100644 --- a/webapp/components/create_comment.jsx +++ b/webapp/components/create_comment.jsx @@ -5,7 +5,6 @@ import $ from 'jquery'; import ReactDOM from 'react-dom'; import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import Client from 'utils/web_client.jsx'; -import ChannelStore from 'stores/channel_store.jsx'; import UserStore from 'stores/user_store.jsx'; import PostDeletedModal from './post_deleted_modal.jsx'; import PostStore from 'stores/post_store.jsx'; @@ -144,22 +143,11 @@ class CreateComment extends React.Component { post.user_id = userId; post.create_at = time; - PostStore.storePendingPost(post); - PostStore.storeCommentDraft(this.props.rootId, null); - + GlobalActions.emitUserCommentedEvent(post); Client.createPost( post, - (data) => { - const channel = ChannelStore.get(this.props.channelId); - const member = ChannelStore.getMember(this.props.channelId); - member.msg_count = channel.total_msg_count; - member.last_viewed_at = Date.now(); - ChannelStore.setChannelMember(member); - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_POST, - post: data - }); + () => { + // DO nothing. Websockets will handle this. }, (err) => { if (err.id === 'api.post.create_post.root_id.app_error') { diff --git a/webapp/components/post_view/components/post_list.jsx b/webapp/components/post_view/components/post_list.jsx index 28be93544..902ad25bf 100644 --- a/webapp/components/post_view/components/post_list.jsx +++ b/webapp/components/post_view/components/post_list.jsx @@ -137,7 +137,10 @@ export default class PostList extends React.Component { } loadMorePostsTop() { - GlobalActions.emitLoadMorePostsEvent(); + if (this.props.isFocusPost) { + return GlobalActions.emitLoadMorePostsFocusedTopEvent(); + } + return GlobalActions.emitLoadMorePostsEvent(); } loadMorePostsBottom() { @@ -522,5 +525,6 @@ PostList.propTypes = { displayNameType: React.PropTypes.string, displayPostsInCenter: React.PropTypes.bool, compactDisplay: React.PropTypes.bool, - previewsCollapsed: React.PropTypes.string + previewsCollapsed: React.PropTypes.string, + isFocusPost: React.PropTypes.bool }; diff --git a/webapp/components/post_view/post_focus_view_controller.jsx b/webapp/components/post_view/post_focus_view_controller.jsx index 7c1da6566..c70ebb0f5 100644 --- a/webapp/components/post_view/post_focus_view_controller.jsx +++ b/webapp/components/post_view/post_focus_view_controller.jsx @@ -115,6 +115,7 @@ export default class PostFocusView extends React.Component { showMoreMessagesTop={!this.state.atTop} showMoreMessagesBottom={!this.state.atBottom} postsToHighlight={postsToHighlight} + isFocusPost={true} /> ); } diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx index 062997f2b..73cb60314 100644 --- a/webapp/stores/post_store.jsx +++ b/webapp/stores/post_store.jsx @@ -231,13 +231,14 @@ class PostStoreClass extends EventEmitter { this.postsInfo[post.channel_id].postList = postList; } - storeFocusedPost(postId, postList) { + storeFocusedPost(postId, channelId, postList) { const focusedPost = postList.posts[postId]; if (!focusedPost) { return; } this.currentFocusedPostId = postId; this.storePosts(postId, postList); + this.storePosts(channelId, postList); } checkBounds(id, numRequested, postList, before) { @@ -407,11 +408,11 @@ class PostStoreClass extends EventEmitter { return null; } - let posts; + const posts = {}; let pendingPosts; for (const k in this.postsInfo) { if (this.postsInfo[k].postList && this.postsInfo[k].postList.posts.hasOwnProperty(this.selectedPostId)) { - posts = this.postsInfo[k].postList.posts; + Object.assign(posts, this.postsInfo[k].postList.posts); if (this.postsInfo[k].pendingPosts != null) { pendingPosts = this.postsInfo[k].pendingPosts.posts; } @@ -559,7 +560,7 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => { } case ActionTypes.RECEIVED_FOCUSED_POST: PostStore.clearChannelVisibility(action.postId, false); - PostStore.storeFocusedPost(action.postId, makePostListNonNull(action.post_list)); + PostStore.storeFocusedPost(action.postId, action.channelId, makePostListNonNull(action.post_list)); PostStore.emitChange(); break; case ActionTypes.RECEIVED_POST: @@ -579,6 +580,10 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => { PostStore.storeDraft(action.post.channel_id, null); PostStore.jumpPostsViewToBottom(); break; + case ActionTypes.CREATE_COMMENT: + PostStore.storePendingPost(action.post); + PostStore.storeCommentDraft(action.post.root_id, null); + break; case ActionTypes.POST_DELETED: PostStore.deletePost(action.post); PostStore.emitChange(); diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx index 3a6098713..c8807ae8d 100644 --- a/webapp/utils/constants.jsx +++ b/webapp/utils/constants.jsx @@ -41,6 +41,7 @@ export default { CREATE_CHANNEL: null, LEAVE_CHANNEL: null, CREATE_POST: null, + CREATE_COMMENT: null, POST_DELETED: null, REMOVE_POST: null, |