Merge pull request #1104 from lbryio/improve-subscription-notifications

Improve subscription notifications
This commit is contained in:
Liam Cardenas 2018-03-15 01:37:39 -07:00 committed by GitHub
commit 8240e70fb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 43 deletions

View file

@ -4,7 +4,7 @@ import { doFetchFileInfo } from 'redux/actions/file_info';
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
import { selectRewardContentClaimIds } from 'redux/selectors/content';
import { doFetchCostInfoForUri } from 'redux/actions/cost_info';
import { checkSubscriptionLatest } from 'redux/actions/subscriptions';
import { doCheckSubscription } from 'redux/actions/subscriptions';
import {
makeSelectClaimForUri,
makeSelectContentTypeForUri,
@ -32,8 +32,7 @@ const perform = dispatch => ({
navigate: (path, params) => dispatch(doNavigate(path, params)),
fetchFileInfo: uri => dispatch(doFetchFileInfo(uri)),
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
checkSubscriptionLatest: (subscription, uri) =>
dispatch(checkSubscriptionLatest(subscription, uri)),
checkSubscription: subscription => dispatch(doCheckSubscription(subscription)),
});
export default connect(select, perform)(FilePage);

View file

@ -17,7 +17,7 @@ class FilePage extends React.PureComponent {
componentDidMount() {
this.fetchFileInfo(this.props);
this.fetchCostInfo(this.props);
this.checkSubscriptionLatest(this.props);
this.checkSubscription(this.props);
}
componentWillReceiveProps(nextProps) {
@ -36,25 +36,22 @@ class FilePage extends React.PureComponent {
}
}
checkSubscriptionLatest(props) {
checkSubscription(props) {
if (
props.subscriptions
.map(subscription => subscription.channelName)
.indexOf(props.claim.channel_name) !== -1
) {
props.checkSubscriptionLatest(
{
channelName: props.claim.channel_name,
uri: buildURI(
{
contentName: props.claim.channel_name,
claimId: props.claim.value.publisherSignature.certificateId,
},
false
),
},
buildURI({ contentName: props.claim.name, claimId: props.claim.claim_id }, false)
);
props.checkSubscription({
channelName: props.claim.channel_name,
uri: buildURI(
{
contentName: props.claim.channel_name,
claimId: props.claim.value.publisherSignature.certificateId,
},
false
),
});
}
}

View file

@ -165,7 +165,7 @@ export function doUpdateLoadStatus(uri, outpoint) {
setProgressBar(totalProgress);
const notif = new window.Notification('LBRY Download Complete', {
body: fileInfo.metadata.stream.metadata.title,
body: fileInfo.metadata.title,
silent: false,
});
notif.onclick = () => {

View file

@ -28,7 +28,7 @@ export const doCheckSubscriptions = () => (
const checkSubscriptionsTimer = setInterval(
() =>
selectSubscriptions(getState()).map((subscription: Subscription) =>
dispatch(doCheckSubscription(subscription))
dispatch(doCheckSubscription(subscription, true))
),
CHECK_SUBSCRIPTIONS_INTERVAL
);
@ -38,7 +38,9 @@ export const doCheckSubscriptions = () => (
});
};
export const doCheckSubscription = (subscription: Subscription) => (dispatch: Dispatch) => {
export const doCheckSubscription = (subscription: Subscription, notify?: boolean) => (
dispatch: Dispatch
) => {
dispatch({
type: ACTIONS.CHECK_SUBSCRIPTION_STARTED,
data: subscription,
@ -59,7 +61,7 @@ export const doCheckSubscription = (subscription: Subscription) => (dispatch: Di
)
: 1;
if (count !== 0) {
if (count !== 0 && notify) {
if (!claimsInChannel[0].value.stream.metadata.fee) {
dispatch(
doPurchaseUri(
@ -90,7 +92,22 @@ export const doCheckSubscription = (subscription: Subscription) => (dispatch: Di
};
}
//$FlowIssue
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
)
)
);
dispatch({
type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED,
data: subscription,
@ -98,26 +115,6 @@ export const doCheckSubscription = (subscription: Subscription) => (dispatch: Di
});
};
export const checkSubscriptionLatest = (channel: Subscription, uri: string) => (
dispatch: Dispatch
) => {
Lbry.claim_list_by_channel({ uri: channel.uri, page: 1 }).then(result => {
const claimResult = result[channel.uri] || {};
const { claims_in_channel: claimsInChannel } = claimResult;
if (
claimsInChannel &&
claimsInChannel.length &&
buildURI(
{ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id },
false
) === uri
) {
dispatch(setSubscriptionLatest(channel, uri));
}
});
};
export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (
dispatch: Dispatch
) =>