diff options
author | Emmanuel ROHEE <erohee@amdocs.com> | 2014-09-03 11:07:44 +0200 |
---|---|---|
committer | Emmanuel ROHEE <erohee@amdocs.com> | 2014-09-03 11:07:53 +0200 |
commit | 65c7f78e9f864aff4d273f59f7f9bf43b81db9bd (patch) | |
tree | 62d8ffe18cc3db48d6bd908b4c4e604a8671bb7a /webclient | |
parent | cmdclient: Now works correctly with user localpart login. Default to 8008 not... (diff) | |
download | synapse-65c7f78e9f864aff4d273f59f7f9bf43b81db9bd.tar.xz |
Made IRC style command easier to handle specifically for possible arguments
Diffstat (limited to 'webclient')
-rw-r--r-- | webclient/room/room-controller.js | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 72c290ad73..da2a9b0e77 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -250,28 +250,40 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) $scope.state.sending = true; - // Send the text message var promise; - // FIXME: handle other commands too - if ($scope.textInput.indexOf("/me") === 0) { - promise = matrixService.sendEmoteMessage($scope.room_id, $scope.textInput.substr(4)); - } - else if ($scope.textInput.indexOf("/nick ") === 0) { - // Change user display name - promise = matrixService.setDisplayName($scope.textInput.substr(6)); + + // Check for IRC style commands first + if ($scope.textInput.indexOf("/") === 0) { + var args = $scope.textInput.split(' '); + var cmd = args[0]; + + switch (cmd) { + case "/me": + var emoteMsg = args.slice(1).join(' '); + promise = matrixService.sendEmoteMessage($scope.room_id, emoteMsg); + break; + + case "/nick": + // Change user display name + if (2 === args.length) { + promise = matrixService.setDisplayName(args[1]); + } + break; + } } else { + // Send the text message promise = matrixService.sendTextMessage($scope.room_id, $scope.textInput); } promise.then( function() { - console.log("Sent message"); + console.log("Request successfully sent"); $scope.textInput = ""; $scope.state.sending = false; }, function(error) { - $scope.feedback = "Failed to send: " + error.data.error; + $scope.feedback = "Request failed: " + error.data.error; $scope.state.sending = false; }); }; |