Added notifications and downloading upon detecting to subscription items
This commit is contained in:
parent
7296800ce0
commit
c3dd7f3449
5 changed files with 69 additions and 6 deletions
|
@ -165,6 +165,9 @@ export const CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE';
|
||||||
export const CHANNEL_UNSUBSCRIBE = 'CHANNEL_UNSUBSCRIBE';
|
export const CHANNEL_UNSUBSCRIBE = 'CHANNEL_UNSUBSCRIBE';
|
||||||
export const HAS_FETCHED_SUBSCRIPTIONS = 'HAS_FETCHED_SUBSCRIPTIONS';
|
export const HAS_FETCHED_SUBSCRIPTIONS = 'HAS_FETCHED_SUBSCRIPTIONS';
|
||||||
export const SET_SUBSCRIPTION_LATEST = 'SET_SUBSCRIPTION_LATEST';
|
export const SET_SUBSCRIPTION_LATEST = 'SET_SUBSCRIPTION_LATEST';
|
||||||
|
export const CHECK_SUBSCRIPTION_STARTED = 'CHECK_SUBSCRIPTION_STARTED';
|
||||||
|
export const CHECK_SUBSCRIPTION_COMPLETED = 'CHECK_SUBSCRIPTION_COMPLETED';
|
||||||
|
export const CHECK_SUBSCRIPTIONS_SUBSCRIBE = 'CHECK_SUBSCRIPTIONS_SUBSCRIBE';
|
||||||
|
|
||||||
// Video controls
|
// Video controls
|
||||||
export const SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE';
|
export const SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE';
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { doFetchDaemonSettings } from 'redux/actions/settings';
|
||||||
import { doAuthenticate } from 'redux/actions/user';
|
import { doAuthenticate } from 'redux/actions/user';
|
||||||
import { doBalanceSubscribe } from 'redux/actions/wallet';
|
import { doBalanceSubscribe } from 'redux/actions/wallet';
|
||||||
import { doPause } from 'redux/actions/media';
|
import { doPause } from 'redux/actions/media';
|
||||||
|
import { doCheckSubscriptions } from 'redux/actions/subscriptions';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
selectCurrentModal,
|
selectCurrentModal,
|
||||||
|
@ -298,6 +299,7 @@ export function doDaemonReady() {
|
||||||
dispatch(doCheckUpgradeAvailable());
|
dispatch(doCheckUpgradeAvailable());
|
||||||
}
|
}
|
||||||
dispatch(doCheckUpgradeSubscribe());
|
dispatch(doCheckUpgradeSubscribe());
|
||||||
|
dispatch(doCheckSubscriptions());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,7 +289,7 @@ export function doLoadVideo(uri) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doPurchaseUri(uri) {
|
export function doPurchaseUri(uri, specificCostInfo) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const balance = selectBalance(state);
|
const balance = selectBalance(state);
|
||||||
|
@ -322,7 +322,7 @@ export function doPurchaseUri(uri) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const costInfo = makeSelectCostInfoForUri(uri)(state);
|
const costInfo = makeSelectCostInfoForUri(uri)(state) || specificCostInfo;
|
||||||
const { cost } = costInfo;
|
const { cost } = costInfo;
|
||||||
|
|
||||||
if (cost > balance) {
|
if (cost > balance) {
|
||||||
|
@ -359,8 +359,8 @@ export function doFetchClaimsByChannel(uri, page) {
|
||||||
const claimResult = result[uri] || {};
|
const claimResult = result[uri] || {};
|
||||||
const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult;
|
const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult;
|
||||||
|
|
||||||
if(claimResult && claimResult.claims_in_channel && claimResult.claims_in_channel.length) {
|
if(claimsInChannel && claimsInChannel.length) {
|
||||||
let latest = claimResult.claims_in_channel[0];
|
let latest = claimsInChannel[0];
|
||||||
dispatch(setSubscriptionLatest({
|
dispatch(setSubscriptionLatest({
|
||||||
channelName: latest.channel_name,
|
channelName: latest.channel_name,
|
||||||
uri: `${latest.channel_name}#${latest.value.publisherSignature.certificateId}`
|
uri: `${latest.channel_name}#${latest.value.publisherSignature.certificateId}`
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
// @flow
|
// @flow
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
import type { Subscription, Dispatch } from 'redux/reducers/subscriptions';
|
import type { Subscription, Dispatch, SubscriptionState } from 'redux/reducers/subscriptions';
|
||||||
|
import { selectSubscriptions } from 'redux/selectors/subscriptions';
|
||||||
|
import Lbry from 'lbry';
|
||||||
|
import { doPurchaseUri } from 'redux/actions/content';
|
||||||
|
import { doNavigate } from 'redux/actions/navigation';
|
||||||
|
|
||||||
|
const CHECK_SUBSCRIPTIONS_INTERVAL = 10 * 60 * 1000;
|
||||||
|
|
||||||
export const doChannelSubscribe = (subscription: Subscription) => (dispatch: Dispatch) =>
|
export const doChannelSubscribe = (subscription: Subscription) => (dispatch: Dispatch) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -14,6 +20,50 @@ export const doChannelUnsubscribe = (subscription: Subscription) => (dispatch: D
|
||||||
data: subscription,
|
data: subscription,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const doCheckSubscriptions = () => (dispatch: Dispatch, getState: () => SubscriptionState) => {
|
||||||
|
const checkSubscriptionsTimer = setInterval(
|
||||||
|
() => selectSubscriptions(getState()).map((subscription: Subscription) => dispatch(doCheckSubscription(subscription))),
|
||||||
|
CHECK_SUBSCRIPTIONS_INTERVAL
|
||||||
|
);
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
||||||
|
data: { checkSubscriptionsTimer },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const doCheckSubscription = (subscription: Subscription) => (dispatch: Dispatch) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.CHECK_SUBSCRIPTION_STARTED,
|
||||||
|
data: subscription,
|
||||||
|
});
|
||||||
|
|
||||||
|
Lbry.claim_list_by_channel({ uri: subscription.uri, page: 1 }).then(result => {
|
||||||
|
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)
|
||||||
|
|
||||||
|
if(count !== 0) {
|
||||||
|
if(!claimsInChannel[0].value.stream.metadata.fee) {
|
||||||
|
dispatch(doPurchaseUri(`${claimsInChannel[0].name}#${claimsInChannel[0].claim_id}`, {cost: 0}));
|
||||||
|
}
|
||||||
|
|
||||||
|
const notif = new window.Notification(subscription.channelName, {
|
||||||
|
body: `Posted ${claimsInChannel[0].value.stream.metadata.title}${count > 1 ? ` and ${count-1} other new items` : '' }${count < 0 ? ' and 9+ other new items' : ''}`,
|
||||||
|
silent: false,
|
||||||
|
});
|
||||||
|
notif.onclick = () => {
|
||||||
|
dispatch(doNavigate('/show', { uri: `lbry://${claimsInChannel[0].name}#${claimsInChannel[0].claim_id}` }))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED,
|
||||||
|
data: subscription
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (dispatch: Dispatch) =>
|
export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (dispatch: Dispatch) =>
|
||||||
{
|
{
|
||||||
return dispatch({
|
return dispatch({
|
||||||
|
|
|
@ -37,7 +37,15 @@ type setSubscriptionLatest = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Action = doChannelSubscribe | doChannelUnsubscribe | HasFetchedSubscriptions | setSubscriptionLatest;
|
type CheckSubscriptionStarted = {
|
||||||
|
type: ACTIONS.CHECK_SUBSCRIPTION_STARTED
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckSubscriptionCompleted = {
|
||||||
|
type: ACTIONS.CHECK_SUBSCRIPTION_COMPLETED
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Action = doChannelSubscribe | doChannelUnsubscribe | HasFetchedSubscriptions | setSubscriptionLatest | CheckSubscriptionStarted | CheckSubscriptionCompleted | Function;
|
||||||
export type Dispatch = (action: Action) => any;
|
export type Dispatch = (action: Action) => any;
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue