send messages to users from the home page (SYWEB-19)

This commit is contained in:
Matthew Hodgson 2014-09-23 13:36:58 +01:00
parent 997a016122
commit 4847045259
3 changed files with 42 additions and 4 deletions

View File

@ -43,6 +43,10 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
avatarUrl: "" avatarUrl: ""
}; };
$scope.newChat = {
user: ""
};
var refresh = function() { var refresh = function() {
matrixService.publicRooms().then( matrixService.publicRooms().then(
@ -113,6 +117,32 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
); );
}; };
// FIXME: factor this out between user-controller and home-controller etc.
$scope.messageUser = function() {
// FIXME: create a new room every time, for now
matrixService.create(null, 'private').then(
function(response) {
// This room has been created. Refresh the rooms list
var room_id = response.data.room_id;
console.log("Created room with id: "+ room_id);
matrixService.invite(room_id, $scope.newChat.user).then(
function() {
$scope.feedback = "Invite sent successfully";
$scope.$parent.goToPage("/room/" + room_id);
},
function(reason) {
$scope.feedback = "Failure: " + JSON.stringify(reason);
});
},
function(error) {
$scope.feedback = "Failure: " + JSON.stringify(error.data);
});
};
$scope.onInit = function() { $scope.onInit = function() {
// Load profile data // Load profile data
// Display name // Display name

View File

@ -52,17 +52,24 @@
<div> <div>
<form> <form>
<input size="40" ng-model="newRoom.room_alias" ng-enter="createNewRoom(newRoom.room_alias, newRoom.private)" placeholder="(e.g. foo_channel)"/> <input size="40" ng-model="newRoom.room_alias" ng-enter="createNewRoom(newRoom.room_alias, newRoom.private)" placeholder="(e.g. foo)"/>
<input type="checkbox" ng-model="newRoom.private">private <input type="checkbox" ng-model="newRoom.private">private
<button ng-disabled="!newRoom.room_alias" ng-click="createNewRoom(newRoom.room_alias, newRoom.private)">Create room</button> <button ng-disabled="!newRoom.room_alias" ng-click="createNewRoom(newRoom.room_alias, newRoom.private)">Create room</button>
</form> </form>
</div> </div>
<div> <div>
<form> <form>
<input size="40" ng-model="joinAlias.room_alias" ng-enter="joinAlias(joinAlias.room_alias)" placeholder="(e.g. #foo_channel:example.org)"/> <input size="40" ng-model="joinAlias.room_alias" ng-enter="joinAlias(joinAlias.room_alias)" placeholder="(e.g. #foo:example.org)"/>
<button ng-disabled="!joinAlias.room_alias" ng-click="joinAlias(joinAlias.room_alias)">Join room</button> <button ng-disabled="!joinAlias.room_alias" ng-click="joinAlias(joinAlias.room_alias)">Join room</button>
</form> </form>
</div> </div>
<div>
<form>
<input size="40" ng-model="newChat.user" ng-enter="messageUser()" placeholder="e.g. @user:domain.com"/>
<button ng-disabled="!newChat.user" ng-click="messageUser()">Message user</button>
</form>
</div>
<br/> <br/>
{{ feedback }} {{ feedback }}

View File

@ -39,6 +39,7 @@ angular.module('UserController', ['matrixService'])
} }
); );
// FIXME: factor this out between user-controller and home-controller etc.
$scope.messageUser = function() { $scope.messageUser = function() {
// FIXME: create a new room every time, for now // FIXME: create a new room every time, for now