summary refs log tree commit diff
path: root/webclient/room/room-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'webclient/room/room-controller.js')
-rw-r--r--webclient/room/room-controller.js67
1 files changed, 49 insertions, 18 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 364ca41510..35abeeca06 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-angular.module('RoomController', ['ngSanitize'])
-.controller('RoomController', ['$scope', '$http', '$timeout', '$routeParams', '$location', 'matrixService', 'eventStreamService', 'eventHandlerService',
-                               function($scope, $http, $timeout, $routeParams, $location, matrixService, eventStreamService, eventHandlerService) {
+angular.module('RoomController', ['ngSanitize', 'mUtilities'])
+.controller('RoomController', ['$scope', '$http', '$timeout', '$routeParams', '$location', 'matrixService', 'eventStreamService', 'eventHandlerService', 'mFileUpload', 'mUtilities',
+                               function($scope, $http, $timeout, $routeParams, $location, matrixService, eventStreamService, eventHandlerService, mFileUpload, mUtilities) {
    'use strict';
     var MESSAGES_PER_PAGINATION = 30;
 
@@ -30,7 +30,8 @@ angular.module('RoomController', ['ngSanitize'])
         earliest_token: "END", // stores how far back we've paginated.
         can_paginate: true, // this is toggled off when we run out of items
         paginating: false, // used to avoid concurrent pagination requests pulling in dup contents
-        stream_failure: undefined // the response when the stream fails
+        stream_failure: undefined, // the response when the stream fails
+        sending: false // true when a message is being sent. It helps to disable the UI when a process is running
     };
     $scope.members = {};
     $scope.autoCompleting = false;
@@ -88,7 +89,7 @@ angular.module('RoomController', ['ngSanitize'])
         
     var paginate = function(numItems) {
         // console.log("paginate " + numItems);
-        if ($scope.state.paginating) {
+        if ($scope.state.paginating || !$scope.room_id) {
             return;
         }
         else {
@@ -144,7 +145,7 @@ angular.module('RoomController', ['ngSanitize'])
                 console.log("Failed to paginateBackMessages: " + JSON.stringify(error));
                 $scope.state.paginating = false;
             }
-        )
+        );
     };
 
     var updateMemberList = function(chunk) {
@@ -232,7 +233,9 @@ angular.module('RoomController', ['ngSanitize'])
         if ($scope.textInput == "") {
             return;
         }
-                    
+
+        $scope.state.sending = true;
+
         // Send the text message
         var promise;
         // FIXME: handle other commands too
@@ -247,10 +250,12 @@ angular.module('RoomController', ['ngSanitize'])
             function() {
                 console.log("Sent message");
                 $scope.textInput = "";
+                $scope.state.sending = false;
             },
             function(error) {
                 $scope.feedback = "Failed to send: " + error.data.error;
-            });               
+                $scope.state.sending = false;
+            });
     };
 
     $scope.onInit = function() {
@@ -361,29 +366,55 @@ angular.module('RoomController', ['ngSanitize'])
             });
     };
 
-    $scope.sendImage = function(url) {
-        matrixService.sendImageMessage($scope.room_id, url).then(
+    $scope.sendImage = function(url, body) {
+        $scope.state.sending = true;
+
+        matrixService.sendImageMessage($scope.room_id, url, body).then(
             function() {
                 console.log("Image sent");
+                $scope.state.sending = false;
             },
             function(error) {
                 $scope.feedback = "Failed to send image: " + error.data.error;
+                $scope.state.sending = false;
             });
     };
     
     $scope.imageFileToSend;
     $scope.$watch("imageFileToSend", function(newValue, oldValue) {
         if ($scope.imageFileToSend) {
-            // First download the image to the Internet
-            console.log("Uploading image...");
-            mFileUpload.uploadFile($scope.imageFileToSend).then(
-                function(url) {
-                    // Then share the URL
-                    $scope.sendImage(url);
+
+            $scope.state.sending = true;
+
+            // First, get the image sise
+            mUtilities.getImageSize($scope.imageFileToSend).then(
+                function(size) {
+
+                    // Upload the image to the Internet
+                    console.log("Uploading image...");
+                    mFileUpload.uploadFile($scope.imageFileToSend).then(
+                        function(url) {
+                            // Build the image info data
+                            var imageInfo = {
+                                size: $scope.imageFileToSend.size,
+                                mimetype: $scope.imageFileToSend.type,
+                                w: size.width,
+                                h: size.height
+                            };
+
+                            // Then share the URL and the metadata
+                            $scope.sendImage(url, imageInfo);
+                        },
+                        function(error) {
+                            $scope.feedback = "Can't upload image";
+                            $scope.state.sending = false;
+                        }
+                    );
                 },
                 function(error) {
-                    $scope.feedback = "Can't upload image";
-                } 
+                    $scope.feedback = "Can't get selected image size";
+                    $scope.state.sending = false;
+                }
             );
         }
     });