Skip to content

Commit

Permalink
clean up subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Yesmunt committed May 10, 2018
1 parent 87026c8 commit 101f135
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 49 deletions.
17 changes: 0 additions & 17 deletions src/renderer/analytics.js
Expand Up @@ -2,7 +2,6 @@
import mixpanel from 'mixpanel-browser';
import Lbryio from 'lbryio';
import isDev from 'electron-is-dev';
import type { Subscription } from 'redux/reducers/subscriptions';

if (isDev) {
mixpanel.init('691723e855cabb9d27a7a79002216967');
Expand All @@ -15,8 +14,6 @@ type Analytics = {
setUser: Object => void,
toggle: (boolean, ?boolean) => void,
apiLogView: (string, string, string) => void,
apiLogSubscribe: Subscription => void,
apiLogUnsubscribe: Subscription => void,
};

let analyticsEnabled: boolean = false;
Expand Down Expand Up @@ -56,20 +53,6 @@ const analytics: Analytics = {
}).catch(() => {});
}
},
apiLogSubscribe: (subscription: Subscription): void => {
if (analyticsEnabled) {
Lbryio.call('subscription', 'new', {
subscription,
}).catch(() => {});
}
},
apiLogUnsubscribe: (subscription: Subscription): void => {
if (analyticsEnabled) {
Lbryio.call('subscription', 'delete', {
subscription,
}).catch(() => {});
}
},
};

export default analytics;
2 changes: 1 addition & 1 deletion src/renderer/component/spinner/view.jsx
@@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import classnames from 'classnames';
import { DARK_THEME, LIGHT_THEME } from 'constants/settings';
import { DARK_THEME, LIGHT_THEME } from 'constants/themes';

