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

@ -42,6 +42,10 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
displayName: "",
avatarUrl: ""
};
$scope.newChat = {
user: ""
};
var refresh = function() {
@ -112,6 +116,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() {
// Load profile data

View file

@ -17,7 +17,7 @@
<div>{{ config.user_id }}</div>
</div>
</div>
<h3>Recent conversations</h3>
<div ng-include="'recents/recents.html'"></div>
<br/>
@ -52,17 +52,24 @@
<div>
<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
<button ng-disabled="!newRoom.room_alias" ng-click="createNewRoom(newRoom.room_alias, newRoom.private)">Create room</button>
</form>
</div>
<div>
<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>
</form>
</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/>
{{ feedback }}

View file

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