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

Reddit users can now receive direct contributions (tips) via Brave Rewards panel #2624

Merged
merged 1 commit into from
Jun 6, 2019

Conversation

jasonrsadler
Copy link
Contributor

@jasonrsadler jasonrsadler commented Jun 6, 2019

Fixes brave/brave-browser#4745

Brave-UI: brave/brave-ui#495

Submitter Checklist:

Test Plan:

  1. Open Brave with clean profile and enable Rewards.
  2. Go to reddit.com and click on any user's name to open user's profile
  3. Click Rewards Panel and make sure that Reddit information is displayed on panel
  4. Go to https://www.reddit.com/u/jsadler-brave
  5. Click Rewards Panel and make sure that verified Reddit info is displayed (with icon)
  6. Tip verified Reddit publisher and make sure that tip banner shows Reddit information.
  7. Repeat steps 2-6 using old.reddit.com

Repeat all steps above for unverified publishers and ensure panel shows correctly (e. g. standard reddit icon, etc)

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@jasonrsadler jasonrsadler force-pushed the reddit_panel branch 2 times, most recently from 6be111d to 9be02c0 Compare June 6, 2019 14:57
@jasonrsadler jasonrsadler self-assigned this Jun 6, 2019
@jasonrsadler jasonrsadler marked this pull request as ready for review June 6, 2019 15:24
@jasonrsadler jasonrsadler changed the title Reddit panel Reddit users can now receive direct contributions (tips) via Brave Rewards panel Jun 6, 2019
Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bascially LGTM, just a few comments.

test/BUILD.gn Outdated
@@ -118,6 +118,7 @@ test("brave_unit_tests") {
if (brave_rewards_enabled) {
sources += [
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/helper_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/media/reddit_unittest.cc",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Sometimes hard to tell in a diff, but looks like extra spacing at the beginning of this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was. Removed.

// Canonicalize away 'old.reddit.com' and replace with 'www.reddit.com'.
std::string new_host = reddit_url.host().substr(
0, reddit_url.host().length());
new_host.replace(new_host.find("old"), 3, "www");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to call find here? Seems like it would always return 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not. Removed.

GURL reddit_url(url);
if (reddit_url.DomainIs(OLD_REDDIT_DOMAIN)) {
// Canonicalize away 'old.reddit.com' and replace with 'www.reddit.com'.
std::string new_host = reddit_url.host().substr(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just do a direct assignment here?

std::string new_host = reddit_url.host();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Thanks for the catches.

SergeyZhukovsky
SergeyZhukovsky previously approved these changes Jun 6, 2019
Copy link
Member

@SergeyZhukovsky SergeyZhukovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

std::string url = REDDIT_TLD;
std::string name = REDDIT_MEDIA_TYPE;

if (!url.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: switch if and return, so that we don't have this big if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

void MediaReddit::OnMediaActivityError(
const ledger::VisitData& visit_data,
uint64_t window_id) {
std::string url = REDDIT_TLD;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const ledger::VisitData& visit_data,
uint64_t window_id) {
std::string url = REDDIT_TLD;
std::string name = REDDIT_MEDIA_TYPE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

void MediaReddit::UserPath(
uint64_t window_id,
const ledger::VisitData& visit_data) {
std::string user = GetUserNameFromUrl(visit_data.path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return;
}

std::string media_key = (std::string)REDDIT_MEDIA_TYPE + "_" + user;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return std::string();
}

std::vector<std::string> parts = base::SplitString(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

uint64_t window_id,
const ledger::VisitData& visit_data,
const std::string& publisher_key) {
auto filter = ledger_->CreateActivityFilter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

emerick
emerick previously approved these changes Jun 6, 2019
Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jasonrsadler
Copy link
Contributor Author

Updated with merged brave-ui commit

@emerick emerick self-requested a review June 6, 2019 17:24
emerick
emerick previously approved these changes Jun 6, 2019
@jasonrsadler
Copy link
Contributor Author

Removed package-lock

Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Reddit Panel For Tipping
4 participants