type Props = {
dark?: boolean, // always a dark spinner
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/component/subscribeButton/view.jsx
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { MODALS } from 'lbry-redux';
import * as icons from 'constants/icons';
import Button from 'component/button';
import type { Subscription } from 'redux/reducers/subscriptions';
import type { Subscription } from 'types/subscription';

type SubscribtionArgs = {
channelName: string,
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/constants/action_types.js
Expand Up @@ -176,9 +176,9 @@ export const SET_SUBSCRIPTION_NOTIFICATIONS = 'SET_SUBSCRIPTION_NOTIFICATIONS';
export const CHECK_SUBSCRIPTION_STARTED = 'CHECK_SUBSCRIPTION_STARTED';
export const CHECK_SUBSCRIPTION_COMPLETED = 'CHECK_SUBSCRIPTION_COMPLETED';
export const CHECK_SUBSCRIPTIONS_SUBSCRIBE = 'CHECK_SUBSCRIPTIONS_SUBSCRIBE';
export const FETCH_MY_SUBSCRIPTIONS_START = 'FETCH_MY_SUBSCRIPTIONS_START';
export const FETCH_MY_SUBSCRIPTIONS_FAIL = 'FETCH_MY_SUBSCRIPTIONS_FAIL';
export const FETCH_MY_SUBSCRIPTIONS_SUCCESS = 'FETCH_MY_SUBSCRIPTIONS_SUCCESS';
export const FETCH_SUBSCRIPTIONS_START = 'FETCH_SUBSCRIPTIONS_START';
export const FETCH_SUBSCRIPTIONS_FAIL = 'FETCH_SUBSCRIPTIONS_FAIL';
export const FETCH_SUBSCRIPTIONS_SUCCESS = 'FETCH_SUBSCRIPTIONS_SUCCESS';

// Video controls
export const SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE';
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/constants/settings.js
Expand Up @@ -11,6 +11,4 @@ export const INSTANT_PURCHASE_ENABLED = 'instantPurchaseEnabled';
export const INSTANT_PURCHASE_MAX = 'instantPurchaseMax';
export const THEME = 'theme';
export const THEMES = 'themes';
export const DARK_THEME = 'dark';
export const LIGHT_THEME = 'light';
export const AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled';
4 changes: 4 additions & 0 deletions src/renderer/constants/themes.js
@@ -0,0 +1,4 @@
// css theme values
// saved in settings and found at /static/themes/{theme}.css
export const DARK_THEME = 'dark';
export const LIGHT_THEME = 'light';
2 changes: 1 addition & 1 deletion src/renderer/page/subscriptions/view.jsx
@@ -1,7 +1,7 @@
// @flow
import React from 'react';
import Page from 'component/page';
import type { Subscription } from 'redux/reducers/subscriptions';
import type { Subscription } from 'types/subscription';
import * as NOTIFICATION_TYPES from 'constants/notification_types';
import Button from 'component/button';
import FileList from 'component/fileList';
Expand Down
22 changes: 8 additions & 14 deletions src/renderer/redux/actions/subscriptions.js
Expand Up @@ -2,26 +2,20 @@
import * as ACTIONS from 'constants/action_types';
import * as NOTIFICATION_TYPES from 'constants/notification_types';
import type {
Subscription,
Dispatch,
SubscriptionState,
SubscriptionNotifications,
} from 'redux/reducers/subscriptions';
import type { Subscription } from 'types/subscription';
import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { Lbry, buildURI } from 'lbry-redux';
import { Lbry, buildURI, parseURI } from 'lbry-redux';
import { doPurchaseUri } from 'redux/actions/content';
import Promise from 'bluebird';
import Lbryio from 'lbryio';

const CHECK_SUBSCRIPTIONS_INTERVAL = 60 * 60 * 1000;
const SUBSCRIPTION_DOWNLOAD_LIMIT = 1;

const getClaimId = uri => {
const index = uri.indexOf('#');
const claimId = uri.slice(index + 1);
return claimId;
};

export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () => any) => {
const {
subscriptions: subscriptionState,
Expand All @@ -37,7 +31,7 @@ export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () =>

// most of this logic comes from scenarios where the db isn't synced with redux
// this will happen if the user stops sharing data
dispatch({ type: ACTIONS.FETCH_MY_SUBSCRIPTIONS_START });
dispatch({ type: ACTIONS.FETCH_SUBSCRIPTIONS_START });

Lbryio.call('subscription', 'list')
.then(dbSubscriptions => {
Expand All @@ -62,7 +56,7 @@ export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () =>
});

reduxSubscriptions.forEach(sub => {
const claimId = getClaimId(sub.uri);
const { claimId } = parseURI(sub.uri);
reduxSubMap[claimId] = 1;

if (!dbSubMap[claimId]) {
Expand Down Expand Up @@ -94,13 +88,13 @@ export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () =>
})
.then(subscriptions => {
dispatch({
type: ACTIONS.FETCH_MY_SUBSCRIPTIONS_SUCCESS,
type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
data: subscriptions,
});
})
.catch(() => {
dispatch({
type: ACTIONS.FETCH_MY_SUBSCRIPTIONS_FAIL,
type: ACTIONS.FETCH_SUBSCRIPTIONS_FAIL,
});
});
};
Expand Down Expand Up @@ -217,7 +211,7 @@ export const doChannelSubscribe = (subscription: Subscription) => (

// if the user isn't sharing data, keep the subscriptions entirely in the app
if (isSharingData) {
const claimId = getClaimId(subscription.uri);
const { claimId } = parseURI(subscription.uri);
// They are sharing data, we can store their subscriptions in our internal database
Lbryio.call('subscription', 'new', {
channel_name: subscription.channelName,
Expand All @@ -243,7 +237,7 @@ export const doChannelUnsubscribe = (subscription: Subscription) => (
});

if (isSharingData) {
const claimId = getClaimId(subscription.uri);
const { claimId } = parseURI(subscription.uri);
Lbryio.call('subscription', 'delete', {
claim_id: claimId,
});
Expand Down
15 changes: 5 additions & 10 deletions src/renderer/redux/reducers/subscriptions.js
Expand Up @@ -2,12 +2,7 @@
import * as ACTIONS from 'constants/action_types';
import * as NOTIFICATION_TYPES from 'constants/notification_types';
import { handleActions } from 'util/redux-utils';

export type Subscription = {
channelName: string,
uri: string,
latest: ?string,
};
import type { Subscription } from 'types/subscription';

export type NotificationType =
| NOTIFICATION_TYPES.DOWNLOADING
Expand Down Expand Up @@ -72,7 +67,7 @@ type CheckSubscriptionCompleted = {
};

type fetchedSubscriptionsSucess = {
type: ACTIONS.FETCH_MY_SUBSCRIPTIONS_SUCCESS,
type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
data: Array<Subscription>,
};

Expand Down Expand Up @@ -151,15 +146,15 @@ export default handleActions(
...state,
notifications: action.data.notifications,
}),
[ACTIONS.FETCH_MY_SUBSCRIPTIONS_START]: (state: SubscriptionState): SubscriptionState => ({
[ACTIONS.FETCH_SUBSCRIPTIONS_START]: (state: SubscriptionState): SubscriptionState => ({
...state,
loading: true,
}),
[ACTIONS.FETCH_MY_SUBSCRIPTIONS_FAIL]: (state: SubscriptionState): SubscriptionState => ({
[ACTIONS.FETCH_SUBSCRIPTIONS_FAIL]: (state: SubscriptionState): SubscriptionState => ({
...state,
loading: false,
}),
[ACTIONS.FETCH_MY_SUBSCRIPTIONS_SUCCESS]: (
[ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS]: (
state: SubscriptionState,
action: fetchedSubscriptionsSucess
): SubscriptionState => ({
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/types/subscription.js
@@ -0,0 +1,7 @@
// @flow

export type Subscription = {
channelName: string, // @CryptoCandor,
uri: string, // lbry://@CryptoCandor#9152f3b054f692076a6882d1b58a30e8781cc8e6
latest: string, // substratum#b0ab143243020e7831fd070d9f871e1fda948620
};

0 comments on commit 101f135

Please sign in to comment.