summaryrefslogtreecommitdiffstats
path: root/webapp/components/post_view
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-09-30 11:06:30 -0400
committerGitHub <noreply@github.com>2016-09-30 11:06:30 -0400
commit8a0e649f989a824bb3bbfd1900a5b8e5383b47e1 (patch)
tree4b424929fe13ebec438d2f41a2729e37e5160720 /webapp/components/post_view
parenta2deeed597dea15d9b7ca237be71988469f58cdd (diff)
downloadchat-8a0e649f989a824bb3bbfd1900a5b8e5383b47e1.tar.gz
chat-8a0e649f989a824bb3bbfd1900a5b8e5383b47e1.tar.bz2
chat-8a0e649f989a824bb3bbfd1900a5b8e5383b47e1.zip
PLT-3105 Files table migration (#4068)
* Implemented initial changes for files table * Removed *_benchmark_test.go files * Re-implemented GetPublicFile and added support for old path * Localization for files table * Moved file system code into utils package * Finished server-side changes and added initial upgrade script * Added getPostFiles api * Re-add Extension and HasPreviewImage fields to FileInfo * Removed unused translation * Fixed merge conflicts left over after permissions changes * Forced FileInfo.extension to be lower case * Changed FileUploadResponse to contain the FileInfos instead of FileIds * Fixed permissions on getFile* calls * Fixed notifications for file uploads * Added initial version of client code for files changes * Permanently added FileIds field to Post object and removed Post.HasFiles * Updated PostStore.Update to be usable in more circumstances * Re-added Filenames field and switched file migration to be entirely lazy-loaded * Increased max listener count for FileStore * Removed unused fileInfoCache * Moved file system code back into api * Removed duplicate test case * Fixed unit test running on ports other than 8065 * Renamed HasPermissionToPostContext to HasPermissionToChannelByPostContext * Refactored handleImages to make it more easily understandable * Renamed getPostFiles to getFileInfosForPost * Re-added pre-FileIds posts to analytics * Changed files to be saved as their ids as opposed to id/filename.ext * Renamed FileInfo.UserId to FileInfo.CreatorId * Fixed detection of language in CodePreview * Fixed switching between threads in the RHS not loading new files * Add serverside protection against a rare bug where the client sends the same file twice for a single post * Refactored the important parts of uploadFile api call into a function that can be called without a web context
Diffstat (limited to 'webapp/components/post_view')
-rw-r--r--webapp/components/post_view/components/commented_on_files_message_container.jsx88
-rw-r--r--webapp/components/post_view/components/post_body.jsx31
2 files changed, 102 insertions, 17 deletions
diff --git a/webapp/components/post_view/components/commented_on_files_message_container.jsx b/webapp/components/post_view/components/commented_on_files_message_container.jsx
new file mode 100644
index 000000000..5325a7644
--- /dev/null
+++ b/webapp/components/post_view/components/commented_on_files_message_container.jsx
@@ -0,0 +1,88 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import React from 'react';
+
+import * as AsyncClient from 'utils/async_client.jsx';
+import FileStore from 'stores/file_store.jsx';
+import * as Utils from 'utils/utils.jsx';
+
+export default class CommentedOnFilesMessageContainer extends React.Component {
+ static propTypes = {
+ parentPostChannelId: React.PropTypes.string.isRequired,
+ parentPostId: React.PropTypes.string.isRequired
+ }
+
+ constructor(props) {
+ super(props);
+
+ this.handleFileChange = this.handleFileChange.bind(this);
+
+ this.state = {
+ fileInfos: FileStore.getInfosForPost(this.props.parentPostId)
+ };
+ }
+
+ componentDidMount() {
+ FileStore.addChangeListener(this.handleFileChange);
+
+ if (!FileStore.hasInfosForPost(this.props.parentPostId)) {
+ AsyncClient.getFileInfosForPost(this.props.parentPostChannelId, this.props.parentPostId);
+ }
+ }
+
+ componentWillReceiveProps(nextProps) {
+ if (nextProps.parentPostId !== this.props.parentPostId) {
+ this.setState({
+ fileInfos: FileStore.getInfosForPost(this.props.parentPostId)
+ });
+
+ if (!FileStore.hasInfosForPost(this.props.parentPostId)) {
+ AsyncClient.getFileInfosForPost(this.props.parentPostChannelId, this.props.parentPostId);
+ }
+ }
+ }
+
+ shouldComponentUpdate(nextProps, nextState) {
+ if (nextProps.parentPostId !== this.props.parentPostId) {
+ return true;
+ }
+
+ if (nextProps.parentPostChannelId !== this.props.parentPostChannelId) {
+ return true;
+ }
+
+ // fileInfos are treated as immutable by the FileStore
+ if (nextState.fileInfos !== this.state.fileInfos) {
+ return true;
+ }
+
+ return false;
+ }
+
+ handleFileChange() {
+ this.setState({
+ fileInfos: FileStore.getInfosForPost(this.props.parentPostId)
+ });
+ }
+
+ componentWillUnmount() {
+ FileStore.removeChangeListener(this.handleFileChange);
+ }
+
+ render() {
+ let message = ' ';
+
+ if (this.state.fileInfos && this.state.fileInfos.length > 0) {
+ message = this.state.fileInfos[0].name;
+
+ if (this.state.fileInfos.length === 2) {
+ message += Utils.localizeMessage('post_body.plusOne', ' plus 1 other file');
+ } else if (this.state.fileInfos.length > 2) {
+ message += Utils.localizeMessage('post_body.plusMore', ' plus {count} other files').replace('{count}', (this.state.fileInfos.length - 1).toString());
+ }
+ }
+
+ return <span>{message}</span>;
+ }
+}
diff --git a/webapp/components/post_view/components/post_body.jsx b/webapp/components/post_view/components/post_body.jsx
index 5c02e9c40..c23939c1f 100644
--- a/webapp/components/post_view/components/post_body.jsx
+++ b/webapp/components/post_view/components/post_body.jsx
@@ -1,11 +1,12 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import FileAttachmentList from 'components/file_attachment_list.jsx';
import UserStore from 'stores/user_store.jsx';
import * as Utils from 'utils/utils.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import Constants from 'utils/constants.jsx';
+import CommentedOnFilesMessageContainer from './commented_on_files_message_container.jsx';
+import FileAttachmentListContainer from 'components/file_attachment_list_container.jsx';
import PostBodyAdditionalContent from './post_body_additional_content.jsx';
import PostMessageContainer from './post_message_container.jsx';
import PendingPostOptions from './pending_post_options.jsx';
@@ -22,6 +23,7 @@ export default class PostBody extends React.Component {
this.removePost = this.removePost.bind(this);
}
+
shouldComponentUpdate(nextProps) {
if (nextProps.isCommentMention !== this.props.isCommentMention) {
return true;
@@ -56,7 +58,6 @@ export default class PostBody extends React.Component {
render() {
const post = this.props.post;
- const filenames = this.props.post.filenames;
const parentPost = this.props.parentPost;
let comment = '';
@@ -94,14 +95,13 @@ export default class PostBody extends React.Component {
let message = '';
if (parentPost.message) {
message = Utils.replaceHtmlEntities(parentPost.message);
- } else if (parentPost.filenames.length) {
- message = parentPost.filenames[0].split('/').pop();
-
- if (parentPost.filenames.length === 2) {
- message += Utils.localizeMessage('post_body.plusOne', ' plus 1 other file');
- } else if (parentPost.filenames.length > 2) {
- message += Utils.localizeMessage('post_body.plusMore', ' plus {count} other files').replace('{count}', (parentPost.filenames.length - 1).toString());
- }
+ } else if (parentPost.file_ids && parentPost.file_ids.length > 0) {
+ message = (
+ <CommentedOnFilesMessageContainer
+ parentPostChannelId={parentPost.channel_id}
+ parentPostId={parentPost.id}
+ />
+ );
}
comment = (
@@ -140,14 +140,11 @@ export default class PostBody extends React.Component {
);
}
- let fileAttachmentHolder = '';
- if (filenames && filenames.length > 0) {
+ let fileAttachmentHolder = null;
+ if ((post.file_ids && post.file_ids.length > 0) || (post.filenames && post.filenames.length > 0)) {
fileAttachmentHolder = (
- <FileAttachmentList
-
- filenames={filenames}
- channelId={post.channel_id}
- userId={post.user_id}
+ <FileAttachmentListContainer
+ post={post}
compactDisplay={this.props.compactDisplay}
/>
);