doCheckSubs only takes uri; do not clear notifications on doFetchClaimsByChan; doFetchMySubs on startup; always set latest on checkSub; do not download or notify when latest is undefined
This commit is contained in:
parent
6b375965f9
commit
5e270c129c
6 changed files with 72 additions and 65 deletions
|
@ -25,10 +25,7 @@ type Props = {
|
||||||
const SideBar = (props: Props) => {
|
const SideBar = (props: Props) => {
|
||||||
const { navLinks, notifications } = props;
|
const { navLinks, notifications } = props;
|
||||||
|
|
||||||
const badges = Object.keys(notifications).reduce(
|
const badges = Object.keys(notifications).length;
|
||||||
(acc, cur) => (notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING ? acc : acc + 1),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className="nav">
|
<nav className="nav">
|
||||||
|
|
|
@ -40,7 +40,7 @@ const perform = dispatch => ({
|
||||||
navigate: (path, params) => dispatch(doNavigate(path, params)),
|
navigate: (path, params) => dispatch(doNavigate(path, params)),
|
||||||
fetchFileInfo: uri => dispatch(doFetchFileInfo(uri)),
|
fetchFileInfo: uri => dispatch(doFetchFileInfo(uri)),
|
||||||
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
|
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
|
||||||
checkSubscription: subscription => dispatch(doCheckSubscription(subscription)),
|
checkSubscription: uri => dispatch(doCheckSubscription(uri)),
|
||||||
openModal: (modal, props) => dispatch(doNotify(modal, props)),
|
openModal: (modal, props) => dispatch(doNotify(modal, props)),
|
||||||
prepareEdit: (publishData, uri) => dispatch(doPrepareEdit(publishData, uri)),
|
prepareEdit: (publishData, uri) => dispatch(doPrepareEdit(publishData, uri)),
|
||||||
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
||||||
|
|
|
@ -44,7 +44,7 @@ type Props = {
|
||||||
fetchFileInfo: string => void,
|
fetchFileInfo: string => void,
|
||||||
fetchCostInfo: string => void,
|
fetchCostInfo: string => void,
|
||||||
prepareEdit: ({}, string) => void,
|
prepareEdit: ({}, string) => void,
|
||||||
checkSubscription: ({ channelName: string, uri: string }) => void,
|
checkSubscription: (uri: string) => void,
|
||||||
subscriptions: Array<Subscription>,
|
subscriptions: Array<Subscription>,
|
||||||
setClientSetting: (string, boolean | string) => void,
|
setClientSetting: (string, boolean | string) => void,
|
||||||
autoplay: boolean,
|
autoplay: boolean,
|
||||||
|
@ -96,16 +96,12 @@ class FilePage extends React.Component<Props> {
|
||||||
|
|
||||||
checkSubscription = (props: Props) => {
|
checkSubscription = (props: Props) => {
|
||||||
if (props.subscriptions.find(sub => sub.channelName === props.claim.channel_name)) {
|
if (props.subscriptions.find(sub => sub.channelName === props.claim.channel_name)) {
|
||||||
props.checkSubscription({
|
props.checkSubscription(
|
||||||
channelName: props.claim.channel_name,
|
buildURI({
|
||||||
uri: buildURI(
|
|
||||||
{
|
|
||||||
contentName: props.claim.channel_name,
|
contentName: props.claim.channel_name,
|
||||||
claimId: props.claim.value.publisherSignature.certificateId,
|
claimId: props.claim.value.publisherSignature.certificateId,
|
||||||
},
|
}, false)
|
||||||
false
|
);
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ export default class extends React.PureComponent<Props> {
|
||||||
const { notifications, setSubscriptionNotifications, doFetchMySubscriptions } = this.props;
|
const { notifications, setSubscriptionNotifications, doFetchMySubscriptions } = this.props;
|
||||||
doFetchMySubscriptions();
|
doFetchMySubscriptions();
|
||||||
|
|
||||||
|
// @sean will change this behavior when implementing new content labeling
|
||||||
|
// notifications should be cleared individually
|
||||||
|
// do we want a way to clear individual claims without viewing?
|
||||||
const newNotifications = {};
|
const newNotifications = {};
|
||||||
Object.keys(notifications).forEach(cur => {
|
Object.keys(notifications).forEach(cur => {
|
||||||
if (notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING) {
|
if (notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING) {
|
||||||
|
|
|
@ -379,17 +379,18 @@ export function doFetchClaimsByChannel(uri, page) {
|
||||||
buildURI({ contentName: latest.name, claimId: latest.claim_id }, false)
|
buildURI({ contentName: latest.name, claimId: latest.claim_id }, false)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const notifications = selectNotifications(getState());
|
// commented out as a note for @sean, notification will be clared individually
|
||||||
const newNotifications = {};
|
// const notifications = selectNotifications(getState());
|
||||||
Object.keys(notifications).forEach(cur => {
|
// const newNotifications = {};
|
||||||
if (
|
// Object.keys(notifications).forEach(cur => {
|
||||||
notifications[cur].subscription.channelName !== latest.channel_name ||
|
// if (
|
||||||
notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING
|
// notifications[cur].subscription.channelName !== latest.channel_name ||
|
||||||
) {
|
// notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING
|
||||||
newNotifications[cur] = { ...notifications[cur] };
|
// ) {
|
||||||
}
|
// newNotifications[cur] = { ...notifications[cur] };
|
||||||
});
|
// }
|
||||||
dispatch(setSubscriptionNotifications(newNotifications));
|
// });
|
||||||
|
// dispatch(setSubscriptionNotifications(newNotifications));
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|
|
@ -124,25 +124,31 @@ export const setSubscriptionNotification = (
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => (
|
export const doCheckSubscription = (subscriptionUri: string, notify?: boolean) => (
|
||||||
dispatch: Dispatch,
|
dispatch: Dispatch,
|
||||||
getState: () => {}
|
getState: () => {}
|
||||||
) => {
|
) => {
|
||||||
// no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on <SubscriptionsPage>
|
// no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on <SubscriptionsPage>
|
||||||
|
|
||||||
Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => {
|
const state = getState();
|
||||||
const claimResult = result[subscription.uri] || {};
|
const savedSubscription = state.subscriptions.subscriptions.find(sub => sub.uri === subscriptionUri);
|
||||||
|
|
||||||
|
Lbry.claim_list_by_channel({ uri: subscriptionUri, page: 1 }).then(result => {
|
||||||
|
const claimResult = result[subscriptionUri] || {};
|
||||||
const { claims_in_channel: claimsInChannel } = claimResult;
|
const { claims_in_channel: claimsInChannel } = claimResult;
|
||||||
|
|
||||||
const latestIndex = claimsInChannel.findIndex(
|
const latestIndex = claimsInChannel.findIndex(
|
||||||
claim => `${claim.name}#${claim.claim_id}` === subscription.latest
|
claim => `${claim.name}#${claim.claim_id}` === savedSubscription.latest
|
||||||
);
|
);
|
||||||
|
|
||||||
if (claimsInChannel.length && latestIndex !== 0) {
|
// if latest is 0, nothing has changed
|
||||||
|
// when there is no subscription latest, it is either a newly subscriubed channel or
|
||||||
|
// the user has cleared their cache. Either way, do not download or notify about new content
|
||||||
|
// as that would download/notify 10 claims per channel
|
||||||
|
if (claimsInChannel.length && latestIndex !== 0 && savedSubscription.latest) {
|
||||||
let downloadCount = 0;
|
let downloadCount = 0;
|
||||||
claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach(claim => {
|
claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach(claim => {
|
||||||
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false);
|
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false);
|
||||||
const state = getState();
|
|
||||||
const shouldDownload = Boolean(
|
const shouldDownload = Boolean(
|
||||||
downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT &&
|
downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT &&
|
||||||
!claim.value.stream.metadata.fee &&
|
!claim.value.stream.metadata.fee &&
|
||||||
|
@ -151,7 +157,7 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
|
||||||
if (notify) {
|
if (notify) {
|
||||||
dispatch(
|
dispatch(
|
||||||
setSubscriptionNotification(
|
setSubscriptionNotification(
|
||||||
subscription,
|
savedSubscription,
|
||||||
uri,
|
uri,
|
||||||
shouldDownload ? NOTIFICATION_TYPES.DOWNLOADING : NOTIFICATION_TYPES.NOTIFY_ONLY
|
shouldDownload ? NOTIFICATION_TYPES.DOWNLOADING : NOTIFICATION_TYPES.NOTIFY_ONLY
|
||||||
)
|
)
|
||||||
|
@ -163,6 +169,9 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// always setLatest; important for newly subscribed channels
|
||||||
dispatch(
|
dispatch(
|
||||||
setSubscriptionLatest(
|
setSubscriptionLatest(
|
||||||
{
|
{
|
||||||
|
@ -187,12 +196,11 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
|
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
|
||||||
data: {
|
data: {
|
||||||
uri: subscription.uri,
|
uri: subscriptionUri,
|
||||||
claims: claimsInChannel || [],
|
claims: claimsInChannel || [],
|
||||||
page: 1,
|
page: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -232,6 +240,7 @@ export const doChannelSubscribe = (subscription: Subscription) => (
|
||||||
dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true }));
|
dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// should be subUri
|
||||||
dispatch(doCheckSubscription(subscription, true));
|
dispatch(doCheckSubscription(subscription, true));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -269,10 +278,11 @@ export const doCheckSubscriptionsInit = () => (dispatch: Dispatch) => {
|
||||||
// doCheckSubscriptionsInit is called by doDaemonReady
|
// doCheckSubscriptionsInit is called by doDaemonReady
|
||||||
// setTimeout below is a hack to ensure redux is hydrated when subscriptions are checked
|
// setTimeout below is a hack to ensure redux is hydrated when subscriptions are checked
|
||||||
// this will be replaced with <PersistGate> which reqiures a package upgrade
|
// this will be replaced with <PersistGate> which reqiures a package upgrade
|
||||||
setTimeout(() => dispatch(doCheckSubscriptions()), 5000);
|
setTimeout(() => dispatch(doFetchMySubscriptions()), 5000);
|
||||||
|
setTimeout(() => dispatch(doCheckSubscriptions()), 10000);
|
||||||
const checkSubscriptionsTimer = setInterval(
|
const checkSubscriptionsTimer = setInterval(
|
||||||
() => dispatch(doCheckSubscriptions()),
|
() => dispatch(doCheckSubscriptions()),
|
||||||
CHECK_SUBSCRIPTIONS_INTERVAL
|
20000//CHECK_SUBSCRIPTIONS_INTERVAL
|
||||||
);
|
);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
||||||
|
|
Loading…
Reference in a new issue