diff --git a/www/plugins/es/js/controllers/settings-controllers.js b/www/plugins/es/js/controllers/settings-controllers.js index 1d70bdf58a3302c438f0787a6ea617519ec32a33..449ad5996b3fb169436ec8ea5d8dd1449839c103 100644 --- a/www/plugins/es/js/controllers/settings-controllers.js +++ b/www/plugins/es/js/controllers/settings-controllers.js @@ -69,17 +69,26 @@ function ESPluginSettingsController ($scope, $window, $q, $translate, $ionicPop $scope.isFallbackNode = $scope.formData.enable && esHttp.node.isFallback(); $scope.server = $scope.getServer(esHttp); - // Load moderators - esHttp.node.moderators() - .then(function(res) { - $scope.moderator = csWallet.isLogin() && _.contains(res && res.moderators, csWallet.data.pubkey); - if ($scope.moderator) console.info("[ES] [peer] Wallet user is a moderator"); - $scope.loading = false; - }).catch(function(err) { - console.error("[ES] [peer] Cannot load moderators. Too old Pod version ?"); - $scope.moderator = false; - $scope.loading = false; - }); + // Disable : ok + if (!$scope.formData.enable) { + $scope.moderator = false; + $scope.loading = false; + return $q.when(); + } + else { + + // Load moderators + return esHttp.node.moderators() + .then(function(res) { + $scope.moderator = csWallet.isLogin() && _.contains(res && res.moderators, csWallet.data.pubkey); + if ($scope.moderator) console.info("[ES] [http] Wallet user is a moderator"); + $scope.loading = false; + }).catch(function(err) { + console.error("[ES] [http] Cannot load moderators. Too old Pod version ?", err); + $scope.moderator = false; + $scope.loading = false; + }); + } }; esSettings.api.state.on.changed($scope, function(enable) { diff --git a/www/plugins/es/js/services/group-services.js b/www/plugins/es/js/services/group-services.js index f0a216c18c6eaaa8a020f358bfa447836a74d0b8..022e686395a72826d5a12844794daa5bbd32b538 100644 --- a/www/plugins/es/js/services/group-services.js +++ b/www/plugins/es/js/services/group-services.js @@ -23,7 +23,11 @@ angular.module('cesium.es.group.services', ['cesium.platform', 'cesium.es.http.s notifications: ["issuer", "time", "hash", "read_signature"] }, exports = { - _internal: {} + raw: { + search: esHttp.post('/group/record/_search'), + get: esHttp.get('/group/record/:id'), + getCommons: esHttp.get('/group/record/:id?_source=' + fields.commons.join(',')) + } }; function onWalletInit(data) { @@ -100,10 +104,9 @@ angular.module('cesium.es.group.services', ['cesium.platform', 'cesium.es.http.s return record; } - exports._internal.search = esHttp.post('/group/record/_search'); function _executeSearchRequest(request) { - return exports._internal.search(request) + return exports.raw.search(request) .then(function(res) { if (!res || !res.hits || !res.hits.total) { return []; @@ -185,8 +188,6 @@ angular.module('cesium.es.group.services', ['cesium.platform', 'cesium.es.http.s return _executeSearchRequest(request); } - exports._internal.get = esHttp.get('/group/record/:id'); - exports._internal.getCommons = esHttp.get('/group/record/:id?_source=' + fields.commons.join(',')); function loadData(id, options) { options = options || {}; @@ -195,8 +196,8 @@ angular.module('cesium.es.group.services', ['cesium.platform', 'cesium.es.http.s // Do get source var promise = options.fecthPictures ? - exports._internal.get({id: id}) : - exports._internal.getCommons({id: id}); + exports.raw.get({id: id}) : + exports.raw.getCommons({id: id}); return promise .then(function(hit) { diff --git a/www/plugins/es/js/services/http-services.js b/www/plugins/es/js/services/http-services.js index f20aa8d1b62e9f0f9d0dda09e5442c2cdebbc71f..51b57ed7c3e5988393e80b1cccdca05c5db21bf0 100644 --- a/www/plugins/es/js/services/http-services.js +++ b/www/plugins/es/js/services/http-services.js @@ -127,7 +127,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic if (!that.raw) return; - console.warn('[ES] [http] Closing all websockets...'); + console.debug('[ES] [http] Closing all websockets...'); _.keys(that.raw.wsByPath||{}).forEach(function(key) { var sock = that.raw.wsByPath[key]; sock.close(); @@ -327,6 +327,8 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic if (that._startPromise) return that._startPromise; if (that.started) return $q.when(that.alive); + console.debug('[ES] [http] Starting...'); + that._startPromise = csPlatform.ready() .then(function() { diff --git a/www/plugins/es/js/services/invitation-services.js b/www/plugins/es/js/services/invitation-services.js index d6e1bc374b87e74e2060433cc0f8a51dd7f9ac8d..ea048ca7cda8ead6a07006dcbfacb93a2dd9ab19 100644 --- a/www/plugins/es/js/services/invitation-services.js +++ b/www/plugins/es/js/services/invitation-services.js @@ -32,7 +32,8 @@ angular.module('cesium.es.invitation.services', ['cesium.platform', add: esHttp.record.post('/invitation/certification'), postSearch: esHttp.post('/invitation/certification/_search'), remove: esHttp.record.remove('invitation', 'certification'), - getIds: esHttp.get('/invitation/certification/_search?q=recipient::pubkey&_source=false&size=1000') + getIds: esHttp.get('/invitation/certification/_search?q=recipient::pubkey&_source=false&size=1000'), + count: esHttp.post('/invitation/certification/_count') } }; @@ -152,7 +153,7 @@ angular.module('cesium.es.invitation.services', ['cesium.platform', // TODO : count using size=0 // and with 'group by' on type - return esHttp.post('/invitation/certification/_count')(request) + return that.raw.count(request) .then(function(res) { return res.count; }); diff --git a/www/plugins/es/js/services/message-services.js b/www/plugins/es/js/services/message-services.js index 4da3ae86e5fab715f4e3b71e3dbb643d8d9e013c..58c85b5d94e401b2842593d0cfc292ff58280a75 100644 --- a/www/plugins/es/js/services/message-services.js +++ b/www/plugins/es/js/services/message-services.js @@ -24,10 +24,11 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', notifications: ["issuer", "time", "hash", "read_signature"] }, raw = { - postSearch: esHttp.post('/message/inbox/_search'), - postSearchByType: esHttp.post('/message/:type/_search'), + search: esHttp.post('/message/inbox/_search'), + searchByType: esHttp.post('/message/:type/_search'), getByTypeAndId : esHttp.get('/message/:type/:id'), - postReadById: esHttp.post('/message/inbox/:id/_read') + postReadById: esHttp.post('/message/inbox/:id/_read'), + count: esHttp.post('/message/inbox/_count') }, listeners, api = new Api(this, 'esMessage'); @@ -119,7 +120,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', request.query.bool.must.push({range: {time: {gt: options.readTime}}}); } - return esHttp.post('/message/inbox/_count')(request) + return raw.count(request) .then(function(res) { return res.count; }); @@ -147,7 +148,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', _source: ['time'] }; - return esHttp.post('/message/inbox/_search')(request) + return raw.search(request) .then(function(res) { if (!res || !res.hits || !res.hits.total || !res.hits.hits) return undefined; return res.hits.hits[0] && res.hits.hits[0]._source && res.hits.hits[0]._source.time; @@ -254,7 +255,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', _source: fields.notifications }; - return raw.postSearch(request) + return raw.search(request) .then(function(res) { if (!res || !res.hits || !res.hits.total) return []; var notifications = res.hits.hits.reduce(function(result, hit) { @@ -286,14 +287,14 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', _source: options._source }; - if (options.type == 'inbox') { + if (options.type === 'inbox') { request.query = {bool: {filter: {term: {recipient: pubkey}}}}; } else { request.query = {bool: {filter: {term: {issuer: pubkey}}}}; } - return raw.postSearchByType(request, {type: options.type}) + return raw.searchByType(request, {type: options.type}) .then(function(res) { if (!res || !res.hits || !res.hits.total) { return []; @@ -301,7 +302,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', var messages = res.hits.hits.reduce(function(res, hit) { var msg = hit._source || {}; msg.id = hit._id; - msg.read = (options.type == 'outbox') || !!msg.read_signature; + msg.read = (options.type === 'outbox') || !!msg.read_signature; delete msg.read_signature; // not need anymore return res.concat(msg); }, []); @@ -390,7 +391,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', if (!hit.found) return; var msg = hit._source; msg.id = hit._id; - msg.read = (type == 'outbox') || !!msg.read_signature; + msg.read = (type === 'outbox') || !!msg.read_signature; delete msg.read_signature; // not need anymore // Decrypt message @@ -398,7 +399,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', // Add avatar .then(function(){ - var avatarField = (type == 'inbox') ? 'issuer' : 'recipient'; + var avatarField = (type === 'inbox') ? 'issuer' : 'recipient'; return csWot.extend(msg, avatarField); }); }); @@ -469,7 +470,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', if (message.content) { message.summary = message.content.replace(/(^|[\n\r]+)\s*>[^\n\r]*/g, '').trim(); if (message.summary.length > 140) { - message.summary = message.summary.substr(0, 137) + '...'; + message.summary = message.summary.substring(0, 137) + '...'; } } } @@ -748,7 +749,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', return { api: api, - search: raw.postSearch, + search: raw.search, notifications: { load: loadMessageNotifications }, diff --git a/www/plugins/es/js/services/profile-services.js b/www/plugins/es/js/services/profile-services.js index a0d7339cb6d5becbba8d4d51c73f8856d2ef948d..e3f3c88c66415275cd4806860a829c1cc8681906 100644 --- a/www/plugins/es/js/services/profile-services.js +++ b/www/plugins/es/js/services/profile-services.js @@ -387,13 +387,13 @@ angular.module('cesium.es.profile.services', ['cesium.services', 'cesium.es.http } function refreshState() { - var enable = esHttp.alive; + var enable = esSettings.isEnable() && esHttp.alive; if (!enable && listeners && listeners.length > 0) { - console.debug("[ES] [profile] Disable"); + console.debug("[ES] [profile] WoT extend disable"); removeListeners(); } else if (enable && (!listeners || listeners.length === 0)) { - console.debug("[ES] [profile] Enable"); + console.debug("[ES] [profile] WoT extend enable"); addListeners(); } }