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

Internal subscriptions #1424

Merged
merged 1 commit into from
May 15, 2018
Merged

Internal subscriptions #1424

merged 1 commit into from
May 15, 2018

Conversation

neb-b
Copy link

@neb-b neb-b commented May 2, 2018

Adds subscriptions to our internal-api database

Notes

Ideally this should live in lbry-redux. It seems like there is still some work moving lbry.call over, mostly with auth stuff. And we need to figure out how we want to interact between app code and lbry-redux code. Currently the the subscriptions actions we are using doPurchaseUri which doesn't exist in lbry-redux. It shouldn't be too difficult to move over, but will just take some planning. I thought it was out of the scope for this PR.

Implementation

There are 3 main scenarios that cause some extra logic re: respecting users privacy. If a user decides not to share app usage, we will not make any calls to the db. If they are sharing data with us, this is what happens:

0 subs in db, but x subs in redux:
- This will happen on the initial run, or if users decide to start sharing data after they have subscribed to a channel
- In this case we will populate every sub in redux into the db


x subs in db, but 0 subs in redux:
- This will happen if a user clears there cache
- Populate all subs in db into redux
- This will cause issues with users who have subscribed, then stopped sharing data, and unsubscribed from everyone, then started sharing data again. They will be re-subscribed (I think this is ok for now)

x subs in db, y subs in redux:
- There is some mismatch from failing api calls or stopping/starting to share app usage
- Default to whats in redux
- Subscribe to any missing channels in the db
- Unsubscribe to any channels in the db that aren't in redux

@neb-b neb-b force-pushed the internal-subscriptions branch 2 times, most recently from b8f568e to 0331298 Compare May 2, 2018 21:21
@lbryio lbryio deleted a comment May 2, 2018
@lbryio lbryio deleted a comment May 2, 2018
@neb-b neb-b requested a review from kauffj May 2, 2018 21:58
@lbry-bot lbry-bot assigned kauffj and unassigned neb-b May 2, 2018
@neb-b neb-b requested a review from IGassmann May 2, 2018 21:58
@neb-b neb-b requested a review from liamcardenas May 2, 2018 21:58
@neb-b neb-b removed the request for review from IGassmann May 2, 2018 21:58
@neb-b neb-b changed the title [WIP] Internal subscriptions Internal subscriptions May 3, 2018
@neb-b neb-b force-pushed the internal-subscriptions branch 2 times, most recently from 8611169 to a22813b Compare May 5, 2018 22:16
};

class Page extends React.PureComponent<Props, State> {
static getDerivedStateFromProps(nextProps: Props, prevState: State) {
Copy link
Author

Choose a reason for hiding this comment

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

React recommends getDerivedStateFromProps moving forward instead of componentWillReceiveProps

@@ -34,6 +34,7 @@
"singleQuote": true
}],
"func-names": ["warn", "as-needed"],
"jsx-a11y/label-has-for": 0
"jsx-a11y/label-has-for": 0,
"import/prefer-default-export": 0
Copy link
Author

Choose a reason for hiding this comment

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

IMO this isn't needed. Mostly for util files, I don't want to add the first one as a default export if I think there may be more functions added later.

};

export const doChannelUnsubscribe = (subscription: Subscription) => (dispatch: Dispatch) => {
export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (
Copy link
Author

Choose a reason for hiding this comment

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

Didn't touch this, lint was telling me to move it

@@ -114,40 +228,80 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
});
};

export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (
export const setSubscriptionNotifications = (notifications: SubscriptionNotifications) => (
Copy link
Author

Choose a reason for hiding this comment

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

Same here, just re-ordering

}
};

