Created
April 17, 2015 12:26
-
-
Save albulescu/760334d1cf6211aad8ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----- html | |
<div ng-class="ChatController"> | |
<chat> | |
<div chat-messages class="messages"> | |
<div chat-message class="message-item"> | |
</div> | |
</div> | |
<div class="footer"> | |
<input chat-input/> | |
<button chat-send-button>Send</button> | |
<button chat-attachment-button>File</button> | |
</div> | |
</chat> | |
</div> | |
------ configurations | |
.config(function($chatProvider){ | |
//enable attachments | |
$chatProvider.config('attachments', true); | |
}) | |
------ proxy to communicate with backend | |
.service('ChatProxy', function($q){ | |
return { | |
connect: function() { | |
var deferer = $q.defer(); | |
/* | |
get converstions | |
if no conversation start one | |
then defere.resolve() | |
*/ | |
return deferer.promise; | |
}, | |
send: function(message) { | |
var deferer = $q.defer(); | |
//concrete send implementation | |
return deferer.promise; | |
}, | |
file: function() { | |
var deferer = $q.defer(); | |
//concrete send file and deferer.resolve or deferer.reject('fail to send') | |
return deferer.promise; | |
} | |
} | |
}) | |
------ Chat container controller | |
.controller('ChatController', function($scope, Auth, ChatProxy){ | |
$scope.$on('chat.ready', function(chat){ | |
chat.proxy(ChatProxy); | |
if( Auth.isLoggedIn() ) { | |
//sync mode | |
chat.connect(Auth.loggedUser()); | |
} | |
else { | |
Auth.on('login', function(user){ | |
chat.connect(user); | |
}); | |
} | |
}); | |
$scope.$on('chat.message', function(){ | |
//make custom other actions | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment