fix conflicts
This commit is contained in:
commit
e21c85a1af
2 changed files with 195 additions and 198 deletions
203
dist/bundle.js
vendored
203
dist/bundle.js
vendored
|
@ -9269,7 +9269,7 @@ function doUserInviteNew(email) {
|
||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
exports.doChannelSubscriptionDisableNotifications = exports.doChannelSubscriptionEnableNotifications = exports.doShowSuggestedSubs = exports.doCompleteFirstRun = exports.doFetchRecommendedSubscriptions = exports.doCheckSubscriptionsInit = exports.doCheckSubscriptions = exports.doChannelUnsubscribe = exports.doChannelSubscribe = exports.doCheckSubscription = exports.doRemoveUnreadSubscription = exports.doRemoveUnreadSubscriptions = exports.doUpdateUnreadSubscriptions = exports.setSubscriptionLatest = exports.doFetchMySubscriptions = exports.doSetViewMode = undefined;
|
exports.doChannelSubscriptionDisableNotifications = exports.doChannelSubscriptionEnableNotifications = exports.doShowSuggestedSubs = exports.doCompleteFirstRun = exports.doFetchRecommendedSubscriptions = exports.doCheckSubscriptionsInit = exports.doFetchMySubscriptions = exports.doCheckSubscriptions = exports.doChannelUnsubscribe = exports.doChannelSubscribe = exports.doCheckSubscription = exports.doRemoveUnreadSubscription = exports.doRemoveUnreadSubscriptions = exports.doUpdateUnreadSubscriptions = exports.setSubscriptionLatest = exports.doSetViewMode = undefined;
|
||||||
|
|
||||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||||
|
|
||||||
|
@ -9333,99 +9333,6 @@ var doSetViewMode = exports.doSetViewMode = function doSetViewMode(viewMode /*:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var doFetchMySubscriptions = exports.doFetchMySubscriptions = function doFetchMySubscriptions() {
|
|
||||||
return function (dispatch /*: ReduxDispatch*/, getState /*: GetState*/) {
|
|
||||||
var state /*: { subscriptions: SubscriptionState, settings: any }*/ = getState();
|
|
||||||
var reduxSubscriptions = state.subscriptions.subscriptions;
|
|
||||||
|
|
||||||
// default to true if daemonSettings not found
|
|
||||||
|
|
||||||
var isSharingData = state.settings && state.settings.daemonSettings ? state.settings.daemonSettings.share_usage_data : true;
|
|
||||||
|
|
||||||
if (!isSharingData && isSharingData !== undefined) {
|
|
||||||
// They aren't sharing their data, subscriptions will be handled by persisted redux state
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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_SUBSCRIPTIONS_START });
|
|
||||||
|
|
||||||
_lbryio2.default.call('subscription', 'list').then(function (dbSubscriptions) {
|
|
||||||
var storedSubscriptions = dbSubscriptions || [];
|
|
||||||
|
|
||||||
// User has no subscriptions in db or redux
|
|
||||||
if (!storedSubscriptions.length && (!reduxSubscriptions || !reduxSubscriptions.length)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// There is some mismatch between redux state and db state
|
|
||||||
// If something is in the db, but not in redux, add it to redux
|
|
||||||
// If something is in redux, but not in the db, add it to the db
|
|
||||||
if (storedSubscriptions.length !== reduxSubscriptions.length) {
|
|
||||||
var dbSubMap = {};
|
|
||||||
var reduxSubMap = {};
|
|
||||||
var subsNotInDB = [];
|
|
||||||
var subscriptionsToReturn = reduxSubscriptions.slice();
|
|
||||||
|
|
||||||
storedSubscriptions.forEach(function (sub) {
|
|
||||||
dbSubMap[sub.claim_id] = 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
reduxSubscriptions.forEach(function (sub) {
|
|
||||||
var _parseURI = (0, _lbryRedux.parseURI)(sub.uri),
|
|
||||||
claimId = _parseURI.claimId;
|
|
||||||
|
|
||||||
reduxSubMap[claimId] = 1;
|
|
||||||
|
|
||||||
if (!dbSubMap[claimId]) {
|
|
||||||
subsNotInDB.push({
|
|
||||||
claim_id: claimId,
|
|
||||||
channel_name: sub.channelName
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
storedSubscriptions.forEach(function (sub) {
|
|
||||||
if (!reduxSubMap[sub.claim_id]) {
|
|
||||||
var uri = 'lbry://' + sub.channel_name + '#' + sub.claim_id;
|
|
||||||
subscriptionsToReturn.push({ uri: uri, channelName: sub.channel_name });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return _bluebird2.default.all(subsNotInDB.map(function (payload) {
|
|
||||||
return _lbryio2.default.call('subscription', 'new', payload);
|
|
||||||
})).then(function () {
|
|
||||||
return subscriptionsToReturn;
|
|
||||||
}).catch(function () {
|
|
||||||
return (
|
|
||||||
// let it fail, we will try again when the navigate to the subscriptions page
|
|
||||||
subscriptionsToReturn
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// DB is already synced, just return the subscriptions in redux
|
|
||||||
return reduxSubscriptions;
|
|
||||||
}).then(function (subscriptions /*: Array<Subscription>*/) {
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
|
|
||||||
data: subscriptions
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatch((0, _lbryRedux.doResolveUris)(subscriptions.map(function (_ref) {
|
|
||||||
var uri = _ref.uri;
|
|
||||||
return uri;
|
|
||||||
})));
|
|
||||||
dispatch(doCheckSubscriptions());
|
|
||||||
}).catch(function () {
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.FETCH_SUBSCRIPTIONS_FAIL
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var setSubscriptionLatest = exports.setSubscriptionLatest = function setSubscriptionLatest(subscription /*: Subscription*/, uri /*: string*/) {
|
var setSubscriptionLatest = exports.setSubscriptionLatest = function setSubscriptionLatest(subscription /*: Subscription*/, uri /*: string*/) {
|
||||||
return function (dispatch /*: ReduxDispatch*/) {
|
return function (dispatch /*: ReduxDispatch*/) {
|
||||||
return dispatch({
|
return dispatch({
|
||||||
|
@ -9500,7 +9407,7 @@ var doRemoveUnreadSubscriptions = exports.doRemoveUnreadSubscriptions = function
|
||||||
var currentChannelUnread = unreadByChannel[channelUri];
|
var currentChannelUnread = unreadByChannel[channelUri];
|
||||||
if (!currentChannelUnread || !currentChannelUnread.uris) {
|
if (!currentChannelUnread || !currentChannelUnread.uris) {
|
||||||
// Channel passed in doesn't have any unreads
|
// Channel passed in doesn't have any unreads
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each uri passed in, remove it from the list of unread uris
|
// For each uri passed in, remove it from the list of unread uris
|
||||||
|
@ -9519,7 +9426,7 @@ var doRemoveUnreadSubscriptions = exports.doRemoveUnreadSubscriptions = function
|
||||||
newUris = null;
|
newUris = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch({
|
return dispatch({
|
||||||
type: ACTIONS.REMOVE_SUBSCRIPTION_UNREADS,
|
type: ACTIONS.REMOVE_SUBSCRIPTION_UNREADS,
|
||||||
data: {
|
data: {
|
||||||
channel: channelUri,
|
channel: channelUri,
|
||||||
|
@ -9636,8 +9543,8 @@ var doChannelSubscribe = exports.doChannelSubscribe = function doChannelSubscrib
|
||||||
|
|
||||||
// if the user isn't sharing data, keep the subscriptions entirely in the app
|
// if the user isn't sharing data, keep the subscriptions entirely in the app
|
||||||
if (isSharingData) {
|
if (isSharingData) {
|
||||||
var _parseURI2 = (0, _lbryRedux.parseURI)(subscription.uri),
|
var _parseURI = (0, _lbryRedux.parseURI)(subscription.uri),
|
||||||
claimId = _parseURI2.claimId;
|
claimId = _parseURI.claimId;
|
||||||
// They are sharing data, we can store their subscriptions in our internal database
|
// They are sharing data, we can store their subscriptions in our internal database
|
||||||
|
|
||||||
|
|
||||||
|
@ -9666,8 +9573,8 @@ var doChannelUnsubscribe = exports.doChannelUnsubscribe = function doChannelUnsu
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isSharingData) {
|
if (isSharingData) {
|
||||||
var _parseURI3 = (0, _lbryRedux.parseURI)(subscription.uri),
|
var _parseURI2 = (0, _lbryRedux.parseURI)(subscription.uri),
|
||||||
claimId = _parseURI3.claimId;
|
claimId = _parseURI2.claimId;
|
||||||
|
|
||||||
_lbryio2.default.call('subscription', 'delete', {
|
_lbryio2.default.call('subscription', 'delete', {
|
||||||
claim_id: claimId
|
claim_id: claimId
|
||||||
|
@ -9687,6 +9594,99 @@ var doCheckSubscriptions = exports.doCheckSubscriptions = function doCheckSubscr
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var doFetchMySubscriptions = exports.doFetchMySubscriptions = function doFetchMySubscriptions() {
|
||||||
|
return function (dispatch /*: ReduxDispatch*/, getState /*: GetState*/) {
|
||||||
|
var state /*: { subscriptions: SubscriptionState, settings: any }*/ = getState();
|
||||||
|
var reduxSubscriptions = state.subscriptions.subscriptions;
|
||||||
|
|
||||||
|
// default to true if daemonSettings not found
|
||||||
|
|
||||||
|
var isSharingData = state.settings && state.settings.daemonSettings ? state.settings.daemonSettings.share_usage_data : true;
|
||||||
|
|
||||||
|
if (!isSharingData && isSharingData !== undefined) {
|
||||||
|
// They aren't sharing their data, subscriptions will be handled by persisted redux state
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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_SUBSCRIPTIONS_START });
|
||||||
|
|
||||||
|
_lbryio2.default.call('subscription', 'list').then(function (dbSubscriptions) {
|
||||||
|
var storedSubscriptions = dbSubscriptions || [];
|
||||||
|
|
||||||
|
// User has no subscriptions in db or redux
|
||||||
|
if (!storedSubscriptions.length && (!reduxSubscriptions || !reduxSubscriptions.length)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is some mismatch between redux state and db state
|
||||||
|
// If something is in the db, but not in redux, add it to redux
|
||||||
|
// If something is in redux, but not in the db, add it to the db
|
||||||
|
if (storedSubscriptions.length !== reduxSubscriptions.length) {
|
||||||
|
var dbSubMap = {};
|
||||||
|
var reduxSubMap = {};
|
||||||
|
var subsNotInDB = [];
|
||||||
|
var subscriptionsToReturn = reduxSubscriptions.slice();
|
||||||
|
|
||||||
|
storedSubscriptions.forEach(function (sub) {
|
||||||
|
dbSubMap[sub.claim_id] = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
reduxSubscriptions.forEach(function (sub) {
|
||||||
|
var _parseURI3 = (0, _lbryRedux.parseURI)(sub.uri),
|
||||||
|
claimId = _parseURI3.claimId;
|
||||||
|
|
||||||
|
reduxSubMap[claimId] = 1;
|
||||||
|
|
||||||
|
if (!dbSubMap[claimId]) {
|
||||||
|
subsNotInDB.push({
|
||||||
|
claim_id: claimId,
|
||||||
|
channel_name: sub.channelName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
storedSubscriptions.forEach(function (sub) {
|
||||||
|
if (!reduxSubMap[sub.claim_id]) {
|
||||||
|
var uri = 'lbry://' + sub.channel_name + '#' + sub.claim_id;
|
||||||
|
subscriptionsToReturn.push({ uri: uri, channelName: sub.channel_name });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return _bluebird2.default.all(subsNotInDB.map(function (payload) {
|
||||||
|
return _lbryio2.default.call('subscription', 'new', payload);
|
||||||
|
})).then(function () {
|
||||||
|
return subscriptionsToReturn;
|
||||||
|
}).catch(function () {
|
||||||
|
return (
|
||||||
|
// let it fail, we will try again when the navigate to the subscriptions page
|
||||||
|
subscriptionsToReturn
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB is already synced, just return the subscriptions in redux
|
||||||
|
return reduxSubscriptions;
|
||||||
|
}).then(function (subscriptions /*: Array<Subscription>*/) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
|
||||||
|
data: subscriptions
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch((0, _lbryRedux.doResolveUris)(subscriptions.map(function (_ref) {
|
||||||
|
var uri = _ref.uri;
|
||||||
|
return uri;
|
||||||
|
})));
|
||||||
|
dispatch(doCheckSubscriptions());
|
||||||
|
}).catch(function () {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.FETCH_SUBSCRIPTIONS_FAIL
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
var doCheckSubscriptionsInit = exports.doCheckSubscriptionsInit = function doCheckSubscriptionsInit() {
|
var doCheckSubscriptionsInit = exports.doCheckSubscriptionsInit = function doCheckSubscriptionsInit() {
|
||||||
return function (dispatch /*: ReduxDispatch*/) {
|
return function (dispatch /*: ReduxDispatch*/) {
|
||||||
// doCheckSubscriptionsInit is called by doDaemonReady
|
// doCheckSubscriptionsInit is called by doDaemonReady
|
||||||
|
@ -9702,6 +9702,9 @@ var doCheckSubscriptionsInit = exports.doCheckSubscriptionsInit = function doChe
|
||||||
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
||||||
data: { checkSubscriptionsTimer: checkSubscriptionsTimer }
|
data: { checkSubscriptionsTimer: checkSubscriptionsTimer }
|
||||||
});
|
});
|
||||||
|
setInterval(function () {
|
||||||
|
return dispatch(doCheckSubscriptions());
|
||||||
|
}, CHECK_SUBSCRIPTIONS_INTERVAL);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,7 @@ import type {
|
||||||
import { PAGE_SIZE } from 'constants/claim';
|
import { PAGE_SIZE } from 'constants/claim';
|
||||||
import { doClaimRewardType } from 'redux/actions/rewards';
|
import { doClaimRewardType } from 'redux/actions/rewards';
|
||||||
import { selectSubscriptions, selectUnreadByChannel } from 'redux/selectors/subscriptions';
|
import { selectSubscriptions, selectUnreadByChannel } from 'redux/selectors/subscriptions';
|
||||||
import {
|
import { Lbry, buildURI, parseURI, doResolveUris, doPurchaseUri } from 'lbry-redux';
|
||||||
Lbry,
|
|
||||||
buildURI,
|
|
||||||
parseURI,
|
|
||||||
doResolveUris,
|
|
||||||
doPurchaseUri,
|
|
||||||
doFetchClaimsByChannel,
|
|
||||||
} from 'lbry-redux';
|
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
import * as NOTIFICATION_TYPES from 'constants/subscriptions';
|
import * as NOTIFICATION_TYPES from 'constants/subscriptions';
|
||||||
import Lbryio from 'lbryio';
|
import Lbryio from 'lbryio';
|
||||||
|
@ -36,94 +29,6 @@ export const doSetViewMode = (viewMode: ViewMode) => (dispatch: ReduxDispatch) =
|
||||||
data: viewMode,
|
data: viewMode,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const doFetchMySubscriptions = () => (dispatch: ReduxDispatch, getState: GetState) => {
|
|
||||||
const state: { subscriptions: SubscriptionState, settings: any } = getState();
|
|
||||||
const { subscriptions: reduxSubscriptions } = state.subscriptions;
|
|
||||||
|
|
||||||
// default to true if daemonSettings not found
|
|
||||||
const isSharingData =
|
|
||||||
state.settings && state.settings.daemonSettings
|
|
||||||
? state.settings.daemonSettings.share_usage_data
|
|
||||||
: true;
|
|
||||||
|
|
||||||
if (!isSharingData && isSharingData !== undefined) {
|
|
||||||
// They aren't sharing their data, subscriptions will be handled by persisted redux state
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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_SUBSCRIPTIONS_START });
|
|
||||||
|
|
||||||
Lbryio.call('subscription', 'list')
|
|
||||||
.then(dbSubscriptions => {
|
|
||||||
const storedSubscriptions = dbSubscriptions || [];
|
|
||||||
|
|
||||||
// User has no subscriptions in db or redux
|
|
||||||
if (!storedSubscriptions.length && (!reduxSubscriptions || !reduxSubscriptions.length)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// There is some mismatch between redux state and db state
|
|
||||||
// If something is in the db, but not in redux, add it to redux
|
|
||||||
// If something is in redux, but not in the db, add it to the db
|
|
||||||
if (storedSubscriptions.length !== reduxSubscriptions.length) {
|
|
||||||
const dbSubMap = {};
|
|
||||||
const reduxSubMap = {};
|
|
||||||
const subsNotInDB = [];
|
|
||||||
const subscriptionsToReturn = reduxSubscriptions.slice();
|
|
||||||
|
|
||||||
storedSubscriptions.forEach(sub => {
|
|
||||||
dbSubMap[sub.claim_id] = 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
reduxSubscriptions.forEach(sub => {
|
|
||||||
const { claimId } = parseURI(sub.uri);
|
|
||||||
reduxSubMap[claimId] = 1;
|
|
||||||
|
|
||||||
if (!dbSubMap[claimId]) {
|
|
||||||
subsNotInDB.push({
|
|
||||||
claim_id: claimId,
|
|
||||||
channel_name: sub.channelName,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
storedSubscriptions.forEach(sub => {
|
|
||||||
if (!reduxSubMap[sub.claim_id]) {
|
|
||||||
const uri = `lbry://${sub.channel_name}#${sub.claim_id}`;
|
|
||||||
subscriptionsToReturn.push({ uri, channelName: sub.channel_name });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(subsNotInDB.map(payload => Lbryio.call('subscription', 'new', payload)))
|
|
||||||
.then(() => subscriptionsToReturn)
|
|
||||||
.catch(
|
|
||||||
() =>
|
|
||||||
// let it fail, we will try again when the navigate to the subscriptions page
|
|
||||||
subscriptionsToReturn
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DB is already synced, just return the subscriptions in redux
|
|
||||||
return reduxSubscriptions;
|
|
||||||
})
|
|
||||||
.then((subscriptions: Array<Subscription>) => {
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
|
|
||||||
data: subscriptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatch(doResolveUris(subscriptions.map(({ uri }) => uri)));
|
|
||||||
dispatch(doCheckSubscriptions());
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.FETCH_SUBSCRIPTIONS_FAIL,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (
|
export const setSubscriptionLatest = (subscription: Subscription, uri: string) => (
|
||||||
dispatch: ReduxDispatch
|
dispatch: ReduxDispatch
|
||||||
) =>
|
) =>
|
||||||
|
@ -199,7 +104,7 @@ export const doRemoveUnreadSubscriptions = (channelUri: ?string, readUris: ?Arra
|
||||||
const currentChannelUnread = unreadByChannel[channelUri];
|
const currentChannelUnread = unreadByChannel[channelUri];
|
||||||
if (!currentChannelUnread || !currentChannelUnread.uris) {
|
if (!currentChannelUnread || !currentChannelUnread.uris) {
|
||||||
// Channel passed in doesn't have any unreads
|
// Channel passed in doesn't have any unreads
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each uri passed in, remove it from the list of unread uris
|
// For each uri passed in, remove it from the list of unread uris
|
||||||
|
@ -220,7 +125,7 @@ export const doRemoveUnreadSubscriptions = (channelUri: ?string, readUris: ?Arra
|
||||||
newUris = null;
|
newUris = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch({
|
return dispatch({
|
||||||
type: ACTIONS.REMOVE_SUBSCRIPTION_UNREADS,
|
type: ACTIONS.REMOVE_SUBSCRIPTION_UNREADS,
|
||||||
data: {
|
data: {
|
||||||
channel: channelUri,
|
channel: channelUri,
|
||||||
|
@ -410,6 +315,94 @@ export const doCheckSubscriptions = () => (dispatch: ReduxDispatch, getState: Ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const doFetchMySubscriptions = () => (dispatch: ReduxDispatch, getState: GetState) => {
|
||||||
|
const state: { subscriptions: SubscriptionState, settings: any } = getState();
|
||||||
|
const { subscriptions: reduxSubscriptions } = state.subscriptions;
|
||||||
|
|
||||||
|
// default to true if daemonSettings not found
|
||||||
|
const isSharingData =
|
||||||
|
state.settings && state.settings.daemonSettings
|
||||||
|
? state.settings.daemonSettings.share_usage_data
|
||||||
|
: true;
|
||||||
|
|
||||||
|
if (!isSharingData && isSharingData !== undefined) {
|
||||||
|
// They aren't sharing their data, subscriptions will be handled by persisted redux state
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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_SUBSCRIPTIONS_START });
|
||||||
|
|
||||||
|
Lbryio.call('subscription', 'list')
|
||||||
|
.then(dbSubscriptions => {
|
||||||
|
const storedSubscriptions = dbSubscriptions || [];
|
||||||
|
|
||||||
|
// User has no subscriptions in db or redux
|
||||||
|
if (!storedSubscriptions.length && (!reduxSubscriptions || !reduxSubscriptions.length)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is some mismatch between redux state and db state
|
||||||
|
// If something is in the db, but not in redux, add it to redux
|
||||||
|
// If something is in redux, but not in the db, add it to the db
|
||||||
|
if (storedSubscriptions.length !== reduxSubscriptions.length) {
|
||||||
|
const dbSubMap = {};
|
||||||
|
const reduxSubMap = {};
|
||||||
|
const subsNotInDB = [];
|
||||||
|
const subscriptionsToReturn = reduxSubscriptions.slice();
|
||||||
|
|
||||||
|
storedSubscriptions.forEach(sub => {
|
||||||
|
dbSubMap[sub.claim_id] = 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
reduxSubscriptions.forEach(sub => {
|
||||||
|
const { claimId } = parseURI(sub.uri);
|
||||||
|
reduxSubMap[claimId] = 1;
|
||||||
|
|
||||||
|
if (!dbSubMap[claimId]) {
|
||||||
|
subsNotInDB.push({
|
||||||
|
claim_id: claimId,
|
||||||
|
channel_name: sub.channelName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
storedSubscriptions.forEach(sub => {
|
||||||
|
if (!reduxSubMap[sub.claim_id]) {
|
||||||
|
const uri = `lbry://${sub.channel_name}#${sub.claim_id}`;
|
||||||
|
subscriptionsToReturn.push({ uri, channelName: sub.channel_name });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(subsNotInDB.map(payload => Lbryio.call('subscription', 'new', payload)))
|
||||||
|
.then(() => subscriptionsToReturn)
|
||||||
|
.catch(
|
||||||
|
() =>
|
||||||
|
// let it fail, we will try again when the navigate to the subscriptions page
|
||||||
|
subscriptionsToReturn
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DB is already synced, just return the subscriptions in redux
|
||||||
|
return reduxSubscriptions;
|
||||||
|
})
|
||||||
|
.then((subscriptions: Array<Subscription>) => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
|
||||||
|
data: subscriptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch(doResolveUris(subscriptions.map(({ uri }) => uri)));
|
||||||
|
dispatch(doCheckSubscriptions());
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.FETCH_SUBSCRIPTIONS_FAIL,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const doCheckSubscriptionsInit = () => (dispatch: ReduxDispatch) => {
|
export const doCheckSubscriptionsInit = () => (dispatch: ReduxDispatch) => {
|
||||||
// doCheckSubscriptionsInit is called by doDaemonReady
|
// doCheckSubscriptionsInit is called by doDaemonReady
|
||||||
// setTimeout below is a hack to ensure redux is hydrated when subscriptions are checked
|
// setTimeout below is a hack to ensure redux is hydrated when subscriptions are checked
|
||||||
|
@ -423,6 +416,7 @@ export const doCheckSubscriptionsInit = () => (dispatch: ReduxDispatch) => {
|
||||||
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
type: ACTIONS.CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
||||||
data: { checkSubscriptionsTimer },
|
data: { checkSubscriptionsTimer },
|
||||||
});
|
});
|
||||||
|
setInterval(() => dispatch(doCheckSubscriptions()), CHECK_SUBSCRIPTIONS_INTERVAL);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const doFetchRecommendedSubscriptions = () => (dispatch: ReduxDispatch) => {
|
export const doFetchRecommendedSubscriptions = () => (dispatch: ReduxDispatch) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue