Skip to content

Commit

Permalink
Removes icon fetching for unverified publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jan 3, 2019
1 parent 4b992d0 commit 9f502b3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 58 deletions.
51 changes: 4 additions & 47 deletions vendor/bat-native-ledger/src/bat_get_media.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ using namespace std::placeholders;

namespace braveledger_bat_get_media {

void onVisitSavedDummy(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> media_publisher_info) {
// OnMediaPublisherInfoUpdated will always be called by LedgerImpl so do nothing
}

BatGetMedia::BatGetMedia(bat_ledger::LedgerImpl* ledger):
ledger_(ledger) {
}
Expand Down Expand Up @@ -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<ledger::PublisherInfo> 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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions vendor/bat-native-ledger/src/bat_get_media.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ledger::PublisherInfo> info,
const std::string& favicon_url);

std::string getTwitchStatus(const ledger::TwitchEventInfo& oldEventInfo,
const ledger::TwitchEventInfo& newEventInfo);

Expand Down
52 changes: 49 additions & 3 deletions vendor/bat-native-ledger/src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -273,10 +283,46 @@ void BatPublishers::saveVisitInternal(

auto media_info = std::make_unique<ledger::PublisherInfo>(*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<ledger::PublisherInfo> 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";
}
}

Expand Down
8 changes: 8 additions & 0 deletions vendor/bat-native-ledger/src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ class BatPublishers : public ledger::LedgerCallbackHandler {
ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> publisher_info);

void onFetchFavIcon(const std::string& publisher_key,
bool success,
const std::string& favicon_url);

void onFetchFavIconDBResponse(ledger::Result result,
std::unique_ptr<ledger::PublisherInfo> info,
const std::string& favicon_url);

void setNumExcludedSitesInternal(ledger::PUBLISHER_EXCLUDE exclude);

void makePaymentInternal(
Expand Down

0 comments on commit 9f502b3

Please sign in to comment.