From 3402bd98368d83cb2b4d72aa704506985ebc20e9 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 25 Jun 2015 20:36:38 +0000 Subject: [PATCH] Use angularJS to manage contact list update properly. This also fix a recent upstream bug which doesn't re-insert contact into contactlist when new messages arrived --- js/public/app.js | 43 ++++++++++++++++++++----------------------- templates/main.php | 2 +- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/js/public/app.js b/js/public/app.js index 17c3ace..05ad8fc 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -117,15 +117,11 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' } if (!inArray(peerLabel, bufferedContacts)) { - $("li[peer-label='" + peerLabel + "']").remove(); - peerListBuf = '
  • ' + peerLabel + ' (' + val + ')
  • '; + contactObj = {'label': peerLabel, 'nav': idxVal2, 'avatar': jsondata['photos'][peerLabel], 'unread': val}; + + $scope.removeContact(contactObj); + $scope.addContactToFront(contactObj); - g_ulContactList.prepend(peerListBuf); bufferedContacts.push(peerLabel); // Re-set conversation because we reload the element @@ -134,20 +130,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' } g_unreadCountAllConv += parseInt(val); - - // Now bind the events when we click on the phone number - $("a[mailbox-navigation='" + idxVal + "']").on('click', function (event) { - var phoneNumber = $(this).attr('mailbox-navigation'); - OC.Util.History.pushState('phonenumber=' + phoneNumber); - - // phoneNumber must exist - if (phoneNumber != null) { - $scope.fetchConversation(phoneNumber); - g_unreadCountAllConv += val; - changeSelectedConversation($(this)); - } - event.preventDefault(); - }); } }); @@ -197,6 +179,21 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' $scope.contacts.push(ct); }); }; + $scope.addContactToFront = function (ct) { + $scope.$apply(function () { + $scope.contacts.splice(0, 0, ct); + }); + }; + $scope.removeContact = function (ct) { + var len = $scope.contacts.length; + for (var i=0; i < len; i++) { + var curCt = $scope.contacts[i]; + if (curCt['nav'] == ct['nav']) { + $scope.contacts.splice(i, 1); + return; + } + } + } $scope.fetchInitialSettings = function () { $.getJSON(OC.generateUrl('/apps/ocsms/get/country'), function(jsondata, status) { @@ -223,7 +220,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' peerLabel = fn; } if (!inArray(peerLabel, bufferedContacts)) { - $scope.addContact({'label': peerLabel, 'nav': idxVal2, 'avatar': jsondata['photos'][peerLabel]}); + $scope.addContact({'label': peerLabel, 'nav': idxVal2, 'avatar': jsondata['photos'][peerLabel], 'unread' : 0}); bufferedContacts.push(peerLabel); } }); diff --git a/templates/main.php b/templates/main.php index 0ecbcdb..d9a3138 100644 --- a/templates/main.php +++ b/templates/main.php @@ -11,7 +11,7 @@ use \OCA\OcSms\Lib\CountryCodes;