diff --git a/webclient/components/fileInput/file-input-directive.js b/webclient/components/fileInput/file-input-directive.js
index 9b73f877e9..c5e4ae07a8 100644
--- a/webclient/components/fileInput/file-input-directive.js
+++ b/webclient/components/fileInput/file-input-directive.js
@@ -29,7 +29,7 @@ angular.module('mFileInput', [])
scope: {
selectedFile: '=mFileInput'
},
-
+
link: function(scope, element, attrs, ctrl) {
element.bind("click", function() {
element.find("input")[0].click();
@@ -38,6 +38,9 @@ angular.module('mFileInput', [])
scope.$apply();
});
});
+
+ // Change the mouse icon on mouseover on this element
+ element.css("cursor", "pointer");
}
};
});
\ No newline at end of file
diff --git a/webclient/components/fileUpload/file-upload-service.js b/webclient/components/fileUpload/file-upload-service.js
index 5729d5da48..d620e6a4d0 100644
--- a/webclient/components/fileUpload/file-upload-service.js
+++ b/webclient/components/fileUpload/file-upload-service.js
@@ -16,11 +16,12 @@
'use strict';
+// TODO determine if this is really required as a separate service to matrixService.
/*
* Upload an HTML5 file to a server
*/
angular.module('mFileUpload', [])
-.service('mFileUpload', ['$http', '$q', function ($http, $q) {
+.service('mFileUpload', ['matrixService', '$q', function (matrixService, $q) {
/*
* Upload an HTML5 file to a server and returned a promise
@@ -28,20 +29,19 @@ angular.module('mFileUpload', [])
*/
this.uploadFile = function(file) {
var deferred = $q.defer();
-
- // @TODO: This service runs with the do_POST hacky implementation of /synapse/demos/webserver.py.
- // This is temporary until we have a true file upload service
- console.log("Uploading " + file.name + "...");
- $http.post(file.name, file)
- .success(function(data, status, headers, config) {
- deferred.resolve(location.origin + data.url);
- console.log(" -> Successfully uploaded! Available at " + location.origin + data.url);
- }).
- error(function(data, status, headers, config) {
- console.log(" -> Failed to upload" + file.name);
- deferred.reject();
- });
+ console.log("Uploading " + file.name + "... to /matrix/content");
+ matrixService.uploadContent(file).then(
+ function(response) {
+ var content_url = location.origin + "/matrix/content/" + response.data.content_token;
+ console.log(" -> Successfully uploaded! Available at " + content_url);
+ deferred.resolve(content_url);
+ },
+ function(error) {
+ console.log(" -> Failed to upload " + file.name);
+ deferred.reject(error);
+ }
+ );
return deferred.promise;
};
-}]);
\ No newline at end of file
+}]);
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index 3cd0aa674b..828396c866 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -54,13 +54,14 @@ angular.module('matrixService', [])
params.access_token = config.access_token;
+ if (path.indexOf(prefixPath) !== 0) {
+ path = prefixPath + path;
+ }
+
return doBaseRequest(config.homeserver, method, path, params, data, undefined);
};
var doBaseRequest = function(baseUrl, method, path, params, data, headers) {
- if (path.indexOf(prefixPath) !== 0) {
- path = prefixPath + path;
- }
return $http({
method: method,
url: baseUrl + path,
@@ -165,6 +166,16 @@ angular.module('matrixService', [])
return doRequest("DELETE", path, undefined, undefined);
},
+ // Retrieves the room ID corresponding to a room alias
+ resolveRoomAlias:function(room_alias) {
+ var path = "/matrix/client/api/v1/ds/room/$room_alias";
+ room_alias = encodeURIComponent(room_alias);
+
+ path = path.replace("$room_alias", room_alias);
+
+ return doRequest("GET", path, undefined, {});
+ },
+
sendMessage: function(room_id, msg_id, content) {
// The REST path spec
var path = "/rooms/$room_id/messages/$from/$msg_id";
@@ -309,6 +320,17 @@ angular.module('matrixService', [])
return doBaseRequest(config.identityServer, "POST", path, {}, data, headers);
},
+ uploadContent: function(file) {
+ var path = "/matrix/content";
+ var headers = {
+ "Content-Type": undefined // undefined means angular will figure it out
+ };
+ var params = {
+ access_token: config.access_token
+ };
+ return doBaseRequest(config.homeserver, "POST", path, params, file, headers);
+ },
+
// start listening on /events
getEventStream: function(from, timeout) {
var path = "/events";
|