Subscribe notify #1066

Merged
liamcardenas merged 9 commits from subscribe-notify into master 2018-03-08 06:13:26 +01:00
3 changed files with 33 additions and 6 deletions
Showing only changes of commit 1e1c494367 - Show all commits

View file

@ -40,7 +40,13 @@ class FilePage extends React.PureComponent {
props.checkSubscriptionLatest( props.checkSubscriptionLatest(
{ {
channelName: props.claim.channel_name, channelName: props.claim.channel_name,
uri: buildURI({ contentName: props.claim.channel_name, claimId: props.claim.value.publisherSignature.certificateId }, false), uri: buildURI(
{
contentName: props.claim.channel_name,
claimId: props.claim.value.publisherSignature.certificateId,
},
false
),
}, },
buildURI({ contentName: props.claim.name, claimId: props.claim.claim_id }, false) buildURI({ contentName: props.claim.name, claimId: props.claim.claim_id }, false)
); );

View file

@ -365,7 +365,13 @@ export function doFetchClaimsByChannel(uri, page) {
setSubscriptionLatest( setSubscriptionLatest(
{ {
channelName: latest.channel_name, channelName: latest.channel_name,
uri: buildURI({ contentName: latest.channel_name, claimId: latest.value.publisherSignature.certificateId }, false), uri: buildURI(
{
contentName: latest.channel_name,
claimId: latest.value.publisherSignature.certificateId,
},
false
),
}, },
buildURI({ contentName: latest.name, claimId: latest.claim_id }, false) buildURI({ contentName: latest.name, claimId: latest.claim_id }, false)
) )

View file

@ -51,7 +51,10 @@ export const doCheckSubscription = (subscription: Subscription) => (dispatch: Di
let count = subscription.latest let count = subscription.latest
? claimsInChannel.reduce( ? claimsInChannel.reduce(
(prev, cur, index) => (prev, cur, index) =>
buildURI({ contentName: cur.name, claimId: cur.claim_id}, false) === subscription.latest ? index : prev, buildURI({ contentName: cur.name, claimId: cur.claim_id }, false) ===
subscription.latest
? index
: prev,
-1 -1
) )
: 1; : 1;
@ -59,7 +62,13 @@ export const doCheckSubscription = (subscription: Subscription) => (dispatch: Di
if (count !== 0) { if (count !== 0) {
if (!claimsInChannel[0].value.stream.metadata.fee) { if (!claimsInChannel[0].value.stream.metadata.fee) {
dispatch( dispatch(
doPurchaseUri(buildURI({ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id }, false), { cost: 0 }) doPurchaseUri(
buildURI(
{ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id },
false
),
{ cost: 0 }
)
); );
} }
@ -72,7 +81,10 @@ export const doCheckSubscription = (subscription: Subscription) => (dispatch: Di
notif.onclick = () => { notif.onclick = () => {
dispatch( dispatch(
doNavigate('/show', { doNavigate('/show', {
uri: buildURI({ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id }, true), uri: buildURI(
{ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id },
true
),
}) })
); );
}; };
@ -96,7 +108,10 @@ export const checkSubscriptionLatest = (channel: Subscription, uri: string) => (
if ( if (
claimsInChannel && claimsInChannel &&
claimsInChannel.length && claimsInChannel.length &&
buildURI({ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id }, false) === uri buildURI(
{ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id },
false
) === uri
) { ) {
dispatch(setSubscriptionLatest(channel, uri)); dispatch(setSubscriptionLatest(channel, uri));
kauffj commented 2018-03-06 21:53:36 +01:00 (Migrated from github.com)
Review

Is this function actually necessary? Could doCheckSubscription just call setSubscriptionLatest?

Is this function actually necessary? Could `doCheckSubscription` just call `setSubscriptionLatest`?
liamcardenas commented 2018-03-07 20:34:27 +01:00 (Migrated from github.com)
Review

check and set are different, set simply sets the value in the redux store. Check does an asynchronous call and sets the value accordingly by dispatching set, if that makes sense.

check and set are different, set simply sets the value in the redux store. Check does an asynchronous call and sets the value accordingly by dispatching set, if that makes sense.
kauffj commented 2018-03-07 22:58:38 +01:00 (Migrated from github.com)
Review

I'm asking two things in my question:

  1. If we're already fetching the latest subscription data at time interval n, is it actually necessary to check for the latest for this same information when accessing a file page?
  2. If it is necessary (for staleness reasons, presumably), why can't more of the code be shared between the two? Isn't doCheckSubscription a superset of the functionality provided by checkSubscriptionLatest? and why wouldn't you want checkSubscriptionLatest to also begin downloads? Furthermore, why do both of these call Lbry.claim_list_by_channel when they could call doFetchClaimsByChannel instead?
I'm asking two things in my question: 1) If we're already fetching the latest subscription data at time interval `n`, is it actually necessary to check for the latest for this same information when accessing a file page? 2) If it is necessary (for staleness reasons, presumably), why can't more of the code be shared between the two? Isn't `doCheckSubscription` a superset of the functionality provided by `checkSubscriptionLatest`? and why wouldn't you want `checkSubscriptionLatest` to also begin downloads? Furthermore, why do _both_ of these call `Lbry.claim_list_by_channel` when they could call `doFetchClaimsByChannel` instead?
kauffj commented 2018-03-09 00:04:47 +01:00 (Migrated from github.com)
Review

@liamcardenas did you see above?

@liamcardenas did you see above?
} }