aboutsummaryrefslogtreecommitdiffstats
path: root/alias-angular/app/js/controllers.js
diff options
context:
space:
mode:
Diffstat (limited to 'alias-angular/app/js/controllers.js')
-rw-r--r--alias-angular/app/js/controllers.js36
1 files changed, 32 insertions, 4 deletions
diff --git a/alias-angular/app/js/controllers.js b/alias-angular/app/js/controllers.js
index 97b44ee..2040e3a 100644
--- a/alias-angular/app/js/controllers.js
+++ b/alias-angular/app/js/controllers.js
@@ -24,17 +24,44 @@ function ConnectCtl($scope, StropheSrv, $log, $rootScope) {
ConnectCtl.$inject = ['$scope', 'StropheSrv', '$log', '$rootScope'];
function RosterCtl($scope, StropheSrv, $log) {
- $scope.contacts = [];
+ $scope.contacts = {};
function onRoster(iq) {
+ $log.log('im here');
var elems = iq.getElementsByTagName('query');
var query = elems[0];
Strophe.forEachChild(query, 'item', function(item){
var jid = item.getAttribute('jid');
- var name = item.getAttribute('name') || jid;
- $scope.contacts.push(name);
+ var name = item.getAttribute('name');
+ $scope.contacts[jid]={name: name};
});
};
- $scope.$on('connected', function() {$scope.getRoster();});
+ function onPresence(presence) {
+ var who = $(presence).attr('from');
+ var jid = Strophe.getBareJidFromJid(who);
+ $log.log(jid);
+ var type = $(presence).attr('type');
+ if (type !== 'error') {
+ if (type === 'unavailable') {
+ $scope.contacts[jid]['status']='offline';
+ }
+ else {
+ var show = $(presence).find('show').text();
+ if (show === '') {
+ $scope.contacts[jid]['status'] = 'online';
+ }else{
+ $scope.contacts[jid]['status'] = 'away';
+ }
+ }
+ delete $scope.contacts[jid];
+ }
+ return true;
+ }
+ $scope.$on('connected', function() {
+ StropheSrv.addHandler(onPresence, 'presence');
+ $log.log('test');
+ $scope.getRoster();
+ StropheSrv.send($pres());
+ });
$scope.getRoster = function () {
var query = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER});
StropheSrv.sendIQ(query, onRoster);
@@ -42,3 +69,4 @@ function RosterCtl($scope, StropheSrv, $log) {
}
RosterCtl.$inject = ['$scope','StropheSrv','$log'];
+