fix: claim search params
This commit is contained in:
parent
60543562aa
commit
7baa73aff9
2 changed files with 77 additions and 67 deletions
|
@ -292,7 +292,13 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1, pageSize:
|
|||
data: { uri, page },
|
||||
});
|
||||
|
||||
Lbry.claim_search({ channel: uri, is_controlling: true, page, page_size: pageSize }).then(result => {
|
||||
Lbry.claim_search({
|
||||
channel: uri,
|
||||
page,
|
||||
page_size: pageSize,
|
||||
valid_channel_signatures: true,
|
||||
order_by: ['release_time'],
|
||||
}).then(result => {
|
||||
const { items: claimsInChannel, page: returnedPage } = result;
|
||||
|
||||
if (claimsInChannel && claimsInChannel.length) {
|
||||
|
|
|
@ -204,84 +204,88 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
|
|||
}
|
||||
|
||||
// We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel?
|
||||
Lbry.claim_search({ channel: subscriptionUri, is_controlling: true, page: 1, page_size: PAGE_SIZE }).then(
|
||||
claimListByChannel => {
|
||||
const { items: claimsInChannel } = claimListByChannel;
|
||||
Lbry.claim_search({
|
||||
channel: subscriptionUri,
|
||||
valid_channel_signatures: true,
|
||||
order_by: ['release_time'],
|
||||
page: 1,
|
||||
page_size: PAGE_SIZE,
|
||||
}).then(claimListByChannel => {
|
||||
const { items: claimsInChannel } = claimListByChannel;
|
||||
|
||||
// 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.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.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) => (dispatch: Dispatch, getState: GetState) => {
|
||||
|
|
Loading…
Reference in a new issue