Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Publisher refactor #183

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 19 additions & 15 deletions include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LEDGER_EXPORT struct VisitData {
const std::string& _domain,
const std::string& _path,
uint32_t _tab_id,
PUBLISHER_MONTH _local_month,
ACTIVITY_MONTH _local_month,
int _local_year,
const std::string& name,
const std::string& url,
Expand All @@ -39,7 +39,7 @@ LEDGER_EXPORT struct VisitData {
std::string domain;
std::string path;
uint32_t tab_id;
PUBLISHER_MONTH local_month;
ACTIVITY_MONTH local_month;
int local_year;
std::string name;
std::string url;
Expand All @@ -52,17 +52,17 @@ LEDGER_EXPORT struct PaymentData {
PaymentData(const std::string& _publisher_id,
const double& _value,
const int64_t& _timestamp,
PUBLISHER_CATEGORY _category,
PUBLISHER_MONTH _local_month,
REWARDS_CATEGORY _category,
ACTIVITY_MONTH _local_month,
int _local_year);
PaymentData(const PaymentData& data);
~PaymentData();

std::string publisher_id;
double value;
int64_t timestamp;
PUBLISHER_CATEGORY category;
PUBLISHER_MONTH local_month;
REWARDS_CATEGORY category;
ACTIVITY_MONTH local_month;
int local_year;
};

Expand Down Expand Up @@ -118,18 +118,22 @@ class LEDGER_EXPORT Ledger {

virtual void SetPublisherInfo(std::unique_ptr<PublisherInfo> publisher_info,
PublisherInfoCallback callback) = 0;
virtual void GetPublisherInfo(const ledger::PublisherInfoFilter& filter,
virtual void SetActivityInfo(std::unique_ptr<PublisherInfo> publisher_info,
PublisherInfoCallback callback) = 0;
virtual void GetPublisherInfo(const std::string& publisher_key,
PublisherInfoCallback callback) = 0;
virtual void GetActivityInfo(const ledger::ActivityInfoFilter& filter,
PublisherInfoCallback callback) = 0;
virtual void SetMediaPublisherInfo(const std::string& media_key,
const std::string& publisher_id) = 0;
virtual void GetMediaPublisherInfo(const std::string& media_key,
PublisherInfoCallback callback) = 0;
virtual std::vector<ContributionInfo> GetRecurringDonationPublisherInfo() = 0;
virtual void GetPublisherInfoList(uint32_t start, uint32_t limit,
const ledger::PublisherInfoFilter& filter,
virtual void GetActivityInfoList(uint32_t start, uint32_t limit,
const ledger::ActivityInfoFilter& filter,
PublisherInfoListCallback callback) = 0;
virtual void GetCurrentPublisherInfoList(uint32_t start, uint32_t limit,
const ledger::PublisherInfoFilter& filter,
const ledger::ActivityInfoFilter& filter,
ledger::PublisherInfoListCallback callback) = 0;

virtual void SetRewardsMainEnabled(bool enabled) = 0;
Expand All @@ -140,7 +144,7 @@ class LEDGER_EXPORT Ledger {
virtual void SetContributionAmount(double amount) = 0;
virtual void SetUserChangedContribution() = 0;
virtual void SetAutoContribute(bool enabled) = 0;
virtual void SetBalanceReport(PUBLISHER_MONTH month,
virtual void SetBalanceReport(ACTIVITY_MONTH month,
int year,
const ledger::BalanceReportInfo& report_info) = 0;

Expand All @@ -162,7 +166,7 @@ class LEDGER_EXPORT Ledger {
virtual void SolveGrantCaptcha(const std::string& solution) const = 0;
virtual void GetGrantCaptcha() const = 0;
virtual std::string GetWalletPassphrase() const = 0;
virtual bool GetBalanceReport(PUBLISHER_MONTH month,
virtual bool GetBalanceReport(ACTIVITY_MONTH month,
int year,
ledger::BalanceReportInfo* report_info) const = 0;
virtual std::map<std::string, ledger::BalanceReportInfo> GetAllBalanceReports() const = 0;
Expand All @@ -178,16 +182,16 @@ class LEDGER_EXPORT Ledger {
virtual void RestorePublishers() = 0;
virtual bool IsWalletCreated() const = 0;
virtual void GetPublisherActivityFromUrl(uint64_t windowId, const ledger::VisitData& visit_data) = 0;
virtual void SetBalanceReportItem(PUBLISHER_MONTH month,
virtual void SetBalanceReportItem(ACTIVITY_MONTH month,
int year,
ledger::ReportType type,
const std::string& probi) = 0;
virtual void GetPublisherBanner(const std::string& publisher_id, ledger::PublisherBannerCallback callback) = 0;
virtual double GetBalance() = 0;
virtual void OnReconcileCompleteSuccess(const std::string& viewing_id,
const ledger::PUBLISHER_CATEGORY category,
const ledger::REWARDS_CATEGORY category,
const std::string& probi,
const ledger::PUBLISHER_MONTH month,
const ledger::ACTIVITY_MONTH month,
const int year,
const uint32_t date) = 0;
virtual void RemoveRecurring(const std::string& publisher_key) = 0;
Expand Down
20 changes: 14 additions & 6 deletions include/bat/ledger/ledger_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ using GetNicewareListCallback =
using RecurringDonationCallback = std::function<void(const PublisherInfoList&)>;
using RecurringRemoveCallback = std::function<void(Result)>;
using FetchIconCallback = std::function<void(bool, const std::string&)>;
using OnRestoreCallback = std::function<void(bool)>;

class LEDGER_EXPORT LedgerClient {
public:
Expand All @@ -68,7 +69,7 @@ class LEDGER_EXPORT LedgerClient {
std::unique_ptr<ledger::WalletInfo>) = 0;
virtual void OnReconcileComplete(Result result,
const std::string& viewing_id,
ledger::PUBLISHER_CATEGORY category,
ledger::REWARDS_CATEGORY category,
const std::string& probi) = 0;

virtual void LoadLedgerState(LedgerCallbackHandler* handler) = 0;
Expand All @@ -88,17 +89,23 @@ class LEDGER_EXPORT LedgerClient {

virtual void SavePublisherInfo(std::unique_ptr<PublisherInfo> publisher_info,
PublisherInfoCallback callback) = 0;
virtual void LoadPublisherInfo(PublisherInfoFilter filter,
virtual void SaveActivityInfo(std::unique_ptr<PublisherInfo> publisher_info,
PublisherInfoCallback callback) = 0;
virtual void LoadPublisherInfo(const std::string& publisher_key,
PublisherInfoCallback callback) = 0;
virtual void LoadActivityInfo(ActivityInfoFilter filter,
PublisherInfoCallback callback) = 0;
virtual void LoadPanelPublisherInfo(ActivityInfoFilter filter,
PublisherInfoCallback callback) = 0;
virtual void LoadMediaPublisherInfo(const std::string& media_key,
PublisherInfoCallback callback) = 0;
virtual void SaveMediaPublisherInfo(const std::string& media_key,
const std::string& publisher_id) = 0;
virtual void LoadPublisherInfoList(uint32_t start, uint32_t limit,
PublisherInfoFilter filter,
virtual void LoadActivityInfoList(uint32_t start, uint32_t limit,
ActivityInfoFilter filter,
PublisherInfoListCallback callback) = 0;
virtual void LoadCurrentPublisherInfoList(uint32_t start, uint32_t limit,
PublisherInfoFilter filter,
ActivityInfoFilter filter,
PublisherInfoListCallback callback) = 0;

// TODO this can be removed
Expand All @@ -120,7 +127,7 @@ class LEDGER_EXPORT LedgerClient {
const int year,
const uint32_t date,
const std::string& publisher_key,
const ledger::PUBLISHER_CATEGORY category) = 0;
const ledger::REWARDS_CATEGORY category) = 0;
virtual void GetRecurringDonations(ledger::PublisherInfoListCallback callback) = 0;
virtual void OnRemoveRecurring(const std::string& publisher_key,
ledger::RecurringRemoveCallback callback) = 0;
Expand Down Expand Up @@ -149,6 +156,7 @@ class LEDGER_EXPORT LedgerClient {
const char* file,
int line,
const ledger::LogLevel log_level) const = 0;
virtual void OnRestorePublishers(ledger::OnRestoreCallback callback) = 0;
};

} // namespace ledger
Expand Down
25 changes: 12 additions & 13 deletions include/bat/ledger/publisher_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

namespace ledger {

LEDGER_EXPORT enum PUBLISHER_CATEGORY {
LEDGER_EXPORT enum REWARDS_CATEGORY {
AUTO_CONTRIBUTE = 1 << 1,
TIPPING = 1 << 2,
DIRECT_DONATION = 1 << 3,
RECURRING_DONATION = 1 << 4,
ALL_CATEGORIES = (1 << 5) - 1,
};

LEDGER_EXPORT enum PUBLISHER_MONTH {
LEDGER_EXPORT enum ACTIVITY_MONTH {
ANY = -1,
JANUARY = 1,
FEBRUARY = 2,
Expand All @@ -44,24 +44,23 @@ LEDGER_EXPORT enum PUBLISHER_EXCLUDE {
INCLUDED = 2 // user manually changed it to include and is overriding server flags
};

LEDGER_EXPORT enum PUBLISHER_EXCLUDE_FILTER {
LEDGER_EXPORT enum EXCLUDE_FILTER {
FILTER_ALL = -1,
FILTER_DEFAULT = 0,
FILTER_EXCLUDED = 1,
FILTER_INCLUDED = 2,
FILTER_ALL_EXCEPT_EXCLUDED = 3
};

LEDGER_EXPORT struct PublisherInfoFilter {
PublisherInfoFilter();
PublisherInfoFilter(const PublisherInfoFilter& filter);
~PublisherInfoFilter();
LEDGER_EXPORT struct ActivityInfoFilter {
ActivityInfoFilter();
ActivityInfoFilter(const ActivityInfoFilter& filter);
~ActivityInfoFilter();

std::string id;
int category;
PUBLISHER_MONTH month;
ACTIVITY_MONTH month;
int year;
PUBLISHER_EXCLUDE_FILTER excluded;
EXCLUDE_FILTER excluded;
std::vector<std::pair<std::string, bool>> order_by;
unsigned int min_duration;
uint64_t reconcile_stamp;
Expand Down Expand Up @@ -96,7 +95,7 @@ LEDGER_EXPORT struct PublisherBanner {

LEDGER_EXPORT struct PublisherInfo {
PublisherInfo();
PublisherInfo(const std::string& publisher_id, PUBLISHER_MONTH month, int year);
PublisherInfo(const std::string& publisher_id, ACTIVITY_MONTH month, int year);
PublisherInfo(const PublisherInfo& info);
~PublisherInfo();

Expand All @@ -110,8 +109,8 @@ LEDGER_EXPORT struct PublisherInfo {
uint32_t percent;
double weight;
PUBLISHER_EXCLUDE excluded;
PUBLISHER_CATEGORY category;
PUBLISHER_MONTH month;
REWARDS_CATEGORY category;
ACTIVITY_MONTH month;
int year;
uint64_t reconcile_stamp;
bool verified;
Expand Down
32 changes: 15 additions & 17 deletions src/bat/ledger/ledger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ VisitData::VisitData(const std::string& _tld,
const std::string& _domain,
const std::string& _path,
uint32_t _tab_id,
PUBLISHER_MONTH _local_month,
ACTIVITY_MONTH _local_month,
int _local_year,
const std::string& _name,
const std::string& _url,
Expand Down Expand Up @@ -58,13 +58,13 @@ VisitData::~VisitData() {}
PaymentData::PaymentData():
value(0),
timestamp(0),
category(PUBLISHER_CATEGORY::TIPPING) {}
category(REWARDS_CATEGORY::TIPPING) {}

PaymentData::PaymentData(const std::string& _publisher_id,
const double& _value,
const int64_t& _timestamp,
PUBLISHER_CATEGORY _category,
PUBLISHER_MONTH _local_month,
REWARDS_CATEGORY _category,
ACTIVITY_MONTH _local_month,
int _local_year):
publisher_id(_publisher_id),
value(_value),
Expand All @@ -83,23 +83,21 @@ PaymentData::PaymentData(const PaymentData& data):

PaymentData::~PaymentData() {}

PublisherInfoFilter::PublisherInfoFilter() :
category(PUBLISHER_CATEGORY::ALL_CATEGORIES),
month(PUBLISHER_MONTH::ANY),
ActivityInfoFilter::ActivityInfoFilter() :
month(ACTIVITY_MONTH::ANY),
year(-1),
excluded(PUBLISHER_EXCLUDE_FILTER::FILTER_DEFAULT),
excluded(EXCLUDE_FILTER::FILTER_DEFAULT),
min_duration(0),
reconcile_stamp(0) {}
PublisherInfoFilter::PublisherInfoFilter(const PublisherInfoFilter& filter) :
ActivityInfoFilter::ActivityInfoFilter(const ActivityInfoFilter& filter) :
id(filter.id),
category(filter.category),
month(filter.month),
year(filter.year),
excluded(filter.excluded),
order_by(filter.order_by),
min_duration(filter.min_duration),
reconcile_stamp(filter.reconcile_stamp) {}
PublisherInfoFilter::~PublisherInfoFilter() {}
ActivityInfoFilter::~ActivityInfoFilter() {}

PublisherBanner::PublisherBanner() {}

Expand All @@ -123,8 +121,8 @@ PublisherInfo::PublisherInfo() :
percent(0u),
weight(.0),
excluded(PUBLISHER_EXCLUDE::DEFAULT),
category(PUBLISHER_CATEGORY::AUTO_CONTRIBUTE),
month(PUBLISHER_MONTH::ANY),
category(REWARDS_CATEGORY::AUTO_CONTRIBUTE),
month(ACTIVITY_MONTH::ANY),
year(-1),
reconcile_stamp(0),
verified(false),
Expand All @@ -134,7 +132,7 @@ PublisherInfo::PublisherInfo() :
favicon_url("") {}

PublisherInfo::PublisherInfo(const std::string& publisher_id,
PUBLISHER_MONTH _month,
ACTIVITY_MONTH _month,
int _year) :
id(publisher_id),
duration(0u),
Expand All @@ -143,7 +141,7 @@ PublisherInfo::PublisherInfo(const std::string& publisher_id,
percent(0u),
weight(.0),
excluded(PUBLISHER_EXCLUDE::DEFAULT),
category(PUBLISHER_CATEGORY::AUTO_CONTRIBUTE),
category(REWARDS_CATEGORY::AUTO_CONTRIBUTE),
month(_month),
year(_year),
reconcile_stamp(0),
Expand Down Expand Up @@ -179,10 +177,10 @@ bool PublisherInfo::operator<(const PublisherInfo& rhs) const {
}

bool PublisherInfo::is_valid() const {
return !id.empty() && year > 0 && month != PUBLISHER_MONTH::ANY;
return !id.empty() && year > 0 && month != ACTIVITY_MONTH::ANY;
}

const PublisherInfo invalid("", PUBLISHER_MONTH::ANY, -1);
const PublisherInfo invalid("", ACTIVITY_MONTH::ANY, -1);


TwitchEventInfo::TwitchEventInfo() {}
Expand Down
Loading