diff --git a/vendor/bat-native-ledger/src/bat_get_media.cc b/vendor/bat-native-ledger/src/bat_get_media.cc index 344fb5704b00..b77520906e1f 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) { } @@ -300,37 +295,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, - true); - 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, @@ -371,13 +335,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); @@ -442,16 +403,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 0d51411b0c64..f68feeae75aa 100644 --- a/vendor/bat-native-ledger/src/bat_get_media.h +++ b/vendor/bat-native-ledger/src/bat_get_media.h @@ -80,14 +80,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 35d9814ce861..66446d6888da 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.cc +++ b/vendor/bat-native-ledger/src/bat_publishers.cc @@ -253,7 +253,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; @@ -273,10 +283,46 @@ 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, + true); + 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 0ebf8939570d..2dee8e3d6df1 100644 --- a/vendor/bat-native-ledger/src/bat_publishers.h +++ b/vendor/bat-native-ledger/src/bat_publishers.h @@ -156,6 +156,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(