diff --git a/vendor/bat-native-ledger/src/bat_get_media.cc b/vendor/bat-native-ledger/src/bat_get_media.cc index 8951de364846..fa68d2b8b8eb 100644 --- a/vendor/bat-native-ledger/src/bat_get_media.cc +++ b/vendor/bat-native-ledger/src/bat_get_media.cc @@ -18,11 +18,6 @@ using namespace std::placeholders; namespace braveledger_bat_get_media { -void onVisitSavedDummy(ledger::Result result, - std::unique_ptr media_publisher_info) { -// OnMediaPublisherInfoUpdated will always be called by LedgerImpl so do nothing -} - BatGetMedia::BatGetMedia(bat_ledger::LedgerImpl* ledger): ledger_(ledger) { } @@ -310,36 +305,6 @@ uint64_t BatGetMedia::getTwitchDuration(const ledger::TwitchEventInfo& oldEventI return (uint64_t)std::round(time); } -void BatGetMedia::onFetchFavIcon(const std::string& publisher_key, - bool success, - const std::string& favicon_url) { - uint64_t currentReconcileStamp = ledger_->GetReconcileStamp(); - auto filter = ledger_->CreatePublisherFilter(publisher_key, - ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE, - ledger::PUBLISHER_MONTH::ANY, - -1, - ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL, - false, - currentReconcileStamp); - ledger_->GetPublisherInfo(filter, - std::bind(&BatGetMedia::onFetchFavIconDBResponse, - this, _1, _2, favicon_url)); -} - -void BatGetMedia::onFetchFavIconDBResponse(ledger::Result result, - std::unique_ptr info, - const std::string& favicon_url) { - if (result == ledger::Result::LEDGER_OK && !favicon_url.empty()) { - info->favicon_url = favicon_url; - - ledger_->SetPublisherInfo(std::move(info), - std::bind(&onVisitSavedDummy, _1, _2)); - } else { - BLOG(ledger_, ledger::LogLevel::LOG_WARNING) << - "Missing or corrupted favicon file"; - } -} - void BatGetMedia::getPublisherFromMediaPropsCallback(const uint64_t& duration, const std::string& media_key, const std::string& providerName, @@ -391,13 +356,10 @@ void BatGetMedia::getPublisherFromMediaPropsCallback(const uint64_t& duration, std::string id = providerName + "#author:" + twitchMediaID; ledger::VisitData updated_visit_data(visit_data); - updated_visit_data.favicon_url = "https://" + ledger_->GenerateGUID() + ".invalid"; updated_visit_data.name = author_name; if (fav_icon.length() > 0) { - ledger_->FetchFavIcon(fav_icon, - updated_visit_data.favicon_url, - std::bind(&BatGetMedia::onFetchFavIcon, this, id, _1, _2)); + updated_visit_data.favicon_url = fav_icon; } ledger_->SaveMediaVisit(id, updated_visit_data, duration, window_id); @@ -462,16 +424,12 @@ void BatGetMedia::savePublisherInfo(const uint64_t& duration, return; } + ledger::VisitData updated_visit_data(visit_data); + if (favIconURL.length() > 0) { - std::string favicon_key = "https://" + ledger_->GenerateGUID() + - ".invalid"; - ledger_->FetchFavIcon(favIconURL, - favicon_key, - std::bind(&BatGetMedia::onFetchFavIcon, this, publisher_id, _1, _2)); + updated_visit_data.favicon_url = favIconURL; } - ledger::VisitData updated_visit_data(visit_data); - updated_visit_data.favicon_url = ""; updated_visit_data.provider = providerName; updated_visit_data.name = publisherName; updated_visit_data.url = url; diff --git a/vendor/bat-native-ledger/src/bat_get_media.h b/vendor/bat-native-ledger/src/bat_get_media.h index cad2d7194c91..6afdeb7b532a 100644 --- a/vendor/bat-native-ledger/src/bat_get_media.h +++ b/vendor/bat-native-ledger/src/bat_get_media.h @@ -81,14 +81,6 @@ class BatGetMedia { uint64_t getTwitchDuration(const ledger::TwitchEventInfo& oldEventInfo, const ledger::TwitchEventInfo& newEventInfo); - void onFetchFavIcon(const std::string& publisher_key, - bool success, - const std::string& favicon_url); - - void onFetchFavIconDBResponse(ledger::Result result, - std::unique_ptr info, - const std::string& favicon_url); - std::string getTwitchStatus(const ledger::TwitchEventInfo& oldEventInfo, const ledger::TwitchEventInfo& newEventInfo); diff --git a/vendor/bat-native-ledger/src/bat_publishers.cc b/vendor/bat-native-ledger/src/bat_publishers.cc index 519d48032e6b..ee4019fde94a 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.cc +++ b/vendor/bat-native-ledger/src/bat_publishers.cc @@ -242,7 +242,17 @@ void BatPublishers::saveVisitInternal( duration = 0; } - publisher_info->favicon_url = visit_data.favicon_url; + std::string fav_icon = visit_data.favicon_url; + if (verified && fav_icon.length() > 0) { + ledger_->FetchFavIcon(fav_icon, + "https://" + ledger_->GenerateGUID() + ".invalid", + std::bind(&BatPublishers::onFetchFavIcon, + this, + publisher_info->id, + _1, + _2)); + } + publisher_info->name = visit_data.name; publisher_info->provider = visit_data.provider; publisher_info->url = visit_data.url; @@ -262,10 +272,45 @@ void BatPublishers::saveVisitInternal( auto media_info = std::make_unique(*publisher_info); - ledger_->SetPublisherInfo(std::move(publisher_info), std::bind(&onVisitSavedDummy, _1, _2)); + ledger_->SetPublisherInfo(std::move(publisher_info), + std::bind(&onVisitSavedDummy, _1, _2)); if (window_id > 0) { - onPublisherActivity(ledger::Result::LEDGER_OK, std::move(media_info), window_id, visit_data); + onPublisherActivity(ledger::Result::LEDGER_OK, + std::move(media_info), + window_id, + visit_data); + } +} + +void BatPublishers::onFetchFavIcon(const std::string& publisher_key, + bool success, + const std::string& favicon_url) { + uint64_t currentReconcileStamp = ledger_->GetReconcileStamp(); + auto filter = ledger_->CreatePublisherFilter(publisher_key, + ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE, + ledger::PUBLISHER_MONTH::ANY, + -1, + ledger::PUBLISHER_EXCLUDE_FILTER::FILTER_ALL, + false, + currentReconcileStamp); + ledger_->GetPublisherInfo(filter, + std::bind(&BatPublishers::onFetchFavIconDBResponse, + this, _1, _2, favicon_url)); +} + +void BatPublishers::onFetchFavIconDBResponse( + ledger::Result result, + std::unique_ptr info, + const std::string& favicon_url) { + if (result == ledger::Result::LEDGER_OK && !favicon_url.empty()) { + info->favicon_url = favicon_url; + + ledger_->SetPublisherInfo(std::move(info), + std::bind(&onVisitSavedDummy, _1, _2)); + } else { + BLOG(ledger_, ledger::LogLevel::LOG_WARNING) << + "Missing or corrupted favicon file"; } } diff --git a/vendor/bat-native-ledger/src/bat_publishers.h b/vendor/bat-native-ledger/src/bat_publishers.h index d49ec61f642b..bd870ab9ba3b 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.h +++ b/vendor/bat-native-ledger/src/bat_publishers.h @@ -155,6 +155,14 @@ class BatPublishers : public ledger::LedgerCallbackHandler { ledger::Result result, std::unique_ptr publisher_info); + void onFetchFavIcon(const std::string& publisher_key, + bool success, + const std::string& favicon_url); + + void onFetchFavIconDBResponse(ledger::Result result, + std::unique_ptr info, + const std::string& favicon_url); + void setNumExcludedSitesInternal(ledger::PUBLISHER_EXCLUDE exclude); void makePaymentInternal(