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 { navLinks, notifications } = props;
|
||||
|
||||
const badges = Object.keys(notifications).reduce(
|
||||
(acc, cur) => (notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING ? acc : acc + 1),
|
||||
0
|
||||
);
|
||||
const badges = Object.keys(notifications).length;
|
||||
|
||||
return (
|
||||
<nav className="nav">
|
||||
|
|
|
@ -40,7 +40,7 @@ const perform = dispatch => ({
|
|||
navigate: (path, params) => dispatch(doNavigate(path, params)),
|
||||
fetchFileInfo: uri => dispatch(doFetchFileInfo(uri)),
|
||||
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
|
||||
checkSubscription: subscription => dispatch(doCheckSubscription(subscription)),
|
||||
checkSubscription: uri => dispatch(doCheckSubscription(uri)),
|
||||
openModal: (modal, props) => dispatch(doNotify(modal, props)),
|
||||
prepareEdit: (publishData, uri) => dispatch(doPrepareEdit(publishData, uri)),
|
||||
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
|
||||
|
|
|
@ -44,7 +44,7 @@ type Props = {
|
|||
fetchFileInfo: string => void,
|
||||
fetchCostInfo: string => void,
|
||||
prepareEdit: ({}, string) => void,
|
||||
checkSubscription: ({ channelName: string, uri: string }) => void,
|
||||
checkSubscription: (uri: string) => void,
|
||||
subscriptions: Array<Subscription>,
|
||||
setClientSetting: (string, boolean | string) => void,
|
||||
autoplay: boolean,
|
||||
|
@ -96,16 +96,12 @@ class FilePage extends React.Component<Props> {
|
|||
|
||||
checkSubscription = (props: Props) => {
|
||||
if (props.subscriptions.find(sub => sub.channelName === props.claim.channel_name)) {
|
||||
props.checkSubscription({
|
||||
channelName: props.claim.channel_name,
|
||||
uri: buildURI(
|
||||
{
|
||||
props.checkSubscription(
|
||||
buildURI({
|
||||
contentName: props.claim.channel_name,
|
||||
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;
|
||||
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 = {};
|
||||
Object.keys(notifications).forEach(cur => {
|
||||
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)
|
||||
)
|
||||
);
|
||||
const notifications = selectNotifications(getState());
|
||||
const newNotifications = {};
|
||||
Object.keys(notifications).forEach(cur => {
|
||||
if (
|
||||
notifications[cur].subscription.channelName !== latest.channel_name ||
|
||||
notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING
|
||||
) {
|
||||
newNotifications[cur] = { ...notifications[cur] };
|
||||
}
|
||||
});
|
||||
dispatch(setSubscriptionNotifications(newNotifications));
|
||||
// commented out as a note for @sean, notification will be clared individually
|
||||
// const notifications = selectNotifications(getState());
|
||||
// const newNotifications = {};
|
||||
// Object.keys(notifications).forEach(cur => {
|
||||
// if (
|
||||
// notifications[cur].subscription.channelName !== latest.channel_name ||
|
||||
// notifications[cur].type === NOTIFICATION_TYPES.DOWNLOADING
|
||||
// ) {
|
||||
// newNotifications[cur] = { ...notifications[cur] };
|
||||
// }
|
||||
// });
|
||||
// dispatch(setSubscriptionNotifications(newNotifications));
|
||||
}
|
||||
|
||||
dispatch({
|
||||
|
|
|
@ -124,25 +124,31 @@ export const setSubscriptionNotification = (
|
|||
},
|
||||
});
|
||||
|
||||
export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => (
|
||||
export const doCheckSubscription = (subscriptionUri: string, notify?: boolean) => (
|
||||
dispatch: Dispatch,
|
||||
getState: () => {}
|
||||
) => {
|
||||
// no dispatching FETCH_CHANNEL_CLAIMS_STARTED; causes loading issues on <SubscriptionsPage>
|
||||
|
||||
Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => {
|
||||
const claimResult = result[subscription.uri] || {};
|
||||
const state = getState();
|
||||
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 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;
|
||||
claimsInChannel.slice(0, latestIndex === -1 ? 10 : latestIndex).forEach(claim => {
|
||||
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, false);
|
||||
const state = getState();
|
||||
const shouldDownload = Boolean(
|
||||
downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT &&
|
||||
!claim.value.stream.metadata.fee &&
|
||||
|
@ -151,7 +157,7 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
|
|||
if (notify) {
|
||||
dispatch(
|
||||
setSubscriptionNotification(
|
||||
subscription,
|
||||
savedSubscription,
|
||||
uri,
|
||||
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(
|
||||
setSubscriptionLatest(
|
||||
{
|
||||
|
@ -187,12 +196,11 @@ export const doCheckSubscription = (subscription: Subscription, notify?: boolean
|
|||
dispatch({
|
||||
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
|
||||
data: {
|
||||
uri: subscription.uri,
|
||||
uri: subscriptionUri,
|
||||
claims: claimsInChannel || [],
|
||||
page: 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -232,6 +240,7 @@ export const doChannelSubscribe = (subscription: Subscription) => (
|
|||
dispatch(doClaimRewardType(rewards.SUBSCRIPTION, { failSilently: true }));
|
||||
}
|
||||
|
||||
// should be subUri
|
||||
dispatch(doCheckSubscription(subscription, true));
|
||||
};
|
||||
|
||||
|
@ -269,10 +278,11 @@ export const doCheckSubscriptionsInit = () => (dispatch: Dispatch) => {
|
|||
// doCheckSubscriptionsInit is called by doDaemonReady
|
||||
// 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
|
||||
setTimeout(() => dispatch(doCheckSubscriptions()), 5000);
|
||||
setTimeout(() => dispatch(doFetchMySubscriptions()), 5000);
|
||||
setTimeout(() => dispatch(doCheckSubscriptions()), 10000);
|
||||
const checkSubscriptionsTimer = setInterval(
|
||||
() => dispatch(doCheckSubscriptions()),
|
||||
CHECK_SUBSCRIPTIONS_INTERVAL
|
||||
20000//CHECK_SUBSCRIPTIONS_INTERVAL
|
||||
);
|
||||
dispatch({
|
||||
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
||||
|
|
Loading…
Reference in a new issue