export const doCheckSubscriptions = () => (
Copy link
Author

Choose a reason for hiding this comment

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

also this, just moved it

@neb-b neb-b removed the request for review from liamcardenas May 7, 2018 04:55
@lyoshenka lyoshenka added this to the May 14 (app) milestone May 7, 2018
@lbry-bot lbry-bot assigned neb-b and unassigned neb-b May 8, 2018
@neb-b neb-b force-pushed the internal-subscriptions branch 4 times, most recently from 22c8a8f to 87026c8 Compare May 10, 2018 16:18
@neb-b neb-b requested a review from kauffj May 10, 2018 16:19
@lbry-bot lbry-bot assigned kauffj and unassigned neb-b May 10, 2018
@neb-b
Copy link
Author

neb-b commented May 10, 2018

@kauffj ready for more feedback

Copy link
Member

@kauffj kauffj left a comment

Choose a reason for hiding this comment

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

Looks very close.

@@ -166,6 +166,9 @@ export const SET_SUBSCRIPTION_NOTIFICATIONS = 'SET_SUBSCRIPTION_NOTIFICATIONS';
export const CHECK_SUBSCRIPTION_STARTED = 'CHECK_SUBSCRIPTION_STARTED';
export const CHECK_SUBSCRIPTION_COMPLETED = 'CHECK_SUBSCRIPTION_COMPLETED';
export const CHECK_SUBSCRIPTIONS_SUBSCRIBE = 'CHECK_SUBSCRIPTIONS_SUBSCRIBE';
export const FETCH_MY_SUBSCRIPTIONS_START = 'FETCH_MY_SUBSCRIPTIONS_START';
Copy link
Member

Choose a reason for hiding this comment

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

@seanyesmunt this is fine for now. My suggestion for that case would be to de-couple noticing new subscriptions from downloading or to add an auto-download setting that can default to a different value for desktop vs. mobile.

(@akinwale )

@@ -11,4 +11,6 @@ export const INSTANT_PURCHASE_ENABLED = 'instantPurchaseEnabled';
export const INSTANT_PURCHASE_MAX = 'instantPurchaseMax';
export const THEME = 'theme';
export const THEMES = 'themes';
export const DARK_THEME = 'dark';
export const LIGHT_THEME = 'light';
Copy link
Member

Choose a reason for hiding this comment

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

Currently these values are setting keys not setting values. It's a good idea to const these theme values, but we ought to do this in a way that retains that distinction.

type: ACTIONS.CHANNEL_SUBSCRIBE,
data: subscription,
});
const getClaimId = uri => {
Copy link
Member

Choose a reason for hiding this comment

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

Use parseURI?


// Actual claim type has more values than this
// Add them as they are used
export type Claim = {
Copy link
Member

Choose a reason for hiding this comment

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

Should Subscription also be a standalone type file like Claim?

Copy link
Author

Choose a reason for hiding this comment

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

Yes

storedSubscriptions.forEach(sub => {
if (!reduxSubMap[sub.claim_id]) {
const uri = `lbry://${sub.channel_name}#${sub.claim_id}`;
subscriptionsToReturn.push({ uri, channelName: sub.channel_name });
Copy link
Member

Choose a reason for hiding this comment

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

I'm mildly surprised this works. If subscriptionsToReturn is an array of Subscription, doesn't this need to include the latest property?

Copy link
Author

Choose a reason for hiding this comment

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

latest isn't required. It will populate it in doCheckSubscriptions. We are just adding them to redux, which is where it looks when it's checking for the latest.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fairly sure this is my misunderstanding, but I still don't understand why Flow type checking wouldn't be forcing storedSubscriptions to be Array<Subscription> and thus require the latest property.

(Going to merge anyway, but if you know the answer would appreciate the education :) )

@@ -166,6 +176,9 @@ export const SET_SUBSCRIPTION_NOTIFICATIONS = 'SET_SUBSCRIPTION_NOTIFICATIONS';
export const CHECK_SUBSCRIPTION_STARTED = 'CHECK_SUBSCRIPTION_STARTED';
export const CHECK_SUBSCRIPTION_COMPLETED = 'CHECK_SUBSCRIPTION_COMPLETED';
export const CHECK_SUBSCRIPTIONS_SUBSCRIBE = 'CHECK_SUBSCRIPTIONS_SUBSCRIBE';
export const FETCH_MY_SUBSCRIPTIONS_START = 'FETCH_MY_SUBSCRIPTIONS_START';
export const FETCH_MY_SUBSCRIPTIONS_FAIL = 'FETCH_MY_SUBSCRIPTIONS_FAIL';
export const FETCH_MY_SUBSCRIPTIONS_SUCCESS = 'FETCH_MY_SUBSCRIPTIONS_SUCCESS';
Copy link
Member

Choose a reason for hiding this comment

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

Can we drop MY from these? Or let me know what additional clarity it is providing if you think it should remain.


// There is some mismatch between redux state and db state
// If something is in the db, but not in redux, add it to redux
// If something is in redux, but not in the db, add it to the db
Copy link
Member

Choose a reason for hiding this comment

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

I think this is the most reasonable choice and that we can't (or shouldn't) do anything differently immediately, but I also think it's guaranteed that this will cause a bug or confusion in the future.

@lbry-bot lbry-bot assigned neb-b and unassigned kauffj and neb-b May 10, 2018
@neb-b neb-b requested a review from kauffj May 10, 2018 17:03
@lbry-bot lbry-bot assigned kauffj and unassigned kauffj May 10, 2018
update subscription types

update changelog

Simplify subscriptions sync logic

add claim type

use let over const

change spinner color based on theme

clean up subscriptions
@kauffj kauffj merged commit 492b160 into master May 15, 2018
@neb-b neb-b deleted the internal-subscriptions branch May 23, 2018 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants