From 9994c9ba24db12e62f0a34212c29dedac1ddc2aa Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sat, 27 Apr 2019 19:57:03 +0100 Subject: [PATCH 1/2] replace claim_list_by_channel with claim_search --- dist/bundle.es.js | 16 ++-- dist/bundle.js | 26 +++--- src/redux/actions/subscriptions.js | 143 ++++++++++++++--------------- 3 files changed, 93 insertions(+), 92 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 7fc5a4a..3aed434 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1544,18 +1544,20 @@ const doCheckSubscription = (subscriptionUri, shouldNotify) => (dispatch, getSta if (!savedSubscription) { throw Error(`Trying to find new content for ${subscriptionUri} but it doesn't exist in your subscriptions`); - } // We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel? + } + const { + claimId + } = lbryRedux.parseURI(subscriptionUri); // We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel? - lbryRedux.Lbry.claim_list_by_channel({ - uri: subscriptionUri, + lbryRedux.Lbry.claim_search({ + channel_id: claimId, page: 1, page_size: PAGE_SIZE - }).then(claimListByChannel => { - const claimResult = claimListByChannel[subscriptionUri] || {}; + }).then(result => { const { - claims_in_channel: claimsInChannel - } = claimResult; // may happen if subscribed to an abandoned channel or an empty channel + items: claimsInChannel + } = result; // may happen if subscribed to an abandoned channel or an empty channel if (!claimsInChannel || !claimsInChannel.length) { return; diff --git a/dist/bundle.js b/dist/bundle.js index 20cdfac..d80f300 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -2527,16 +2527,18 @@ var doCheckSubscription = function doCheckSubscription(subscriptionUri, shouldNo if (!savedSubscription) { throw Error("Trying to find new content for ".concat(subscriptionUri, " but it doesn't exist in your subscriptions")); - } // We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel? + } + + var _parseURI = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscriptionUri), + claimId = _parseURI.claimId; // We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel? - lbry_redux__WEBPACK_IMPORTED_MODULE_3__["Lbry"].claim_list_by_channel({ - uri: subscriptionUri, + lbry_redux__WEBPACK_IMPORTED_MODULE_3__["Lbry"].claim_search({ + channel_id: claimId, page: 1, page_size: constants_claim__WEBPACK_IMPORTED_MODULE_0__["PAGE_SIZE"] - }).then(function (claimListByChannel) { - var claimResult = claimListByChannel[subscriptionUri] || {}; - var claimsInChannel = claimResult.claims_in_channel; // may happen if subscribed to an abandoned channel or an empty channel + }).then(function (result) { + var claimsInChannel = result.items; // may happen if subscribed to an abandoned channel or an empty channel if (!claimsInChannel || !claimsInChannel.length) { return; @@ -2617,8 +2619,8 @@ var doChannelSubscribe = function doChannelSubscribe(subscription) { }); // if the user isn't sharing data, keep the subscriptions entirely in the app if (isSharingData) { - var _parseURI = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscription.uri), - claimId = _parseURI.claimId; // They are sharing data, we can store their subscriptions in our internal database + var _parseURI2 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscription.uri), + claimId = _parseURI2.claimId; // They are sharing data, we can store their subscriptions in our internal database lbryio__WEBPACK_IMPORTED_MODULE_6__["default"].call('subscription', 'new', { @@ -2645,8 +2647,8 @@ var doChannelUnsubscribe = function doChannelUnsubscribe(subscription) { }); if (isSharingData) { - var _parseURI2 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscription.uri), - claimId = _parseURI2.claimId; + var _parseURI3 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscription.uri), + claimId = _parseURI3.claimId; lbryio__WEBPACK_IMPORTED_MODULE_6__["default"].call('subscription', 'delete', { claim_id: claimId @@ -2699,8 +2701,8 @@ var doFetchMySubscriptions = function doFetchMySubscriptions() { dbSubMap[sub.claim_id] = 1; }); reduxSubscriptions.forEach(function (sub) { - var _parseURI3 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(sub.uri), - claimId = _parseURI3.claimId; + var _parseURI4 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(sub.uri), + claimId = _parseURI4.claimId; reduxSubMap[claimId] = 1; diff --git a/src/redux/actions/subscriptions.js b/src/redux/actions/subscriptions.js index c32e1f2..dd924ac 100644 --- a/src/redux/actions/subscriptions.js +++ b/src/redux/actions/subscriptions.js @@ -156,92 +156,89 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool ); } + const { claimId } = parseURI(subscriptionUri); + // We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel? - Lbry.claim_list_by_channel({ uri: subscriptionUri, page: 1, page_size: PAGE_SIZE }).then( - claimListByChannel => { - const claimResult = claimListByChannel[subscriptionUri] || {}; - const { claims_in_channel: claimsInChannel } = claimResult; + Lbry.claim_search({ channel_id: claimId, page: 1, page_size: PAGE_SIZE }).then(result => { + const { items: claimsInChannel } = result; - // may happen if subscribed to an abandoned channel or an empty channel - if (!claimsInChannel || !claimsInChannel.length) { - return; - } + // may happen if subscribed to an abandoned channel or an empty channel + if (!claimsInChannel || !claimsInChannel.length) { + return; + } - // Determine if the latest subscription currently saved is actually the latest subscription - const latestIndex = claimsInChannel.findIndex( - claim => `${claim.name}#${claim.claim_id}` === savedSubscription.latest - ); + // Determine if the latest subscription currently saved is actually the latest subscription + const latestIndex = claimsInChannel.findIndex( + claim => `${claim.name}#${claim.claim_id}` === savedSubscription.latest + ); - // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed - const latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; + // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed + const latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; - // If latest is 0, nothing has changed - // Do not download/notify about new content, it would download/notify 10 claims per channel - if (latestIndex !== 0 && savedSubscription.latest) { - let downloadCount = 0; + // If latest is 0, nothing has changed + // Do not download/notify about new content, it would download/notify 10 claims per channel + if (latestIndex !== 0 && savedSubscription.latest) { + let downloadCount = 0; - const newUnread = []; - claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => { - const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, true); - const shouldDownload = - shouldAutoDownload && - Boolean( - downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee - ); + const newUnread = []; + claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => { + const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, true); + const shouldDownload = + shouldAutoDownload && + Boolean(downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee); - // Add the new content to the list of "un-read" subscriptions - if (shouldNotify) { - newUnread.push(uri); - } + // Add the new content to the list of "un-read" subscriptions + if (shouldNotify) { + newUnread.push(uri); + } - if (shouldDownload) { - downloadCount += 1; - dispatch(doPurchaseUri(uri, { cost: 0 }, true)); - } - }); + if (shouldDownload) { + downloadCount += 1; + dispatch(doPurchaseUri(uri, { cost: 0 }, true)); + } + }); - dispatch( - doUpdateUnreadSubscriptions( - subscriptionUri, - newUnread, - downloadCount > 0 ? NOTIFICATION_TYPES.DOWNLOADING : NOTIFICATION_TYPES.NOTIFY_ONLY - ) - ); - } - - // Set the latest piece of content for a channel - // This allows the app to know if there has been new content since it was last set dispatch( - setSubscriptionLatest( - { - channelName: claimsInChannel[0].channel_name, - uri: buildURI( - { - channelName: claimsInChannel[0].channel_name, - claimId: claimsInChannel[0].claim_id, - }, - false - ), - }, - buildURI( - { contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id }, - false - ) + doUpdateUnreadSubscriptions( + subscriptionUri, + newUnread, + downloadCount > 0 ? NOTIFICATION_TYPES.DOWNLOADING : NOTIFICATION_TYPES.NOTIFY_ONLY ) ); - - // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED - // means it will delete a non-existant fetchingChannelClaims[uri] - dispatch({ - type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED, - data: { - uri: subscriptionUri, - claims: claimsInChannel || [], - page: 1, - }, - }); } - ); + + // Set the latest piece of content for a channel + // This allows the app to know if there has been new content since it was last set + dispatch( + setSubscriptionLatest( + { + channelName: claimsInChannel[0].channel_name, + uri: buildURI( + { + channelName: claimsInChannel[0].channel_name, + claimId: claimsInChannel[0].claim_id, + }, + false + ), + }, + buildURI( + { contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id }, + false + ) + ) + ); + + // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED + // means it will delete a non-existant fetchingChannelClaims[uri] + dispatch({ + type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED, + data: { + uri: subscriptionUri, + claims: claimsInChannel || [], + page: 1, + }, + }); + }); }; export const doChannelSubscribe = (subscription: Subscription) => ( From bec7ce1fba7fb0d90f604170ee00c75b3d8ab7ed Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sat, 27 Apr 2019 20:34:17 +0100 Subject: [PATCH 2/2] update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6db439d..8de3d26 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "reselect": "^3.0.0" }, "peerDependencies": { - "lbry-redux": "lbryio/lbry-redux#sync" + "lbry-redux": "lbryio/lbry-redux" }, "devDependencies": { "@babel/core": "^7.4.3",