diff --git a/app/config.json b/app/config.json index 4f77a1ae65a939edcffbd7e998dc7b5d9325c6f3..0cf86cf4dabe2d4f1c489e44408075278f362350 100644 --- a/app/config.json +++ b/app/config.json @@ -9,6 +9,7 @@ "timeWarningExpire": 7776000, "useLocalStorage": false, "useRelative": true, + "initPhase": false, "node": { "host": "test-net.duniter.fr", "port": "9201" @@ -32,6 +33,7 @@ "timeWarningExpire": 7776000, "useLocalStorage": false, "useRelative": true, + "initPhase": true, "node": { "host": "duniter.le-sou.org", "port": "9600" @@ -55,6 +57,7 @@ "timeWarningExpire": 7776000, "useLocalStorage": true, "useRelative": true, + "initPhase": true, "node": { "host": "192.168.0.28", "port": "9600" diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js index 628dbc3841b48ac23feeee7b1b1770076e24cb0e..b0497e5c4569fb71e554b24744ac489784123520 100644 --- a/www/js/controllers/wot-controllers.js +++ b/www/js/controllers/wot-controllers.js @@ -84,7 +84,7 @@ angular.module('cesium.wot.controllers', ['cesium.services']) ; -function WotLookupController($scope, BMA, $state, UIUtils, $timeout, Device, Wallet, WotService, $focus) { +function WotLookupController($scope, BMA, $state, UIUtils, $timeout, csConfig, Device, Wallet, WotService, $focus) { 'ngInject'; $scope.search = { @@ -171,8 +171,11 @@ function WotLookupController($scope, BMA, $state, UIUtils, $timeout, Device, Wal size = (size && size > 0) ? size : 10; - WotService.newcomers(size) - .then(function(idties){ + var searchFunction = csConfig.initPhase ? + WotService.all : + WotService.newcomers; + + searchFunction(size).then(function(idties){ if (!$scope.search.newIncomers) return; // could have change $scope.search.results = idties || []; $scope.search.looking = false; @@ -258,14 +261,14 @@ function WotIdentityViewController($scope, $state, screenmatch, $timeout, UIUtil $scope.formData = {}; $scope.loading = true; - $scope.$on('$ionicView.enter', function(e, $state) { - if ($state.stateParams && - $state.stateParams.pubkey && - $state.stateParams.pubkey.trim().length > 0) { + $scope.$on('$ionicView.enter', function(e, state) { + if (state.stateParams && + state.stateParams.pubkey && + state.stateParams.pubkey.trim().length > 0) { if ($scope.loading) { $scope.load( - $state.stateParams.pubkey.trim(), - $state.stateParams.uid ? $state.stateParams.uid.trim() : null + state.stateParams.pubkey.trim(), + state.stateParams.uid ? state.stateParams.uid.trim() : null ); } } diff --git a/www/js/services/wot-services.js b/www/js/services/wot-services.js index 344a7ec8351092f61da1f05ee500a679d60d9980..a601d69105fb32408c3cddb1b6a17d8cd75671d2 100644 --- a/www/js/services/wot-services.js +++ b/www/js/services/wot-services.js @@ -481,6 +481,70 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic } }); }); + }, + + getAll = function() { + var letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','u','v','w','x','y','z']; + return getAllRecursive(letters, 0, 5); + }, + + getAllRecursive = function(letters, offset, size) { + return $q(function(resolve, reject) { + var result = []; + var pubkeys = {}; + var jobs = []; + _.each(letters.slice(offset, offset+size), function(letter) { + jobs.push( + search(letter) + .then(function(idties){ + if (!idties || !idties.length) return; + result = idties.reduce(function(res, idty) { + if (!pubkeys[idty.pubkey]) { + pubkeys[idty.pubkey] = true; + return res.concat(idty); + } + return res; + }, result); + }) + ); + }); + + $q.all(jobs) + .then(function() { + if (offset < letters.length - 1) { + $timeout(function() { + getAllRecursive(letters, offset+size, size) + .then(function(idties) { + if (!idties || !idties.length) { + resolve(result); + return; + } + resolve(idties.reduce(function(res, idty) { + if (!pubkeys[idty.pubkey]) { + pubkeys[idty.pubkey] = true; + return res.concat(idty); + } + return res; + }, result)); + }) + .catch(function(err) { + reject(err); + }); + }, 1000); + } + else { + resolve(result); + } + }) + .catch(function(err){ + if (err && err.ucode === BMA.errorCodes.HTTP_LIMITATION) { + resolve(result); + } + else { + reject(err); + } + }); + }); } ; @@ -493,6 +557,7 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic load: loadData, search: search, newcomers: getNewcomers, + all: getAll, // api extension api: api };