From 0c8231abe5b66c406c61abca227570e53421e7bb Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Tue, 20 Nov 2018 20:03:49 +0100 Subject: [PATCH] Refactors restore flow --- include/bat/ledger/ledger_client.h | 3 +++ src/bat_publishers.cc | 26 ++++++-------------------- src/bat_publishers.h | 4 ++-- src/ledger_impl.cc | 6 +++++- src/ledger_impl.h | 1 + 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/include/bat/ledger/ledger_client.h b/include/bat/ledger/ledger_client.h index 9434c9e..58ac890 100644 --- a/include/bat/ledger/ledger_client.h +++ b/include/bat/ledger/ledger_client.h @@ -46,6 +46,7 @@ using GetNicewareListCallback = using RecurringDonationCallback = std::function; using RecurringRemoveCallback = std::function; using FetchIconCallback = std::function; +using OnRestoreCallback = std::function; class LEDGER_EXPORT LedgerClient { public: @@ -141,6 +142,8 @@ class LEDGER_EXPORT LedgerClient { // Log debug information virtual void Log(ledger::LogLevel level, const std::string& text) = 0; + + virtual void OnRestorePublishers(ledger::OnRestoreCallback callback) = 0; }; } // namespace ledger diff --git a/src/bat_publishers.cc b/src/bat_publishers.cc index e1ad139..7e0b68d 100644 --- a/src/bat_publishers.cc +++ b/src/bat_publishers.cc @@ -368,28 +368,14 @@ void BatPublishers::onSetPanelExcludeInternal(ledger::PUBLISHER_EXCLUDE exclude, OnExcludedSitesChanged(); } -// TODO refactor -void BatPublishers::restorePublishers() { - uint64_t currentReconcileStamp = ledger_->GetReconcileStamp(); - auto filter = CreateActivityFilter("", - ledger::ACTIVITY_MONTH::ANY, - -1, - ledger::EXCLUDE_FILTER::FILTER_EXCLUDED, - false, - currentReconcileStamp); - ledger_->GetActivityInfoList(0, 0, filter, std::bind(&BatPublishers::onRestorePublishersInternal, - this, _1, _2)); +void BatPublishers::RestorePublishers() { + ledger_->OnRestorePublishers(std::bind(&BatPublishers::OnRestorePublishersInternal, + this, _1)); } -void BatPublishers::onRestorePublishersInternal(const ledger::PublisherInfoList& publisherInfoList, uint32_t /* next_record */) { - if (publisherInfoList.size() == 0) { - return; - } - - for (size_t i = 0; i < publisherInfoList.size(); i++) { - // Set to PUBLISHER_EXCLUDE::DEFAULT (0) - setExclude(publisherInfoList[i].id, - ledger::PUBLISHER_EXCLUDE::DEFAULT); +void BatPublishers::OnRestorePublishersInternal(bool success) { + if (success) { + setNumExcludedSites(0); } } diff --git a/src/bat_publishers.h b/src/bat_publishers.h index e58fdc6..4fd9aec 100644 --- a/src/bat_publishers.h +++ b/src/bat_publishers.h @@ -56,7 +56,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler { void setPanelExclude(const std::string& publisher_id, const ledger::PUBLISHER_EXCLUDE& exclude, uint64_t windowId); - void restorePublishers(); + void RestorePublishers(); void setPublisherAllowNonVerified(const bool& allow); void setPublisherAllowVideos(const bool& allow); @@ -168,7 +168,7 @@ class BatPublishers : public ledger::LedgerCallbackHandler { ledger::Result result, std::unique_ptr publisher_info); - void onRestorePublishersInternal(const ledger::PublisherInfoList& publisherInfoList, uint32_t /* next_record */); + void OnRestorePublishersInternal(bool success); double concaveScore(const uint64_t& duration); diff --git a/src/ledger_impl.cc b/src/ledger_impl.cc index 23c60f8..ee38a12 100644 --- a/src/ledger_impl.cc +++ b/src/ledger_impl.cc @@ -320,7 +320,11 @@ void LedgerImpl::SetPublisherPanelExclude(const std::string& publisher_id, } void LedgerImpl::RestorePublishers() { - bat_publishers_->restorePublishers(); + bat_publishers_->RestorePublishers(); +} + +void LedgerImpl::OnRestorePublishers(ledger::OnRestoreCallback callback) { + ledger_client_->OnRestorePublishers(callback); } void LedgerImpl::LoadNicewareList(ledger::GetNicewareListCallback callback) { diff --git a/src/ledger_impl.h b/src/ledger_impl.h index d313c5e..7541b53 100644 --- a/src/ledger_impl.h +++ b/src/ledger_impl.h @@ -161,6 +161,7 @@ class LedgerImpl : public ledger::Ledger, const ledger::PUBLISHER_EXCLUDE& exclude, uint64_t windowId) override; void RestorePublishers() override; + void OnRestorePublishers(ledger::OnRestoreCallback callback); bool IsWalletCreated() const override; void GetPublisherActivityFromUrl(uint64_t windowId, const ledger::VisitData& visit_data) override; void GetMediaActivityFromUrl(uint64_t windowId,