Skip to content

Commit

Permalink
Added fake replies
Browse files Browse the repository at this point in the history
  • Loading branch information
yeusiukou committed Feb 16, 2016
1 parent 74df047 commit e86c50e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/app/components/chat/chat.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
return directive;

/** @ngInject */
function ChatController($rootScope, $scope) {
function ChatController($rootScope, $scope, $timeout) {
var chat = this;
chat.messages = [];
chat.sendMessage = sendMessage;

var user = $scope.main.user;
var interlocutor;

$rootScope.$on("OPEN_CHAT", function(event, user){
chat.messages = [];
getMessages(user);
interlocutor = user;
getMessages();
});

function sendMessage(){
Expand All @@ -38,19 +40,28 @@
avatar: user.avatar
});
chat.myMessage = "";

// fake reply
$timeout(function(){
pushFakeMessage();
}, 1000);
}

function getMessages(user){
function getMessages(){
var amount = Math.random()*9;
for(var i=0; i<amount; i++)
chat.messages.push({
text: faker.lorem.paragraph(),
name: user.name,
avatar: user.image
});
pushFakeMessage();
scrollDown();
}

function pushFakeMessage(){
chat.messages.push( {
text: faker.lorem.paragraph(),
name: interlocutor.name,
avatar: interlocutor.image
} );
}

}
function scrollOnNew(scope, element){
scope.$watchCollection('chat.messages', function() {
Expand Down

0 comments on commit e86c50e

Please sign in to comment.