Made IRC style command easier to handle specifically for possible arguments

paul/schema_breaking_changes
Emmanuel ROHEE 2014-09-03 11:07:44 +02:00
parent 8166ebd91a
commit 65c7f78e9f
1 changed files with 22 additions and 10 deletions

View File

@ -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) {
// 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
promise = matrixService.setDisplayName($scope.textInput.substr(6));
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;
});
};