fix: canonical url stuff

This commit is contained in:
Thomas Zarebczan 2019-08-29 12:58:30 -04:00
parent 396e8fff4f
commit 35ca4fbc3d
3 changed files with 53 additions and 101 deletions

51
dist/bundle.es.js vendored
View file

@ -1566,21 +1566,21 @@ const doCheckSubscription = (subscriptionUri, shouldNotify) => (dispatch, getSta
lbryRedux.Lbry.claim_search({ lbryRedux.Lbry.claim_search({
channel: subscriptionUri, channel: subscriptionUri,
page: 1,
page_size: PAGE_SIZE,
valid_channel_signature: true, valid_channel_signature: true,
order_by: ['release_time'] order_by: ['release_time'],
}).then(result => { page: 1,
page_size: PAGE_SIZE
}).then(claimListByChannel => {
const { const {
items: claimsInChannel items: claimsInChannel
} = result; // may happen if subscribed to an abandoned channel or an empty channel } = claimListByChannel; // may happen if subscribed to an abandoned channel or an empty channel
if (!claimsInChannel || !claimsInChannel.length) { if (!claimsInChannel || !claimsInChannel.length) {
return; return;
} // Determine if the latest subscription currently saved is actually the latest subscription } // 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 latestIndex = claimsInChannel.findIndex(claim => claim.permanent_url === 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 0, nothing has changed 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 // Do not download/notify about new content, it would download/notify 10 claims per channel
@ -1589,10 +1589,7 @@ const doCheckSubscription = (subscriptionUri, shouldNotify) => (dispatch, getSta
let downloadCount = 0; let downloadCount = 0;
const newUnread = []; const newUnread = [];
claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => { claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => {
const uri = lbryRedux.buildURI({ const uri = claim.permanent_url;
claimName: claim.name,
claimId: claim.claim_id
}, true);
if (shouldNotify) { if (shouldNotify) {
newUnread.push(uri); newUnread.push(uri);
@ -1603,18 +1600,11 @@ const doCheckSubscription = (subscriptionUri, shouldNotify) => (dispatch, getSta
// This allows the app to know if there has been new content since it was last set // This allows the app to know if there has been new content since it was last set
const latestClaim = claimsInChannel[0]; const latest = claimsInChannel[0];
const latestClaimChannel = latestClaim.signing_channel.name;
dispatch(setSubscriptionLatest({ dispatch(setSubscriptionLatest({
channelName: latestClaimChannel, channelName: latest.signing_channel.name,
uri: lbryRedux.buildURI({ uri: latest.signing_channel.permanent_url
channelName: latestClaimChannel, }, latest.permanent_url)); // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED
claimId: latestClaim.claim_id
}, false)
}, lbryRedux.buildURI({
claimName: latestClaim.name,
claimId: latestClaim.claim_id
}, false))); // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED
// means it will delete a non-existant fetchingChannelClaims[uri] // means it will delete a non-existant fetchingChannelClaims[uri]
dispatch({ dispatch({
@ -1647,12 +1637,12 @@ const doChannelSubscribe = subscription => (dispatch, getState) => {
if (isSharingData) { if (isSharingData) {
const { const {
claimId channelClaimId
} = lbryRedux.parseURI(subscription.uri); // They are sharing data, we can store their subscriptions in our internal database } = lbryRedux.parseURI(subscription.uri); // They are sharing data, we can store their subscriptions in our internal database
Lbryio.call('subscription', 'new', { Lbryio.call('subscription', 'new', {
channel_name: subscription.channelName, channel_name: subscription.channelName,
claim_id: claimId claim_id: channelClaimId
}); });
dispatch(doClaimRewardType(rewards.TYPE_SUBSCRIPTION, { dispatch(doClaimRewardType(rewards.TYPE_SUBSCRIPTION, {
failSilently: true failSilently: true
@ -1675,10 +1665,10 @@ const doChannelUnsubscribe = subscription => (dispatch, getState) => {
if (isSharingData) { if (isSharingData) {
const { const {
claimId channelClaimId
} = lbryRedux.parseURI(subscription.uri); } = lbryRedux.parseURI(subscription.uri);
Lbryio.call('subscription', 'delete', { Lbryio.call('subscription', 'delete', {
claim_id: claimId claim_id: channelClaimId
}); });
} }
}; };
@ -1727,16 +1717,9 @@ const doFetchMySubscriptions = () => (dispatch, getState) => {
}); });
reduxSubscriptions.forEach(sub => { reduxSubscriptions.forEach(sub => {
const { const {
claimId channelClaimId
} = lbryRedux.parseURI(sub.uri); } = lbryRedux.parseURI(sub.uri);
reduxSubMap[claimId] = 1; reduxSubMap[channelClaimId] = 1;
if (!dbSubMap[claimId]) {
subsNotInDB.push({
claim_id: claimId,
channel_name: sub.channelName
});
}
}); });
storedSubscriptions.forEach(sub => { storedSubscriptions.forEach(sub => {
if (!reduxSubMap[sub.claim_id]) { if (!reduxSubMap[sub.claim_id]) {

53
dist/bundle.js vendored
View file

@ -2575,12 +2575,12 @@ var doCheckSubscription = function doCheckSubscription(subscriptionUri, shouldNo
lbry_redux__WEBPACK_IMPORTED_MODULE_3__["Lbry"].claim_search({ lbry_redux__WEBPACK_IMPORTED_MODULE_3__["Lbry"].claim_search({
channel: subscriptionUri, channel: subscriptionUri,
page: 1,
page_size: constants_claim__WEBPACK_IMPORTED_MODULE_0__["PAGE_SIZE"],
valid_channel_signature: true, valid_channel_signature: true,
order_by: ['release_time'] order_by: ['release_time'],
}).then(function (result) { page: 1,
var claimsInChannel = result.items; // may happen if subscribed to an abandoned channel or an empty channel page_size: constants_claim__WEBPACK_IMPORTED_MODULE_0__["PAGE_SIZE"]
}).then(function (claimListByChannel) {
var claimsInChannel = claimListByChannel.items; // may happen if subscribed to an abandoned channel or an empty channel
if (!claimsInChannel || !claimsInChannel.length) { if (!claimsInChannel || !claimsInChannel.length) {
return; return;
@ -2588,7 +2588,7 @@ var doCheckSubscription = function doCheckSubscription(subscriptionUri, shouldNo
var latestIndex = claimsInChannel.findIndex(function (claim) { var latestIndex = claimsInChannel.findIndex(function (claim) {
return "".concat(claim.name, "#").concat(claim.claim_id) === savedSubscription.latest; return claim.permanent_url === savedSubscription.latest;
}); // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed }); // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed
var latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; // If latest is 0, nothing has changed var latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; // If latest is 0, nothing has changed
@ -2598,11 +2598,8 @@ var doCheckSubscription = function doCheckSubscription(subscriptionUri, shouldNo
var downloadCount = 0; var downloadCount = 0;
var newUnread = []; var newUnread = [];
claimsInChannel.slice(0, latestIndexToNotify).forEach(function (claim) { claimsInChannel.slice(0, latestIndexToNotify).forEach(function (claim) {
var uri = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["buildURI"])({ var uri = claim.permanent_url;
claimName: claim.name, var shouldDownload = shouldAutoDownload && Boolean(downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.fee); // Add the new content to the list of "un-read" subscriptions
claimId: claim.claim_id
}, true);
var 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) { if (shouldNotify) {
newUnread.push(uri); newUnread.push(uri);
@ -2620,18 +2617,11 @@ var doCheckSubscription = function doCheckSubscription(subscriptionUri, shouldNo
// This allows the app to know if there has been new content since it was last set // This allows the app to know if there has been new content since it was last set
var latestClaim = claimsInChannel[0]; var latest = claimsInChannel[0];
var latestClaimChannel = latestClaim.signing_channel.name;
dispatch(setSubscriptionLatest({ dispatch(setSubscriptionLatest({
channelName: latestClaimChannel, channelName: latest.signing_channel.name,
uri: Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["buildURI"])({ uri: latest.signing_channel.permanent_url
channelName: latestClaimChannel, }, latest.permanent_url)); // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED
claimId: latestClaim.claim_id
}, false)
}, Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["buildURI"])({
claimName: latestClaim.name,
claimId: latestClaim.claim_id
}, false))); // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED
// means it will delete a non-existant fetchingChannelClaims[uri] // means it will delete a non-existant fetchingChannelClaims[uri]
dispatch({ dispatch({
@ -2664,12 +2654,12 @@ var doChannelSubscribe = function doChannelSubscribe(subscription) {
if (isSharingData) { if (isSharingData) {
var _parseURI = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscription.uri), 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 channelClaimId = _parseURI.channelClaimId; // They are sharing data, we can store their subscriptions in our internal database
lbryio__WEBPACK_IMPORTED_MODULE_6__["default"].call('subscription', 'new', { lbryio__WEBPACK_IMPORTED_MODULE_6__["default"].call('subscription', 'new', {
channel_name: subscription.channelName, channel_name: subscription.channelName,
claim_id: claimId claim_id: channelClaimId
}); });
dispatch(Object(redux_actions_rewards__WEBPACK_IMPORTED_MODULE_1__["doClaimRewardType"])(rewards__WEBPACK_IMPORTED_MODULE_7__["default"].TYPE_SUBSCRIPTION, { dispatch(Object(redux_actions_rewards__WEBPACK_IMPORTED_MODULE_1__["doClaimRewardType"])(rewards__WEBPACK_IMPORTED_MODULE_7__["default"].TYPE_SUBSCRIPTION, {
failSilently: true failSilently: true
@ -2692,10 +2682,10 @@ var doChannelUnsubscribe = function doChannelUnsubscribe(subscription) {
if (isSharingData) { if (isSharingData) {
var _parseURI2 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscription.uri), var _parseURI2 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(subscription.uri),
claimId = _parseURI2.claimId; channelClaimId = _parseURI2.channelClaimId;
lbryio__WEBPACK_IMPORTED_MODULE_6__["default"].call('subscription', 'delete', { lbryio__WEBPACK_IMPORTED_MODULE_6__["default"].call('subscription', 'delete', {
claim_id: claimId claim_id: channelClaimId
}); });
} }
}; };
@ -2746,16 +2736,9 @@ var doFetchMySubscriptions = function doFetchMySubscriptions() {
}); });
reduxSubscriptions.forEach(function (sub) { reduxSubscriptions.forEach(function (sub) {
var _parseURI3 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(sub.uri), var _parseURI3 = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_3__["parseURI"])(sub.uri),
claimId = _parseURI3.claimId; channelClaimId = _parseURI3.channelClaimId;
reduxSubMap[claimId] = 1; reduxSubMap[channelClaimId] = 1;
if (!dbSubMap[claimId]) {
subsNotInDB.push({
claim_id: claimId,
channel_name: sub.channelName
});
}
}); });
storedSubscriptions.forEach(function (sub) { storedSubscriptions.forEach(function (sub) {
if (!reduxSubMap[sub.claim_id]) { if (!reduxSubMap[sub.claim_id]) {

View file

@ -11,7 +11,7 @@ import type {
import { PAGE_SIZE } from 'constants/claim'; import { PAGE_SIZE } from 'constants/claim';
import { doClaimRewardType } from 'redux/actions/rewards'; import { doClaimRewardType } from 'redux/actions/rewards';
import { selectSubscriptions, selectUnreadByChannel } from 'redux/selectors/subscriptions'; import { selectSubscriptions, selectUnreadByChannel } from 'redux/selectors/subscriptions';
import { Lbry, buildURI, parseURI, doResolveUris, doPurchaseUri } from 'lbry-redux'; import { Lbry, parseURI, doResolveUris, doPurchaseUri } from 'lbry-redux';
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import * as NOTIFICATION_TYPES from 'constants/subscriptions'; import * as NOTIFICATION_TYPES from 'constants/subscriptions';
import Lbryio from 'lbryio'; import Lbryio from 'lbryio';
@ -159,12 +159,12 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
// We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel? // We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel?
Lbry.claim_search({ Lbry.claim_search({
channel: subscriptionUri, channel: subscriptionUri,
page: 1,
page_size: PAGE_SIZE,
valid_channel_signature: true, valid_channel_signature: true,
order_by: ['release_time'], order_by: ['release_time'],
}).then(result => { page: 1,
const { items: claimsInChannel } = result; page_size: PAGE_SIZE,
}).then(claimListByChannel => {
const { items: claimsInChannel } = claimListByChannel;
// may happen if subscribed to an abandoned channel or an empty channel // may happen if subscribed to an abandoned channel or an empty channel
if (!claimsInChannel || !claimsInChannel.length) { if (!claimsInChannel || !claimsInChannel.length) {
@ -173,7 +173,7 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
// Determine if the latest subscription currently saved is actually the latest subscription // Determine if the latest subscription currently saved is actually the latest subscription
const latestIndex = claimsInChannel.findIndex( const latestIndex = claimsInChannel.findIndex(
claim => `${claim.name}#${claim.claim_id}` === savedSubscription.latest claim => claim.permanent_url === savedSubscription.latest
); );
// If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed
@ -186,10 +186,10 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
const newUnread = []; const newUnread = [];
claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => { claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => {
const uri = buildURI({ claimName: claim.name, claimId: claim.claim_id }, true); const uri = claim.permanent_url;
const shouldDownload = const shouldDownload =
shouldAutoDownload && shouldAutoDownload &&
Boolean(downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee); Boolean(downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.fee);
// Add the new content to the list of "un-read" subscriptions // Add the new content to the list of "un-read" subscriptions
if (shouldNotify) { if (shouldNotify) {
@ -213,21 +213,14 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
// Set the latest piece of content for a channel // 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 // This allows the app to know if there has been new content since it was last set
const latestClaim = claimsInChannel[0]; const latest = claimsInChannel[0];
const latestClaimChannel = latestClaim.signing_channel.name;
dispatch( dispatch(
setSubscriptionLatest( setSubscriptionLatest(
{ {
channelName: latestClaimChannel, channelName: latest.signing_channel.name,
uri: buildURI( uri: latest.signing_channel.permanent_url,
{
channelName: latestClaimChannel,
claimId: latestClaim.claim_id,
},
false
),
}, },
buildURI({ claimName: latestClaim.name, claimId: latestClaim.claim_id }, false) latest.permanent_url
) )
); );
@ -268,11 +261,11 @@ export const doChannelSubscribe = (subscription: Subscription) => (
// if the user isn't sharing data, keep the subscriptions entirely in the app // if the user isn't sharing data, keep the subscriptions entirely in the app
if (isSharingData) { if (isSharingData) {
const { claimId } = parseURI(subscription.uri); const { channelClaimId } = parseURI(subscription.uri);
// They are sharing data, we can store their subscriptions in our internal database // They are sharing data, we can store their subscriptions in our internal database
Lbryio.call('subscription', 'new', { Lbryio.call('subscription', 'new', {
channel_name: subscription.channelName, channel_name: subscription.channelName,
claim_id: claimId, claim_id: channelClaimId,
}); });
dispatch(doClaimRewardType(rewards.TYPE_SUBSCRIPTION, { failSilently: true })); dispatch(doClaimRewardType(rewards.TYPE_SUBSCRIPTION, { failSilently: true }));
@ -296,9 +289,9 @@ export const doChannelUnsubscribe = (subscription: Subscription) => (
}); });
if (isSharingData) { if (isSharingData) {
const { claimId } = parseURI(subscription.uri); const { channelClaimId } = parseURI(subscription.uri);
Lbryio.call('subscription', 'delete', { Lbryio.call('subscription', 'delete', {
claim_id: claimId, claim_id: channelClaimId,
}); });
} }
}; };
@ -354,15 +347,8 @@ export const doFetchMySubscriptions = () => (dispatch: ReduxDispatch, getState:
}); });
reduxSubscriptions.forEach(sub => { reduxSubscriptions.forEach(sub => {
const { claimId } = parseURI(sub.uri); const { channelClaimId } = parseURI(sub.uri);
reduxSubMap[claimId] = 1; reduxSubMap[channelClaimId] = 1;
if (!dbSubMap[claimId]) {
subsNotInDB.push({
claim_id: claimId,
channel_name: sub.channelName,
});
}
}); });
storedSubscriptions.forEach(sub => { storedSubscriptions.forEach(sub => {