Subscribe notify #1066
3 changed files with 24 additions and 5 deletions
|
@ -4,6 +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 {
|
||||
makeSelectClaimForUri,
|
||||
makeSelectContentTypeForUri,
|
||||
|
@ -29,6 +30,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)),
|
||||
});
|
||||
|
||||
export default connect(select, perform)(FilePage);
|
||||
|
|
|
@ -17,6 +17,7 @@ class FilePage extends React.PureComponent {
|
|||
componentDidMount() {
|
||||
this.fetchFileInfo(this.props);
|
||||
this.fetchCostInfo(this.props);
|
||||
this.checkSubscriptionLatest(this.props);
|
||||
![]() good call good call
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
@ -35,6 +36,13 @@ class FilePage extends React.PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
checkSubscriptionLatest(props) {
|
||||
props.checkSubscriptionLatest({
|
||||
channelName: props.claim.channel_name,
|
||||
uri: `${props.claim.channel_name}#${props.claim.value.publisherSignature.certificateId}`,
|
||||
}, `${props.claim.name}#${props.claim.claim_id}`);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
claim,
|
||||
|
|
|
@ -41,7 +41,7 @@ export const doCheckSubscription = (subscription: Subscription) => (dispatch: Di
|
|||
const claimResult = result[subscription.uri] || {};
|
||||
const { claims_in_channel: claimsInChannel } = claimResult;
|
||||
|
||||
let count = claimsInChannel.reduce((prev, cur, index) => `${cur.name}#${cur.claim_id}` === subscription.latest ? index : prev, -1)
|
||||
let count = subscription.latest ? claimsInChannel.reduce((prev, cur, index) => `${cur.name}#${cur.claim_id}` === subscription.latest ? index : prev, -1) : 1;
|
||||
|
||||
if(count !== 0) {
|
||||
if(!claimsInChannel[0].value.stream.metadata.fee) {
|
||||
|
@ -64,16 +64,25 @@ 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 && `${claimsInChannel[0].name}#${claimsInChannel[0].claim_id}` === uri) {
|
||||
dispatch(setSubscriptionLatest(channel, uri));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (dispatch: Dispatch) =>
|
||||
{
|
||||
return dispatch({
|
||||
dispatch({
|
||||
type: ACTIONS.SET_SUBSCRIPTION_LATEST,
|
||||
data: {
|
||||
subscription,
|
||||
uri
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
export const setHasFetchedSubscriptions = () => (dispatch: Dispatch) =>
|
||||
dispatch({ type: ACTIONS.HAS_FETCHED_SUBSCRIPTIONS });
|
||||
|
|
Loading…
Add table
Reference in a new issue
You can avoid a lot of unnecessary calls by only calling
checkSubscriptionLatest
if you are subscribed to that channel