From 9d9eaec14f4e4a8bc3bda4ef19c980bef2bb467b Mon Sep 17 00:00:00 2001
From: Reed Garmsen <rgarmsen2295@gmail.com>
Date: Wed, 6 Jan 2016 14:18:05 -0800
Subject: Removed ability to drag n' drop text; drag n' drop ui no longer
 appears when non-files are dragged

---
 web/react/components/file_upload.jsx | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

(limited to 'web/react/components/file_upload.jsx')

diff --git a/web/react/components/file_upload.jsx b/web/react/components/file_upload.jsx
index 9316ca9a5..8c7353e86 100644
--- a/web/react/components/file_upload.jsx
+++ b/web/react/components/file_upload.jsx
@@ -109,8 +109,6 @@ export default class FileUpload extends React.Component {
 
         if (typeof files !== 'string' && files.length) {
             this.uploadFiles(files);
-        } else {
-            this.props.onTextDrop(e.originalEvent.dataTransfer.getData('Text'));
         }
     }
 
@@ -120,11 +118,19 @@ export default class FileUpload extends React.Component {
 
         if (this.props.postType === 'post') {
             $('.row.main').dragster({
-                enter() {
-                    $('.center-file-overlay').removeClass('hidden');
+                enter(dragsterEvent, e) {
+                    var files = e.originalEvent.dataTransfer;
+
+                    if (utils.isFileTransfer(files)) {
+                        $('.center-file-overlay').removeClass('hidden');
+                    }
                 },
-                leave() {
-                    $('.center-file-overlay').addClass('hidden');
+                leave(dragsterEvent, e) {
+                    var files = e.originalEvent.dataTransfer;
+
+                    if (utils.isFileTransfer(files)) {
+                        $('.center-file-overlay').addClass('hidden');
+                    }
                 },
                 drop(dragsterEvent, e) {
                     $('.center-file-overlay').addClass('hidden');
@@ -133,11 +139,19 @@ export default class FileUpload extends React.Component {
             });
         } else if (this.props.postType === 'comment') {
             $('.post-right__container').dragster({
-                enter() {
-                    $('.right-file-overlay').removeClass('hidden');
+                enter(dragsterEvent, e) {
+                    var files = e.originalEvent.dataTransfer;
+
+                    if (utils.isFileTransfer(files)) {
+                        $('.right-file-overlay').removeClass('hidden');
+                    }
                 },
-                leave() {
-                    $('.right-file-overlay').addClass('hidden');
+                leave(dragsterEvent, e) {
+                    var files = e.originalEvent.dataTransfer;
+
+                    if (utils.isFileTransfer(files)) {
+                        $('.right-file-overlay').addClass('hidden');
+                    }
                 },
                 drop(dragsterEvent, e) {
                     $('.right-file-overlay').addClass('hidden');
-- 
cgit v1.2.3-1-g7c22


From c2f7aadfa7fad3e6058af5c3be6d40d48727d8ac Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Fri, 8 Jan 2016 09:25:44 -0500
Subject: Fixed FileUpload to properly unbind drag handlers when unmounted

---
 web/react/components/file_upload.jsx | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'web/react/components/file_upload.jsx')

diff --git a/web/react/components/file_upload.jsx b/web/react/components/file_upload.jsx
index 8c7353e86..a0c930ffb 100644
--- a/web/react/components/file_upload.jsx
+++ b/web/react/components/file_upload.jsx
@@ -243,6 +243,18 @@ export default class FileUpload extends React.Component {
         });
     }
 
+    componentWillUnmount() {
+        let target;
+        if (this.props.postType === 'post') {
+            target = $('.row.main');
+        } else {
+            target = $('.post-right__container');
+        }
+
+        // jquery-dragster doesn't provide a function to unregister itself so do it manually
+        target.off('dragenter dragleave dragover drop dragster:enter dragster:leave dragster:over dragster:drop');
+    }
+
     cancelUpload(clientId) {
         var requests = this.state.requests;
         var request = requests[clientId];
-- 
cgit v1.2.3-1-g7c22


From 5de20f013323d59bb81f043c47c177157c4f68d3 Mon Sep 17 00:00:00 2001
From: hmhealey <harrisonmhealey@gmail.com>
Date: Sat, 9 Jan 2016 12:42:34 -0500
Subject: Restricted file uploads on iOS Chrome and the iOS app to work around
 iOS bugs

---
 web/react/components/file_upload.jsx | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

(limited to 'web/react/components/file_upload.jsx')

diff --git a/web/react/components/file_upload.jsx b/web/react/components/file_upload.jsx
index a0c930ffb..6337afabc 100644
--- a/web/react/components/file_upload.jsx
+++ b/web/react/components/file_upload.jsx
@@ -4,7 +4,7 @@
 import * as client from '../utils/client.jsx';
 import Constants from '../utils/constants.jsx';
 import ChannelStore from '../stores/channel_store.jsx';
-import * as utils from '../utils/utils.jsx';
+import * as Utils from '../utils/utils.jsx';
 
 export default class FileUpload extends React.Component {
     constructor(props) {
@@ -52,7 +52,7 @@ export default class FileUpload extends React.Component {
             }
 
             // generate a unique id that can be used by other components to refer back to this upload
-            let clientId = utils.generateId();
+            let clientId = Utils.generateId();
 
             // prepare data to be uploaded
             var formData = new FormData();
@@ -121,14 +121,14 @@ export default class FileUpload extends React.Component {
                 enter(dragsterEvent, e) {
                     var files = e.originalEvent.dataTransfer;
 
-                    if (utils.isFileTransfer(files)) {
+                    if (Utils.isFileTransfer(files)) {
                         $('.center-file-overlay').removeClass('hidden');
                     }
                 },
                 leave(dragsterEvent, e) {
                     var files = e.originalEvent.dataTransfer;
 
-                    if (utils.isFileTransfer(files)) {
+                    if (Utils.isFileTransfer(files)) {
                         $('.center-file-overlay').addClass('hidden');
                     }
                 },
@@ -142,14 +142,14 @@ export default class FileUpload extends React.Component {
                 enter(dragsterEvent, e) {
                     var files = e.originalEvent.dataTransfer;
 
-                    if (utils.isFileTransfer(files)) {
+                    if (Utils.isFileTransfer(files)) {
                         $('.right-file-overlay').removeClass('hidden');
                     }
                 },
                 leave(dragsterEvent, e) {
                     var files = e.originalEvent.dataTransfer;
 
-                    if (utils.isFileTransfer(files)) {
+                    if (Utils.isFileTransfer(files)) {
                         $('.right-file-overlay').addClass('hidden');
                     }
                 },
@@ -205,7 +205,7 @@ export default class FileUpload extends React.Component {
                         var channelId = self.props.channelId || ChannelStore.getCurrentId();
 
                         // generate a unique id that can be used by other components to refer back to this file upload
-                        var clientId = utils.generateId();
+                        var clientId = Utils.generateId();
 
                         var formData = new FormData();
                         formData.append('channel_id', channelId);
@@ -268,6 +268,18 @@ export default class FileUpload extends React.Component {
     }
 
     render() {
+        let multiple = true;
+        if (Utils.isMobileApp()) {
+            // iOS WebViews don't upload videos properly in multiple mode
+            multiple = false;
+        }
+
+        let accept = '';
+        if (Utils.isIosChrome()) {
+            // iOS Chrome can't upload videos at all
+            accept = 'image/*';
+        }
+
         return (
             <span
                 ref='input'
@@ -280,7 +292,8 @@ export default class FileUpload extends React.Component {
                     ref='fileInput'
                     type='file'
                     onChange={this.handleChange}
-                    multiple='true'
+                    multiple={multiple}
+                    accept={accept}
                 />
             </span>
         );
-- 
cgit v1.2.3-1-g7c22


From 9110dd54a15f3d0fcf6f60936e01d816b667b93c Mon Sep 17 00:00:00 2001
From: JoramWilander <jwawilander@gmail.com>
Date: Mon, 4 Jan 2016 12:44:22 -0500
Subject: Added license validation and settings

---
 web/react/components/file_upload.jsx | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

(limited to 'web/react/components/file_upload.jsx')

diff --git a/web/react/components/file_upload.jsx b/web/react/components/file_upload.jsx
index 6337afabc..fef253c52 100644
--- a/web/react/components/file_upload.jsx
+++ b/web/react/components/file_upload.jsx
@@ -1,7 +1,7 @@
 // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
 // See License.txt for license information.
 
-import * as client from '../utils/client.jsx';
+import * as Client from '../utils/client.jsx';
 import Constants from '../utils/constants.jsx';
 import ChannelStore from '../stores/channel_store.jsx';
 import * as Utils from '../utils/utils.jsx';
@@ -26,7 +26,7 @@ export default class FileUpload extends React.Component {
         for (var j = 0; j < data.client_ids.length; j++) {
             delete requests[data.client_ids[j]];
         }
-        this.setState({requests: requests});
+        this.setState({requests});
     }
 
     fileUploadFail(clientId, err) {
@@ -52,7 +52,7 @@ export default class FileUpload extends React.Component {
             }
 
             // generate a unique id that can be used by other components to refer back to this upload
-            let clientId = Utils.generateId();
+            const clientId = Utils.generateId();
 
             // prepare data to be uploaded
             var formData = new FormData();
@@ -60,14 +60,14 @@ export default class FileUpload extends React.Component {
             formData.append('files', files[i], files[i].name);
             formData.append('client_ids', clientId);
 
-            var request = client.uploadFile(formData,
+            var request = Client.uploadFile(formData,
                 this.fileUploadSuccess.bind(this, channelId),
                 this.fileUploadFail.bind(this, clientId)
             );
 
             var requests = this.state.requests;
             requests[clientId] = request;
-            this.setState({requests: requests});
+            this.setState({requests});
 
             this.props.onUploadStart([clientId], channelId);
 
@@ -90,16 +90,7 @@ export default class FileUpload extends React.Component {
 
         this.uploadFiles(element.prop('files'));
 
-        // clear file input for all modern browsers
-        try {
-            element[0].value = '';
-            if (element.value) {
-                element[0].type = 'text';
-                element[0].type = 'file';
-            }
-        } catch (e) {
-            // Do nothing
-        }
+        Utils.clearFileInput(element[0]);
     }
 
     handleDrop(e) {
@@ -227,14 +218,14 @@ export default class FileUpload extends React.Component {
                         formData.append('files', file, name);
                         formData.append('client_ids', clientId);
 
-                        var request = client.uploadFile(formData,
+                        var request = Client.uploadFile(formData,
                             self.fileUploadSuccess.bind(self, channelId),
                             self.fileUploadFail.bind(self, clientId)
                         );
 
                         var requests = self.state.requests;
                         requests[clientId] = request;
-                        self.setState({requests: requests});
+                        self.setState({requests});
 
                         self.props.onUploadStart([clientId], channelId);
                     }
@@ -263,7 +254,7 @@ export default class FileUpload extends React.Component {
             request.abort();
 
             delete requests[clientId];
-            this.setState({requests: requests});
+            this.setState({requests});
         }
     }
 
-- 
cgit v1.2.3-1-g7c22

