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
This commit is contained in:
enahum
2016-06-09 15:28:57 -03:00
committed by Corey Hulen
parent f1eefd99e6
commit 18c53e03eb
6 changed files with 33 additions and 26 deletions

View File

@@ -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,

View File

@@ -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') {

View File

@@ -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
};

View File

@@ -115,6 +115,7 @@ export default class PostFocusView extends React.Component {
showMoreMessagesTop={!this.state.atTop}
showMoreMessagesBottom={!this.state.atBottom}
postsToHighlight={postsToHighlight}
isFocusPost={true}
/>
);
}

View File

@@ -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();

View File

@@ -41,6 +41,7 @@ export default {
CREATE_CHANNEL: null,
LEAVE_CHANNEL: null,
CREATE_POST: null,
CREATE_COMMENT: null,
POST_DELETED: null,
REMOVE_POST: null,