From 90355cc12320d212fe642b1d2803bba3ddca5974 Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Sat, 1 Oct 2016 01:44:18 +0200 Subject: [PATCH] Wot : display all users from full lookup scan, when currency initialization (block #0 not written) --- app/config.json | 3 ++ www/js/controllers/wot-controllers.js | 21 +++++---- www/js/services/wot-services.js | 65 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/app/config.json b/app/config.json index 4f77a1ae6..0cf86cf4d 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 628dbc384..b0497e5c4 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 344a7ec83..a601d6910 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 }; -- GitLab