Browse Source

- broke roster..no onPresence event anymore

pull/16/head
Christine Ho 11 years ago
parent
commit
2a86985da5
  1. 21
      app/widgets/Roster/Roster.php
  2. 61
      app/widgets/Roster/roster.js
  3. 1
      app/widgets/Roster/roster.tpl

21
app/widgets/Roster/Roster.php

@ -30,10 +30,10 @@ class Roster extends WidgetBase
$this->addjs('angular.js');
$this->addjs('roster.js');
$this->registerEvent('roster_getlist_handle', 'onRoster');
$this->registerEvent('roster_additem_handle', 'onRoster');
$this->registerEvent('roster_removeitem_handle', 'onRoster');
$this->registerEvent('roster_updateitem_handle', 'onRoster');
$this->registerEvent('presence', 'onPresence');
$this->registerEvent('roster_additem_handle', 'onUpdate');
$this->registerEvent('roster_removeitem_handle', 'onDelete');
$this->registerEvent('roster_updateitem_handle', 'onUpdate');
$this->registerEvent('presence', 'onUpdate');
}
function display()
@ -41,7 +41,15 @@ class Roster extends WidgetBase
}
function onPresence($packet)
function onDelete($packet)
{
$jid = $packet->content;
if($jid != null){
RPC::call('deleteContact', $jid);
}
}
function onUpdate($packet)
{
$contacts = $packet->content;
if($contacts != null){
@ -53,8 +61,9 @@ class Roster extends WidgetBase
$this->prepareContact($ac, $c, $this->getCaps());
$c = $ac;
}
RPC::call('updatePresence', json_encode($contacts));
RPC::call('updateContact', json_encode($contacts));
}
else movim_log("NULL !");
}
function onRoster()

61
app/widgets/Roster/roster.js

@ -13,7 +13,7 @@
app.controller("RosterController", function($scope){
$scope.contacts = /*localStorage.getObject('rosterContacts') ||*/ [];
$scope.groups = /*localStorage.getObject('rosterGroups') ||*/ [];
//$scope.list = [];
$scope.list = [];
/* Dictionaries */
$scope.lookupgroups = {};
@ -21,6 +21,7 @@
$scope.lookupressource = {};
$scope.initContacts = function(list){
console.log("initContacts");
//$scope.contacts = [];
//$scope.list = list;
for(i=0; i<list.length; i++){
@ -29,7 +30,7 @@
l = $scope.contacts.length;
$scope.contacts.push({
'agroup': list[i].groupname,
'agroupitems': []
'agroupitems': [],
});
$scope.lookupgroups[list[i].groupname] = $scope.contacts[l];
}
@ -39,7 +40,8 @@
$scope.lookupgroups[list[i].groupname].agroupitems.push({
'ajid': list[i].jid,
'aval': list[i].value,
'ajiditems': []
'ajiditems': [],
'tombstone': false,
});
$scope.lookupjid[list[i].jid] = $scope.lookupgroups[list[i].groupname].agroupitems[l];
}
@ -61,7 +63,6 @@
/* Sort groups alphabetically */
$scope.contacts.sort(function(a, b){return a.agroup.localeCompare(b.agroup);});
//localStorage.setObject('rosterContacts', $scope.contacts);
$scope.$apply();
};
@ -75,15 +76,23 @@
else list[i] = localStorage.getItem("rosterGroup_"+i);
}
$scope.groups = list;
//localStorage.setObject('rosterGroups', $scope.groups);
$scope.$apply();
};
$scope.deleteContact = function(jid){
$scope.lookupjid[jid].tombstone = true;
$scope.$apply();
};
$scope.updateContact = function(list){
console.log("updateContact");
$scope.list.push(list);
/* New group */
if(!(list[0].groupname in $scope.lookupgroups)) {
l = $scope.contacts.length;
/* A jid has been moved to a new group */
/* A known jid has been moved to a new group */
if (list[0].jid in $scope.lookupjid){
/* Create the group and put the jid in it */
$scope.contacts.push({
@ -91,33 +100,56 @@
'agroupitems': [{
'ajid': list[0].jid,
'aval': list[0].value,
'ajiditems': list
'ajiditems': list,
'tombstone': false,
}]
});
/* Remove jid of old location */
$scope.lookupgroups[$scope.lookupjid[list[0].jid].ajiditems[0].groupname]
/* Kill jid from old location */
$scope.lookupjid[list[0].jid].tombstone = true;
/* Update dictionaries */
$scope.lookupgroups[list[0].groupname] = $scope.contacts[l];
$scope.lookupjid[list[0].jid] = $scope.lookupgroups[list[0].groupname].agroupitems[0];
}
/* An unknown jid in an unknown group */
else {
$scope.contacts.push({
'agroup': list[0].groupname,
'agroupitems': []
'agroupitems': [],
});
$scope.lookupgroups[list[0].groupname] = $scope.contacts[l];
}
}
/* New jid */
if(!(list[0].jid in $scope.lookupjid)){
l = $scope.lookupgroups[list[0].groupname].agroupitems.length;
$scope.lookupgroups[list[0].groupname].agroupitems.push({
'ajid': list[0].jid,
'aval': list[0].value,
'ajiditems': []
'ajiditems': [],
'tombstone': false,
});
$scope.lookupjid[list[0].jid] = $scope.lookupgroups[list[0].groupname].agroupitems[l];
}
/* Known jid in another existing group */
else if(!($scope.lookupjid[list[0].jid].ajiditem[0].groupname == list[i].groupname)){
/* Kill jid from old location */
$scope.lookupjid[list[0].jid].tombstone = true;
/* Add to new group */
l = $scope.lookupgroups[list[0].groupname].agroupitems.length;
$scope.lookupgroups[list[0].groupname].agroupitems.push({
'ajid': list[0].jid,
'aval': list[0].value,
'ajiditems': list,
'tombstone': false,
});
/* Update JID dictionary */
$scope.lookupjid[list[0].jid] = $scope.lookupgroups[list[0].groupname].agroupitems[l];
}
/* Replace the ajiditems by the new list of ressource */
$scope.lookupjid[list[0].jid].ajiditems = list;
@ -224,10 +256,15 @@ function initGroups(tab){
angular.element(roster).scope().initGroups(JSON.parse(tab));
}
function updatePresence(tab){
function updateContact(tab){
console.log("updateContact out");
angular.element(roster).scope().updateContact(JSON.parse(tab));
}
function deleteContact(jid){
angular.element(roster).scope().deleteContact(jid);
}
function locationOf(element, array, comparer, start, end) {
if (array.length === 0)
return -1;

1
app/widgets/Roster/roster.tpl

@ -11,6 +11,7 @@
<div ng-show="contacts.length" ng-repeat="group in contacts" id="group{{group.agroup}}" ng-class="{groupshown: rosterCtrl.groupIsShown(group.agroup) == 'true'}">
<h1 ng-click="rosterCtrl.showHideGroup(group.agroup)">{{group.agroup}}</h1>
<!--ng-hide="myjid.tombstone == 'true'" -->
<li ng-repeat="myjid in group.agroupitems" id="{{myjid.ajid}}" class="{{myjid.ajiditems[0].rosterview.presencetxt}}" ng-attr-title="{{rosterCtrl.getContactTitle(myjid.ajiditems[0])}}">
<!-- Rostersearch look this way for an angularJS solution http://www.bennadel.com/blog/2487-filter-vs-nghide-with-ngrepeat-in-angularjs.htm -->
<ul class="contact">

Loading…
Cancel
Save