Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rewards] Update publisher info when name or url change. #13475

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,18 @@ const handleSavePublisherVisit = (tabId: number, mediaType: string, data: SavePu

chrome.braveRewards.getPublisherInfo(
data.publisherKey, (result: RewardsExtension.Result, info?: RewardsExtension.Publisher) => {
let shouldUpdate = false
if (result === 0 && info) {
getPublisherPanelInfo(tabId, data.publisherKey)
return
shouldUpdate = (info.name !== data.publisherName || info.url !== data.url)
if (!shouldUpdate) {
getPublisherPanelInfo(tabId, data.publisherKey)
return
}
}

// Failed to find publisher info corresponding to this key, so save it now
if (result === 9) {
// Failed to find the publisher info corresponding to this key or the
// publisher info needs to be updated, so save the info now
if (result === 9 || shouldUpdate) {
savePublisherInfo(
tabId,
mediaType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,14 @@ void Publisher::SaveVisitInternal(
bool is_verified = IsConnectedOrVerified(status);

bool new_publisher = false;
bool updated_publisher = false;
if (!publisher_info) {
new_publisher = true;
publisher_info = type::PublisherInfo::New();
publisher_info->id = publisher_key;
} else if (publisher_info->name != visit_data.name ||
publisher_info->url != visit_data.url) {
updated_publisher = true;
}

std::string fav_icon = visit_data.favicon_url;
Expand Down Expand Up @@ -337,22 +341,18 @@ void Publisher::SaveVisitInternal(
bool verified_new = !allow_non_verified && !is_verified;
bool verified_old = allow_non_verified || is_verified;

if (new_publisher &&
(excluded ||
!ledger_->state()->GetAutoContributeEnabled() ||
min_duration_new ||
verified_new)) {
if ((new_publisher || updated_publisher) &&
(excluded || !ledger_->state()->GetAutoContributeEnabled() ||
min_duration_new || verified_new)) {
panel_info = publisher_info->Clone();

auto callback = std::bind(&Publisher::OnPublisherInfoSaved,
this,
_1);

ledger_->database()->SavePublisherInfo(std::move(publisher_info), callback);
} else if (!excluded &&
ledger_->state()->GetAutoContributeEnabled() &&
min_duration_ok &&
verified_old) {
} else if (!excluded && ledger_->state()->GetAutoContributeEnabled() &&
min_duration_ok && verified_old) {
if (first_visit) {
publisher_info->visits += 1;
}
Expand Down