@@ -278,10 +278,10 @@ export default class RhsRootPost extends React.Component {
}
RhsRootPost.defaultProps = {
- post: null,
commentCount: 0
};
RhsRootPost.propTypes = {
- post: React.PropTypes.object,
+ post: React.PropTypes.object.isRequired,
+ user: React.PropTypes.object.isRequired,
commentCount: React.PropTypes.number
};
diff --git a/web/react/components/rhs_thread.jsx b/web/react/components/rhs_thread.jsx
index 667030b3ac..975a391717 100644
--- a/web/react/components/rhs_thread.jsx
+++ b/web/react/components/rhs_thread.jsx
@@ -19,39 +19,25 @@ export default class RhsThread extends React.Component {
this.mounted = false;
- this.onChange = this.onChange.bind(this);
- this.onChangeAll = this.onChangeAll.bind(this);
+ this.onPostChange = this.onPostChange.bind(this);
+ this.onUserChange = this.onUserChange.bind(this);
this.forceUpdateInfo = this.forceUpdateInfo.bind(this);
this.handleResize = this.handleResize.bind(this);
- const state = this.getStateFromStores();
+ const state = {};
state.windowWidth = Utils.windowWidth();
state.windowHeight = Utils.windowHeight();
+ state.selected = PostStore.getSelectedPost();
+ state.posts = PostStore.getSelectedPostThread();
+ state.profiles = JSON.parse(JSON.stringify(UserStore.getProfiles()));
+
this.state = state;
}
- getStateFromStores() {
- var postList = PostStore.getSelectedPost();
- if (!postList || postList.order.length < 1 || !postList.posts[postList.order[0]]) {
- return {postList: {}};
- }
-
- var channelId = postList.posts[postList.order[0]].channel_id;
- var pendingPostsList = PostStore.getPendingPosts(channelId);
-
- if (pendingPostsList) {
- for (var pid in pendingPostsList.posts) {
- if (pendingPostsList.posts.hasOwnProperty(pid)) {
- postList.posts[pid] = pendingPostsList.posts[pid];
- }
- }
- }
-
- return {postList: postList};
- }
componentDidMount() {
- PostStore.addSelectedPostChangeListener(this.onChange);
- PostStore.addChangeListener(this.onChangeAll);
+ PostStore.addSelectedPostChangeListener(this.onPostChange);
+ PostStore.addChangeListener(this.onPostChange);
PreferenceStore.addChangeListener(this.forceUpdateInfo);
+ UserStore.addChangeListener(this.onUserChange);
this.resize();
window.addEventListener('resize', this.handleResize);
@@ -65,14 +51,30 @@ export default class RhsThread extends React.Component {
this.resize();
}
componentWillUnmount() {
- PostStore.removeSelectedPostChangeListener(this.onChange);
- PostStore.removeChangeListener(this.onChangeAll);
+ PostStore.removeSelectedPostChangeListener(this.onPostChange);
+ PostStore.removeChangeListener(this.onPostChange);
PreferenceStore.removeChangeListener(this.forceUpdateInfo);
+ UserStore.removeChangeListener(this.onUserChange);
window.removeEventListener('resize', this.handleResize);
this.mounted = false;
}
+ shouldComponentUpdate(nextProps, nextState) {
+ if (!Utils.areObjectsEqual(nextState.posts, this.state.posts)) {
+ return true;
+ }
+
+ if (!Utils.areObjectsEqual(nextState.selected, this.state.selected)) {
+ return true;
+ }
+
+ if (!Utils.areObjectsEqual(nextState.profiles, this.state.profiles)) {
+ return true;
+ }
+
+ return false;
+ }
forceUpdateInfo() {
if (this.state.postList) {
for (var postId in this.state.postList.posts) {
@@ -88,49 +90,14 @@ export default class RhsThread extends React.Component {
windowHeight: Utils.windowHeight()
});
}
- onChange() {
- var newState = this.getStateFromStores();
- if (this.mounted && !Utils.areObjectsEqual(newState, this.state)) {
- this.setState(newState);
- }
+ onPostChange() {
+ const selected = PostStore.getSelectedPost();
+ const posts = PostStore.getSelectedPostThread();
+ this.setState({posts, selected});
}
- onChangeAll() {
- // if something was changed in the channel like adding a
- // comment or post then lets refresh the sidebar list
- var currentSelected = PostStore.getSelectedPost();
- if (!currentSelected || currentSelected.order.length === 0 || !currentSelected.posts[currentSelected.order[0]]) {
- return;
- }
-
- var currentPosts = PostStore.getVisiblePosts(currentSelected.posts[currentSelected.order[0]].channel_id);
-
- if (!currentPosts || currentPosts.order.length === 0) {
- return;
- }
-
- if (currentPosts.posts[currentPosts.order[0]].channel_id === currentSelected.posts[currentSelected.order[0]].channel_id) {
- for (var key in currentSelected.posts) {
- if (currentSelected.posts.hasOwnProperty(key)) {
- var post = currentSelected.posts[key];
- if (post.pending_post_id) {
- Reflect.deleteProperty(currentSelected.posts, key);
- }
- }
- }
-
- for (var postId in currentPosts.posts) {
- if (currentPosts.posts.hasOwnProperty(postId)) {
- currentSelected.posts[postId] = currentPosts.posts[postId];
- }
- }
-
- PostStore.storeSelectedPost(currentSelected);
- }
-
- var newState = this.getStateFromStores();
- if (this.mounted && !Utils.areObjectsEqual(newState, this.state)) {
- this.setState(newState);
- }
+ onUserChange() {
+ const profiles = JSON.parse(JSON.stringify(UserStore.getProfiles()));
+ this.setState({profiles});
}
resize() {
$('.post-right__scroll').scrollTop(100000);
@@ -140,29 +107,21 @@ export default class RhsThread extends React.Component {
}
}
render() {
- var postList = this.state.postList;
+ const posts = this.state.posts;
+ const selected = this.state.selected;
- if (postList == null || !postList.order) {
+ if (posts == null || selected == null) {
return (
);
}
- var selectedPost = postList.posts[postList.order[0]];
- var rootPost = null;
-
- if (selectedPost.root_id === '') {
- rootPost = selectedPost;
- } else {
- rootPost = postList.posts[selectedPost.root_id];
- }
-
var postsArray = [];
- for (var postId in postList.posts) {
- if (postList.posts.hasOwnProperty(postId)) {
- var cpost = postList.posts[postId];
- if (cpost.root_id === rootPost.id) {
+ for (const id in posts) {
+ if (posts.hasOwnProperty(id)) {
+ const cpost = posts[id];
+ if (cpost.root_id === selected.id) {
postsArray.push(cpost);
}
}
@@ -199,6 +158,13 @@ export default class RhsThread extends React.Component {
searchForm =
;
}
+ let profile;
+ if (UserStore.getCurrentId() === selected.user_id) {
+ profile = UserStore.getCurrentUser();
+ } else {
+ profile = this.state.profiles[selected.user_id];
+ }
+
return (
@@ -210,26 +176,33 @@ export default class RhsThread extends React.Component {
/>
{postsArray.map(function mapPosts(comPost) {
+ let p;
+ if (UserStore.getCurrentId() === selected.user_id) {
+ p = UserStore.getCurrentUser();
+ } else {
+ p = this.state.profiles[selected.user_id];
+ }
return (
);
})}
diff --git a/web/react/components/search_bar.jsx b/web/react/components/search_bar.jsx
index 1cdd09cc85..eaf8b5069b 100644
--- a/web/react/components/search_bar.jsx
+++ b/web/react/components/search_bar.jsx
@@ -87,7 +87,7 @@ class SearchBar extends React.Component {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_SELECTED,
- results: null
+ postId: null
});
}
handleUserInput(text) {
diff --git a/web/react/components/search_results_header.jsx b/web/react/components/search_results_header.jsx
index 7f88eb2c7b..20fe342dc9 100644
--- a/web/react/components/search_results_header.jsx
+++ b/web/react/components/search_results_header.jsx
@@ -32,7 +32,7 @@ export default class SearchResultsHeader extends React.Component {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_SELECTED,
- results: null
+ postId: null
});
}
diff --git a/web/react/components/user_profile.jsx b/web/react/components/user_profile.jsx
index 1e393cfe94..31b2b99072 100644
--- a/web/react/components/user_profile.jsx
+++ b/web/react/components/user_profile.jsx
@@ -2,7 +2,6 @@
// See License.txt for license information.
import * as Utils from '../utils/utils.jsx';
-import UserStore from '../stores/user_store.jsx';
import {FormattedMessage} from 'mm-intl';
@@ -19,45 +18,15 @@ function nextId() {
export default class UserProfile extends React.Component {
constructor(props) {
super(props);
-
this.uniqueId = nextId();
- this.onChange = this.onChange.bind(this);
-
- this.state = this.getStateFromStores(this.props.userId);
- }
- getStateFromStores(userId) {
- var profile = UserStore.getProfile(userId);
-
- if (profile == null) {
- return {profile: {id: '0', username: '...'}};
- }
-
- return {profile};
}
componentDidMount() {
- UserStore.addChangeListener(this.onChange);
if (!this.props.disablePopover) {
$('body').tooltip({selector: '[data-toggle=tooltip]', trigger: 'hover click'});
}
}
- componentWillUnmount() {
- UserStore.removeChangeListener(this.onChange);
- }
- onChange(userId) {
- if (!userId || userId === this.props.userId) {
- var newState = this.getStateFromStores(this.props.userId);
- if (!Utils.areObjectsEqual(newState, this.state)) {
- this.setState(newState);
- }
- }
- }
- componentWillReceiveProps(nextProps) {
- if (this.props.userId !== nextProps.userId) {
- this.setState(this.getStateFromStores(nextProps.userId));
- }
- }
render() {
- var name = Utils.displayUsername(this.state.profile.id);
+ var name = Utils.displayUsername(this.props.user.id);
if (this.props.overwriteName) {
name = this.props.overwriteName;
} else if (!name) {
@@ -68,7 +37,7 @@ export default class UserProfile extends React.Component {
return
{name}
;
}
- var profileImg = '/api/v1/users/' + this.state.profile.id + '/image?time=' + this.state.profile.update_at + '&' + Utils.getSessionIndex();
+ var profileImg = '/api/v1/users/' + this.props.user.id + '/image?time=' + this.props.user.update_at + '&' + Utils.getSessionIndex();
if (this.props.overwriteImage) {
profileImg = this.props.overwriteImage;
}
@@ -100,14 +69,14 @@ export default class UserProfile extends React.Component {
dataContent.push(
);
@@ -139,13 +108,13 @@ export default class UserProfile extends React.Component {
}
UserProfile.defaultProps = {
- userId: '',
+ user: {},
overwriteName: '',
overwriteImage: '',
disablePopover: false
};
UserProfile.propTypes = {
- userId: React.PropTypes.string,
+ user: React.PropTypes.object.isRequired,
overwriteName: React.PropTypes.string,
overwriteImage: React.PropTypes.string,
disablePopover: React.PropTypes.bool
diff --git a/web/react/stores/post_store.jsx b/web/react/stores/post_store.jsx
index f5c3421634..5100a4936a 100644
--- a/web/react/stores/post_store.jsx
+++ b/web/react/stores/post_store.jsx
@@ -20,72 +20,7 @@ const SELECTED_POST_CHANGE_EVENT = 'selected_post_change';
class PostStoreClass extends EventEmitter {
constructor() {
super();
-
- this.emitChange = this.emitChange.bind(this);
- this.addChangeListener = this.addChangeListener.bind(this);
- this.removeChangeListener = this.removeChangeListener.bind(this);
-
- this.emitEditPost = this.emitEditPost.bind(this);
- this.addEditPostListener = this.addEditPostListener.bind(this);
- this.removeEditPostListener = this.removeEditPostListner.bind(this);
-
- this.emitPostsViewJump = this.emitPostsViewJump.bind(this);
- this.addPostsViewJumpListener = this.addPostsViewJumpListener.bind(this);
- this.removePostsViewJumpListener = this.removePostsViewJumpListener.bind(this);
-
- this.emitPostFocused = this.emitPostFocused.bind(this);
- this.addPostFocusedListener = this.addPostFocusedListener.bind(this);
- this.removePostFocusedListener = this.removePostFocusedListener.bind(this);
-
- this.makePostsInfo = this.makePostsInfo.bind(this);
-
- this.getPost = this.getPost.bind(this);
- this.getAllPosts = this.getAllPosts.bind(this);
- this.getEarliestPost = this.getEarliestPost.bind(this);
- this.getLatestPost = this.getLatestPost.bind(this);
- this.getVisiblePosts = this.getVisiblePosts.bind(this);
- this.getVisibilityAtTop = this.getVisibilityAtTop.bind(this);
- this.getVisibilityAtBottom = this.getVisibilityAtBottom.bind(this);
- this.requestVisibilityIncrease = this.requestVisibilityIncrease.bind(this);
- this.getFocusedPostId = this.getFocusedPostId.bind(this);
-
- this.storePosts = this.storePosts.bind(this);
- this.storePost = this.storePost.bind(this);
- this.storeFocusedPost = this.storeFocusedPost.bind(this);
- this.checkBounds = this.checkBounds.bind(this);
-
- this.clearFocusedPost = this.clearFocusedPost.bind(this);
- this.clearChannelVisibility = this.clearChannelVisibility.bind(this);
-
- this.deletePost = this.deletePost.bind(this);
- this.removePost = this.removePost.bind(this);
-
- this.getPendingPosts = this.getPendingPosts.bind(this);
- this.storePendingPost = this.storePendingPost.bind(this);
- this.removePendingPost = this.removePendingPost.bind(this);
- this.clearPendingPosts = this.clearPendingPosts.bind(this);
- this.updatePendingPost = this.updatePendingPost.bind(this);
-
- // These functions are bad and work should be done to remove this system when the RHS dies
- this.storeSelectedPost = this.storeSelectedPost.bind(this);
- this.getSelectedPost = this.getSelectedPost.bind(this);
- this.emitSelectedPostChange = this.emitSelectedPostChange.bind(this);
- this.addSelectedPostChangeListener = this.addSelectedPostChangeListener.bind(this);
- this.removeSelectedPostChangeListener = this.removeSelectedPostChangeListener.bind(this);
- this.selectedPost = null;
-
- this.getEmptyDraft = this.getEmptyDraft.bind(this);
- this.storeCurrentDraft = this.storeCurrentDraft.bind(this);
- this.getCurrentDraft = this.getCurrentDraft.bind(this);
- this.storeDraft = this.storeDraft.bind(this);
- this.getDraft = this.getDraft.bind(this);
- this.storeCommentDraft = this.storeCommentDraft.bind(this);
- this.getCommentDraft = this.getCommentDraft.bind(this);
- this.clearDraftUploads = this.clearDraftUploads.bind(this);
- this.clearCommentDraftUploads = this.clearCommentDraftUploads.bind(this);
- this.getCurrentUsersLatestPost = this.getCurrentUsersLatestPost.bind(this);
- this.getCommentCount = this.getCommentCount.bind(this);
-
+ this.selectedPostId = null;
this.postsInfo = {};
this.currentFocusedPostId = null;
}
@@ -421,12 +356,59 @@ class PostStoreClass extends EventEmitter {
this.emitChange();
}
- storeSelectedPost(postList) {
- this.selectedPost = postList;
+ storeSelectedPostId(postId) {
+ this.selectedPostId = postId;
+ }
+
+ getSelectedPostId() {
+ return this.selectedPostId;
}
getSelectedPost() {
- return this.selectedPost;
+ if (this.selectedPostId == null) {
+ return null;
+ }
+
+ for (const k in this.postsInfo) {
+ if (this.postsInfo[k].postList.posts.hasOwnProperty(this.selectedPostId)) {
+ return this.postsInfo[k].postList.posts[this.selectedPostId];
+ }
+ }
+
+ return null;
+ }
+
+ getSelectedPostThread() {
+ if (this.selectedPostId == null) {
+ return null;
+ }
+
+ let posts;
+ let pendingPosts;
+ for (const k in this.postsInfo) {
+ if (this.postsInfo[k].postList.posts.hasOwnProperty(this.selectedPostId)) {
+ posts = this.postsInfo[k].postList.posts;
+ if (this.postsInfo[k].pendingPosts != null) {
+ pendingPosts = this.postsInfo[k].pendingPosts.posts;
+ }
+ }
+ }
+
+ const threadPosts = {};
+ const rootId = this.selectedPostId;
+ for (const k in posts) {
+ if (posts[k].root_id === rootId) {
+ threadPosts[k] = JSON.parse(JSON.stringify(posts[k]));
+ }
+ }
+
+ for (const k in pendingPosts) {
+ if (pendingPosts[k].root_id === rootId) {
+ threadPosts[k] = JSON.parse(JSON.stringify(pendingPosts[k]));
+ }
+ }
+
+ return threadPosts;
}
emitSelectedPostChange(fromSearch) {
@@ -565,7 +547,7 @@ PostStore.dispatchToken = AppDispatcher.register((payload) => {
PostStore.emitChange();
break;
case ActionTypes.RECEIVED_POST_SELECTED:
- PostStore.storeSelectedPost(action.post_list);
+ PostStore.storeSelectedPostId(action.postId);
PostStore.emitSelectedPostChange(action.from_search);
break;
default:
diff --git a/web/react/stores/user_store.jsx b/web/react/stores/user_store.jsx
index dd60e166f3..75a87d424d 100644
--- a/web/react/stores/user_store.jsx
+++ b/web/react/stores/user_store.jsx
@@ -17,50 +17,6 @@ const CHANGE_EVENT_STATUSES = 'change_statuses';
class UserStoreClass extends EventEmitter {
constructor() {
super();
-
- this.emitChange = this.emitChange.bind(this);
- this.addChangeListener = this.addChangeListener.bind(this);
- this.removeChangeListener = this.removeChangeListener.bind(this);
- this.emitSessionsChange = this.emitSessionsChange.bind(this);
- this.addSessionsChangeListener = this.addSessionsChangeListener.bind(this);
- this.removeSessionsChangeListener = this.removeSessionsChangeListener.bind(this);
- this.emitAuditsChange = this.emitAuditsChange.bind(this);
- this.addAuditsChangeListener = this.addAuditsChangeListener.bind(this);
- this.removeAuditsChangeListener = this.removeAuditsChangeListener.bind(this);
- this.emitTeamsChange = this.emitTeamsChange.bind(this);
- this.addTeamsChangeListener = this.addTeamsChangeListener.bind(this);
- this.removeTeamsChangeListener = this.removeTeamsChangeListener.bind(this);
- this.emitStatusesChange = this.emitStatusesChange.bind(this);
- this.addStatusesChangeListener = this.addStatusesChangeListener.bind(this);
- this.removeStatusesChangeListener = this.removeStatusesChangeListener.bind(this);
- this.getCurrentId = this.getCurrentId.bind(this);
- this.getCurrentUser = this.getCurrentUser.bind(this);
- this.setCurrentUser = this.setCurrentUser.bind(this);
- this.getLastEmail = this.getLastEmail.bind(this);
- this.setLastEmail = this.setLastEmail.bind(this);
- this.getLastUsername = this.getLastUsername.bind(this);
- this.setLastUsername = this.setLastUsername.bind(this);
- this.hasProfile = this.hasProfile.bind(this);
- this.getProfile = this.getProfile.bind(this);
- this.getProfileByUsername = this.getProfileByUsername.bind(this);
- this.getProfilesUsernameMap = this.getProfilesUsernameMap.bind(this);
- this.getProfiles = this.getProfiles.bind(this);
- this.getActiveOnlyProfiles = this.getActiveOnlyProfiles.bind(this);
- this.getActiveOnlyProfileList = this.getActiveOnlyProfileList.bind(this);
- this.saveProfile = this.saveProfile.bind(this);
- this.setSessions = this.setSessions.bind(this);
- this.getSessions = this.getSessions.bind(this);
- this.setAudits = this.setAudits.bind(this);
- this.getAudits = this.getAudits.bind(this);
- this.setTeams = this.setTeams.bind(this);
- this.getTeams = this.getTeams.bind(this);
- this.getCurrentMentionKeys = this.getCurrentMentionKeys.bind(this);
- this.setStatuses = this.setStatuses.bind(this);
- this.pSetStatuses = this.pSetStatuses.bind(this);
- this.setStatus = this.setStatus.bind(this);
- this.getStatuses = this.getStatuses.bind(this);
- this.getStatus = this.getStatus.bind(this);
-
this.profileCache = null;
}
@@ -277,7 +233,11 @@ class UserStoreClass extends EventEmitter {
}
getCurrentMentionKeys() {
- var user = this.getCurrentUser();
+ return this.getMentionKeys(this.getCurrentId());
+ }
+
+ getMentionKeys(id) {
+ var user = this.getProfile(id);
var keys = [];
@@ -330,7 +290,7 @@ class UserStoreClass extends EventEmitter {
}
var UserStore = new UserStoreClass();
-UserStore.setMaxListeners(0);
+UserStore.setMaxListeners(15);
UserStore.dispatchToken = AppDispatcher.register((payload) => {
var action = payload.action;
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index a4d2515e20..82828e34b0 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -1417,3 +1417,7 @@ export function languages() {
export function isPostEphemeral(post) {
return post.type === Constants.POST_TYPE_EPHEMERAL || post.state === Constants.POST_DELETED;
}
+
+export function getRootId(post) {
+ return post.root_id === '' ? post.id : post.root_id;
+}