1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 16:06:15 +00:00

Merge duplicate phone numbers into a unique list

This commit is contained in:
Loic Blot 2015-06-08 19:09:25 +00:00
parent a620277d86
commit 8680ce6d38

View File

@ -22,6 +22,17 @@ var originalTitle = document.title;
var app = angular.module('OcSms', []); var app = angular.module('OcSms', []);
function inArray(val, arr) {
return ($.inArray(val, arr) != -1);
}
function arrayUnique(arr) {
unq = arr.filter(function(item, i, arr) {
return i == arr.indexOf(item);
})
return unq;
}
app.controller('OcSmsController', ['$scope', app.controller('OcSmsController', ['$scope',
function ($scope) { function ($scope) {
$scope.buttons = [ $scope.buttons = [
@ -116,7 +127,7 @@ var checkNewMessages = function() {
peerLabel = fn; peerLabel = fn;
} }
if ($.inArray(peerLabel, bufferedContacts) == -1) { if (inArray(peerLabel, bufferedContacts)) {
$("li[peer-label='" + peerLabel + "']").remove(); $("li[peer-label='" + peerLabel + "']").remove();
peerListBuf = '<li peer-label="' + peerLabel + '"><div class="ocsms-plavatar"'; peerListBuf = '<li peer-label="' + peerLabel + '"><div class="ocsms-plavatar"';
if (typeof jsondata['photos'][peerLabel] != 'undefined') { if (typeof jsondata['photos'][peerLabel] != 'undefined') {
@ -197,25 +208,8 @@ function fetchConversation(phoneNumber) {
var phoneNumberLabel = phoneNumber; var phoneNumberLabel = phoneNumber;
if (typeof jsondata['phoneNumbers'] != 'undefined') { if (typeof jsondata['phoneNumbers'] != 'undefined') {
var len = jsondata["phoneNumbers"].length; phoneNumberList = arrayUnique(jsondata['phoneNumbers']);
var ctLen = 0; phoneNumberLabel = phoneNumberList.toString();
phoneNumberLabel = '';
// This array permit to remove double entries
phoneNumberShown = [];
$.each(jsondata["phoneNumbers"], function(id, val) {
// Don't add phone numbers is they are already shown
if ($.inArray(val, phoneNumberShown)) {
continue;
}
phoneNumberLabel += val;
ctLen++;
if (ctLen != len) {
phoneNumberLabel += ",";
}
phoneNumberLabel += " ";
phoneNumberShown.push(val);
});
} }
conversationBuf = formatConversation(jsondata)[1]; conversationBuf = formatConversation(jsondata)[1];