From b78615962784bcbb9bfb4cab161bd3439996f0c9 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sat, 7 Apr 2012 00:40:00 -0400 Subject: load the presence --- alias-angular/app/js/controllers.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'alias-angular/app/js/controllers.js') 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']; + -- cgit v1.2.3-70-g09d2