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

Publishers can now be included and excluded #591

Merged
merged 3 commits into from
Oct 23, 2018
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
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@3ff7c5021e9762bc697220ce5de4c71bfb3921df",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@aa984dc02258a42fbdf94d54a92ea454fa020201",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@adeff3254bb90ccdc9699040d5a4e1cd6b8393b7",
Expand Down
19 changes: 19 additions & 0 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ ExtensionFunction::ResponseAction BraveRewardsDonateToSiteFunction::Run() {
BraveRewardsGetPublisherDataFunction::~BraveRewardsGetPublisherDataFunction() {
}

BraveRewardsIncludeInAutoContributionFunction::
~BraveRewardsIncludeInAutoContributionFunction() {
}

ExtensionFunction::ResponseAction
BraveRewardsIncludeInAutoContributionFunction::Run() {

std::unique_ptr<brave_rewards::IncludeInAutoContribution::Params> params(
brave_rewards::IncludeInAutoContribution::Params::Create(*args_));
Profile* profile = Profile::FromBrowserContext(browser_context());
RewardsService* rewards_service_ =
RewardsServiceFactory::GetForProfile(profile);
if (rewards_service_) {
rewards_service_->SetContributionAutoInclude(
params->publisher_key, params->excluded, params->window_id);
}
return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction BraveRewardsGetPublisherDataFunction::Run() {
std::unique_ptr<brave_rewards::GetPublisherData::Params> params(
brave_rewards::GetPublisherData::Params::Create(*args_));
Expand Down
11 changes: 11 additions & 0 deletions browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ class BraveRewardsGetCurrentReportFunction : public UIThreadExtensionFunction {
ResponseAction Run() override;
};

class BraveRewardsIncludeInAutoContributionFunction :
public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveRewards.includeInAutoContribution", UNKNOWN)

protected:
~BraveRewardsIncludeInAutoContributionFunction() override;

ResponseAction Run() override;
};

} // namespace api
} // namespace extensions

Expand Down
21 changes: 20 additions & 1 deletion common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,26 @@
"type": "function",
"description": "Get current month wallet report",
"parameters": []
},
{
"name": "includeInAutoContribution",
"type": "function",
"description": "Toggles auto-contribution for rewards panel",
"parameters": [
{
"name": "publisher_key",
"type": "string"
},
{
"name": "excluded",
"type": "boolean"
},
{
"name": "window_id",
"type": "integer"
}
]
}
]
}
]
]
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/rewards_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class RewardsService : public KeyedService {
virtual void RemoveRecurring(const std::string& publisher_key) = 0;
virtual void UpdateRecurringDonationsList() = 0;
virtual void UpdateTipsList() = 0;
virtual void SetContributionAutoInclude(
std::string publisher_key, bool excluded, uint64_t windowId) = 0;

void AddObserver(RewardsServiceObserver* observer);
void RemoveObserver(RewardsServiceObserver* observer);
Expand Down
9 changes: 8 additions & 1 deletion components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ void RewardsServiceImpl::OnPublisherActivity(ledger::Result result,

publisher.percentage = info->percent;
publisher.verified = info->verified;
publisher.excluded = info->excluded;
publisher.excluded = info->excluded == ledger::PUBLISHER_EXCLUDE::EXCLUDED;
publisher.name = info->name;
publisher.url = info->url;
publisher.provider = info->provider;
Expand Down Expand Up @@ -1573,4 +1573,11 @@ void RewardsServiceImpl::OnRemoveRecurring(const std::string& publisher_key,
AsWeakPtr(), callback));
}

void RewardsServiceImpl::SetContributionAutoInclude(std::string publisher_key,
bool excluded, uint64_t windowId) {
ledger_->SetPublisherPanelExclude(publisher_key, excluded ?
ledger::PUBLISHER_EXCLUDE::EXCLUDED : ledger::PUBLISHER_EXCLUDE::INCLUDED,
windowId);
}

} // namespace brave_rewards
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class RewardsServiceImpl : public RewardsService,
void RemoveRecurring(const std::string& publisher_key) override;
void UpdateRecurringDonationsList() override;
void UpdateTipsList() override;
void SetContributionAutoInclude(
std::string publisher_key, bool excluded, uint64_t windowId) override;

private:
friend void RunIOTaskCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ export const onNotificationDeleted = (id: number, type: number, timestamp: numbe
export const deleteNotification = (id: number) => action(types.DELETE_NOTIFICATION, {
id
})

export const includeInAutoContribution = (publisherKey: string, excluded: boolean, windowId: number) => action(types.INCLUDE_IN_AUTO_CONTRIBUTION, {
publisherKey,
excluded,
windowId
})
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
setBadgeText(state)
break
}
case types.INCLUDE_IN_AUTO_CONTRIBUTION:
{
let publisherKey = payload.publisherKey
let excluded = payload.excluded
let windowId = payload.windowId
chrome.braveRewards.includeInAutoContribution(publisherKey, excluded,
windowId)
break
}
}

if (state !== startingState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ export class Panel extends React.Component<Props, State> {
console.log('doNothing click')
}

switchAutoContribute = () => {
const publisher: RewardsExtension.Publisher | undefined = this.getPublisher()
const publisherKey = publisher && publisher.publisher_key
const excluded = publisher && publisher.excluded
if (publisherKey && publisherKey.length > 0 && excluded !== undefined) {
this.props.actions.includeInAutoContribution(publisherKey, !excluded, this.props.windowId)
}
}

getPublisher = () => {
let windowId = this.props.windowId.toString()

Expand Down Expand Up @@ -251,7 +260,7 @@ export class Panel extends React.Component<Props, State> {
onToggleTips={this.doNothing}
donationAction={this.showDonateToSiteDetail}
onAmountChange={this.doNothing}
onIncludeInAuto={this.doNothing}
onIncludeInAuto={this.switchAutoContribute}
/>
: null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export const enum types {
ON_CURRENT_REPORT = '@@rewards_panel/ON_CURRENT_REPORT',
ON_NOTIFICATION_ADDED = '@@rewards_panel/ON_NOTIFICATION_ADDED',
ON_NOTIFICATION_DELETED = '@@rewards_panel/ON_NOTIFICATION_DELETED',
DELETE_NOTIFICATION = '@@rewards_panel/DELETE_NOTIFICATION'
DELETE_NOTIFICATION = '@@rewards_panel/DELETE_NOTIFICATION',
INCLUDE_IN_AUTO_CONTRIBUTION = '@@rewards_panel/INCLUDE_IN_AUTO_CONTRIBUTION'
}
1 change: 1 addition & 0 deletions components/definitions/chromel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare namespace chrome.braveRewards {
const onCurrentReport: {
addListener: (callback: (properties: RewardsExtension.Report) => void) => void
}
const includeInAutoContribution: (publisherKey: string, excluded: boolean, windowId: number) => {}
}

declare namespace chrome.rewardsNotifications {
Expand Down