diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 0b956f4..82c420d 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -72,14 +72,11 @@ const FETCH_FILTERED_CONTENT_FAILED = 'FETCH_FILTERED_CONTENT_FAILED'; const FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; // Cost Info const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; -const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // Stats +const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // File Stats const FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED'; const FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED'; -const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; -const FETCH_SUB_COUNT_STARTED = 'FETCH_SUB_COUNT_STARTED'; -const FETCH_SUB_COUNT_FAILED = 'FETCH_SUB_COUNT_FAILED'; -const FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED'; // Cross-device Sync +const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; // Cross-device Sync const GET_SYNC_STARTED = 'GET_SYNC_STARTED'; const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; @@ -154,9 +151,6 @@ var action_types = /*#__PURE__*/Object.freeze({ FETCH_VIEW_COUNT_STARTED: FETCH_VIEW_COUNT_STARTED, FETCH_VIEW_COUNT_FAILED: FETCH_VIEW_COUNT_FAILED, FETCH_VIEW_COUNT_COMPLETED: FETCH_VIEW_COUNT_COMPLETED, - FETCH_SUB_COUNT_STARTED: FETCH_SUB_COUNT_STARTED, - FETCH_SUB_COUNT_FAILED: FETCH_SUB_COUNT_FAILED, - FETCH_SUB_COUNT_COMPLETED: FETCH_SUB_COUNT_COMPLETED, GET_SYNC_STARTED: GET_SYNC_STARTED, GET_SYNC_COMPLETED: GET_SYNC_COMPLETED, SET_SYNC_STARTED: SET_SYNC_STARTED, @@ -504,6 +498,7 @@ const handleActions = (actionMap, defaultState) => (state = defaultState, action const defaultState = { enabledChannelNotifications: [], subscriptions: [], + latest: {}, unread: {}, suggested: {}, loading: false, @@ -539,11 +534,17 @@ var subscriptions = handleActions({ subscriptions: newSubscriptions }; }, - [SET_SUBSCRIPTION_LATEST]: (state, action) => ({ ...state, - subscriptions: state.subscriptions.map(subscription => subscription.channelName === action.data.subscription.channelName ? { ...subscription, - latest: action.data.uri - } : subscription) - }), + [SET_SUBSCRIPTION_LATEST]: (state, action) => { + const { + subscription, + uri + } = action.data; + const newLatest = Object.assign({}, state.latest); + newLatest[subscription.uri] = uri; + return { ...state, + latest: newLatest + }; + }, [UPDATE_SUBSCRIPTION_UNREADS]: (state, action) => { const { channel, @@ -1708,6 +1709,7 @@ const doCheckSubscription = (subscriptionUri, shouldNotify) => (dispatch, getSta const state = getState(); const savedSubscription = state.subscriptions.subscriptions.find(sub => sub.uri === subscriptionUri); + const subscriptionLatest = state.subscriptions.latest[subscriptionUri]; if (!savedSubscription) { throw Error(`Trying to find new content for ${subscriptionUri} but it doesn't exist in your subscriptions`); @@ -1730,12 +1732,12 @@ const doCheckSubscription = (subscriptionUri, shouldNotify) => (dispatch, getSta } // Determine if the latest subscription currently saved is actually the latest subscription - const latestIndex = claimsInChannel.findIndex(claim => claim.permanent_url === savedSubscription.latest); // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed + const latestIndex = claimsInChannel.findIndex(claim => claim.permanent_url === subscriptionLatest); // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed const latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; // If latest is 0, nothing has changed // Do not download/notify about new content, it would download/notify 10 claims per channel - if (latestIndex !== 0 && savedSubscription.latest) { + if (latestIndex !== 0 && subscriptionLatest) { let downloadCount = 0; const newUnread = []; claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => { @@ -2172,28 +2174,6 @@ const doFetchViewCount = claimId => dispatch => { }); }); }; -const doFetchSubCount = claimId => dispatch => { - dispatch({ - type: FETCH_SUB_COUNT_STARTED - }); - return Lbryio.call('subscription', 'sub_count', { - claim_id: claimId - }).then(result => { - const subCount = result[0]; - dispatch({ - type: FETCH_SUB_COUNT_COMPLETED, - data: { - claimId, - subCount - } - }); - }).catch(error => { - dispatch({ - type: FETCH_SUB_COUNT_FAILED, - data: error - }); - }); -}; function doSetSync(oldHash, newHash, data) { return dispatch => { @@ -2892,10 +2872,7 @@ const homepageReducer = handleActions({ const defaultState$8 = { fetchingViewCount: false, viewCountError: undefined, - viewCountById: {}, - fetchingSubCount: false, - subCountError: undefined, - subCountById: {} + viewCountById: {} }; const statsReducer = handleActions({ [FETCH_VIEW_COUNT_STARTED]: state => ({ ...state, @@ -2916,25 +2893,6 @@ const statsReducer = handleActions({ fetchingViewCount: false, viewCountById }; - }, - [FETCH_SUB_COUNT_STARTED]: state => ({ ...state, - fetchingSubCount: true - }), - [FETCH_SUB_COUNT_FAILED]: (state, action) => ({ ...state, - subCountError: action.data - }), - [FETCH_SUB_COUNT_COMPLETED]: (state, action) => { - const { - claimId, - subCount - } = action.data; - const subCountById = { ...state.subCountById, - [claimId]: subCount - }; - return { ...state, - fetchingSubCount: false, - subCountById - }; } }, defaultState$8); @@ -3029,9 +2987,7 @@ const selectFetchingTrendingUris = reselect.createSelector(selectState$7, state const selectState$8 = state => state.stats || {}; const selectViewCount = reselect.createSelector(selectState$8, state => state.viewCountById); -const selectSubCount = reselect.createSelector(selectState$8, state => state.subCountById); const makeSelectViewCountForUri = uri => reselect.createSelector(lbryRedux.makeSelectClaimForUri(uri), selectViewCount, (claim, viewCountById) => viewCountById[claim.claim_id] || 0); -const makeSelectSubCountForUri = uri => reselect.createSelector(lbryRedux.makeSelectClaimForUri(uri), selectSubCount, (claim, subCountById) => subCountById[claim.claim_id] || 0); const selectState$9 = state => state.sync || {}; @@ -3072,7 +3028,6 @@ exports.doFetchInviteStatus = doFetchInviteStatus; exports.doFetchMySubscriptions = doFetchMySubscriptions; exports.doFetchRecommendedSubscriptions = doFetchRecommendedSubscriptions; exports.doFetchRewardedContent = doFetchRewardedContent; -exports.doFetchSubCount = doFetchSubCount; exports.doFetchTrendingUris = doFetchTrendingUris; exports.doFetchViewCount = doFetchViewCount; exports.doFilteredOutpointsSubscribe = doFilteredOutpointsSubscribe; @@ -3111,7 +3066,6 @@ exports.makeSelectIsRewardClaimPending = makeSelectIsRewardClaimPending; exports.makeSelectIsSubscribed = makeSelectIsSubscribed; exports.makeSelectRewardAmountByType = makeSelectRewardAmountByType; exports.makeSelectRewardByType = makeSelectRewardByType; -exports.makeSelectSubCountForUri = makeSelectSubCountForUri; exports.makeSelectUnreadByChannel = makeSelectUnreadByChannel; exports.makeSelectViewCountForUri = makeSelectViewCountForUri; exports.rewards = rewards; diff --git a/dist/bundle.js b/dist/bundle.js index 2ca780b..86011ec 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -215,8 +215,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(26); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__["doFetchViewCount"]; }); -/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doFetchSubCount", function() { return redux_actions_stats__WEBPACK_IMPORTED_MODULE_13__["doFetchSubCount"]; }); - /* harmony import */ var redux_actions_sync__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(27); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "doCheckSync", function() { return redux_actions_sync__WEBPACK_IMPORTED_MODULE_14__["doCheckSync"]; }); @@ -418,8 +416,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(42); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__["makeSelectViewCountForUri"]; }); -/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectSubCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_32__["makeSelectSubCountForUri"]; }); - /* harmony import */ var redux_selectors_sync__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(43); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectHasSyncedWallet", function() { return redux_selectors_sync__WEBPACK_IMPORTED_MODULE_33__["selectHasSyncedWallet"]; }); @@ -551,9 +547,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_STARTED", function() { return FETCH_VIEW_COUNT_STARTED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_FAILED", function() { return FETCH_VIEW_COUNT_FAILED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_VIEW_COUNT_COMPLETED", function() { return FETCH_VIEW_COUNT_COMPLETED; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_SUB_COUNT_STARTED", function() { return FETCH_SUB_COUNT_STARTED; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_SUB_COUNT_FAILED", function() { return FETCH_SUB_COUNT_FAILED; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FETCH_SUB_COUNT_COMPLETED", function() { return FETCH_SUB_COUNT_COMPLETED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GET_SYNC_STARTED", function() { return GET_SYNC_STARTED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GET_SYNC_COMPLETED", function() { return GET_SYNC_COMPLETED; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SET_SYNC_STARTED", function() { return SET_SYNC_STARTED; }); @@ -627,14 +620,11 @@ var FETCH_FILTERED_CONTENT_FAILED = 'FETCH_FILTERED_CONTENT_FAILED'; var FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; // Cost Info var FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; -var FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // Stats +var FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // File Stats var FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED'; var FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED'; -var FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; -var FETCH_SUB_COUNT_STARTED = 'FETCH_SUB_COUNT_STARTED'; -var FETCH_SUB_COUNT_FAILED = 'FETCH_SUB_COUNT_FAILED'; -var FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED'; // Cross-device Sync +var FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; // Cross-device Sync var GET_SYNC_STARTED = 'GET_SYNC_STARTED'; var GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; @@ -1234,6 +1224,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope var defaultState = { enabledChannelNotifications: [], subscriptions: [], + latest: {}, unread: {}, suggested: {}, loading: false, @@ -1266,18 +1257,19 @@ var defaultState = { subscriptions: newSubscriptions }); }), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_0__["SET_SUBSCRIPTION_LATEST"], function (state, action) { + var _action$data = action.data, + subscription = _action$data.subscription, + uri = _action$data.uri; + var newLatest = Object.assign({}, state.latest); + newLatest[subscription.uri] = uri; return _objectSpread({}, state, { - subscriptions: state.subscriptions.map(function (subscription) { - return subscription.channelName === action.data.subscription.channelName ? _objectSpread({}, subscription, { - latest: action.data.uri - }) : subscription; - }) + latest: newLatest }); }), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_0__["UPDATE_SUBSCRIPTION_UNREADS"], function (state, action) { - var _action$data = action.data, - channel = _action$data.channel, - uris = _action$data.uris, - type = _action$data.type; + var _action$data2 = action.data, + channel = _action$data2.channel, + uris = _action$data2.uris, + type = _action$data2.type; return _objectSpread({}, state, { unread: _objectSpread({}, state.unread, _defineProperty({}, channel, { uris: uris, @@ -1285,9 +1277,9 @@ var defaultState = { })) }); }), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_0__["REMOVE_SUBSCRIPTION_UNREADS"], function (state, action) { - var _action$data2 = action.data, - channel = _action$data2.channel, - uris = _action$data2.uris; // If no channel is passed in, remove all unreads + var _action$data3 = action.data, + channel = _action$data3.channel, + uris = _action$data3.uris; // If no channel is passed in, remove all unreads var newUnread; @@ -3075,6 +3067,7 @@ var doCheckSubscription = function doCheckSubscription(subscriptionUri, shouldNo var savedSubscription = state.subscriptions.subscriptions.find(function (sub) { return sub.uri === subscriptionUri; }); + var subscriptionLatest = state.subscriptions.latest[subscriptionUri]; if (!savedSubscription) { throw Error("Trying to find new content for ".concat(subscriptionUri, " but it doesn't exist in your subscriptions")); @@ -3096,13 +3089,13 @@ var doCheckSubscription = function doCheckSubscription(subscriptionUri, shouldNo var latestIndex = claimsInChannel.findIndex(function (claim) { - return claim.permanent_url === savedSubscription.latest; + return claim.permanent_url === subscriptionLatest; }); // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed var latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; // If latest is 0, nothing has changed // Do not download/notify about new content, it would download/notify 10 claims per channel - if (latestIndex !== 0 && savedSubscription.latest) { + if (latestIndex !== 0 && subscriptionLatest) { var downloadCount = 0; var newUnread = []; claimsInChannel.slice(0, latestIndexToNotify).forEach(function (claim) { @@ -3674,7 +3667,6 @@ function doFetchTrendingUris() { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doFetchViewCount", function() { return doFetchViewCount; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "doFetchSubCount", function() { return doFetchSubCount; }); /* harmony import */ var lbryio__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2); /* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1); @@ -3703,30 +3695,6 @@ var doFetchViewCount = function doFetchViewCount(claimId) { }); }; }; -var doFetchSubCount = function doFetchSubCount(claimId) { - return function (dispatch) { - dispatch({ - type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_STARTED"] - }); - return lbryio__WEBPACK_IMPORTED_MODULE_0__["default"].call('subscription', 'sub_count', { - claim_id: claimId - }).then(function (result) { - var subCount = result[0]; - dispatch({ - type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_COMPLETED"], - data: { - claimId: claimId, - subCount: subCount - } - }); - })["catch"](function (error) { - dispatch({ - type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_FAILED"], - data: error - }); - }); - }; -}; /***/ }), /* 27 */ @@ -4609,10 +4577,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope var defaultState = { fetchingViewCount: false, viewCountError: undefined, - viewCountById: {}, - fetchingSubCount: false, - subCountError: undefined, - subCountById: {} + viewCountById: {} }; var statsReducer = Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_0__["handleActions"])((_handleActions = {}, _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_STARTED"], function (state) { return _objectSpread({}, state, { @@ -4633,25 +4598,6 @@ var statsReducer = Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_0__["handleA fetchingViewCount: false, viewCountById: viewCountById }); -}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_STARTED"], function (state) { - return _objectSpread({}, state, { - fetchingSubCount: true - }); -}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_FAILED"], function (state, action) { - return _objectSpread({}, state, { - subCountError: action.data - }); -}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_SUB_COUNT_COMPLETED"], function (state, action) { - var _action$data2 = action.data, - claimId = _action$data2.claimId, - subCount = _action$data2.subCount; - - var subCountById = _objectSpread({}, state.subCountById, _defineProperty({}, claimId, subCount)); - - return _objectSpread({}, state, { - fetchingSubCount: false, - subCountById: subCountById - }); }), _handleActions), defaultState); /***/ }), @@ -4876,9 +4822,7 @@ var selectFetchingTrendingUris = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["c "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectViewCount", function() { return selectViewCount; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "selectSubCount", function() { return selectSubCount; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return makeSelectViewCountForUri; }); -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "makeSelectSubCountForUri", function() { return makeSelectSubCountForUri; }); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(13); /* harmony import */ var reselect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(reselect__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3); @@ -4893,19 +4837,11 @@ var selectState = function selectState(state) { var selectViewCount = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { return state.viewCountById; }); -var selectSubCount = Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(selectState, function (state) { - return state.subCountById; -}); var makeSelectViewCountForUri = function makeSelectViewCountForUri(uri) { return Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_1__["makeSelectClaimForUri"])(uri), selectViewCount, function (claim, viewCountById) { return viewCountById[claim.claim_id] || 0; }); }; -var makeSelectSubCountForUri = function makeSelectSubCountForUri(uri) { - return Object(reselect__WEBPACK_IMPORTED_MODULE_0__["createSelector"])(Object(lbry_redux__WEBPACK_IMPORTED_MODULE_1__["makeSelectClaimForUri"])(uri), selectSubCount, function (claim, subCountById) { - return subCountById[claim.claim_id] || 0; - }); -}; /***/ }), /* 43 */ diff --git a/src/constants/action_types.js b/src/constants/action_types.js index edfbf43..ca70262 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -71,13 +71,10 @@ export const FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; export const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; export const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; -// Stats +// File Stats export const FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED'; export const FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED'; export const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED'; -export const FETCH_SUB_COUNT_STARTED = 'FETCH_SUB_COUNT_STARTED'; -export const FETCH_SUB_COUNT_FAILED = 'FETCH_SUB_COUNT_FAILED'; -export const FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED'; // Cross-device Sync export const GET_SYNC_STARTED = 'GET_SYNC_STARTED'; diff --git a/src/index.js b/src/index.js index 32252e9..c81498b 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,7 @@ export { doFetchCostInfoForUri } from 'redux/actions/cost_info'; export { doBlackListedOutpointsSubscribe } from 'redux/actions/blacklist'; export { doFilteredOutpointsSubscribe } from 'redux/actions/filtered'; export { doFetchFeaturedUris, doFetchTrendingUris } from 'redux/actions/homepage'; -export { doFetchViewCount, doFetchSubCount } from 'redux/actions/stats'; +export { doFetchViewCount } from 'redux/actions/stats'; export { doCheckSync, doGetSync, @@ -170,7 +170,7 @@ export { selectTrendingUris, selectFetchingTrendingUris, } from 'redux/selectors/homepage'; -export { makeSelectViewCountForUri, makeSelectSubCountForUri } from 'redux/selectors/stats'; +export { makeSelectViewCountForUri } from 'redux/selectors/stats'; export { selectHasSyncedWallet, selectSyncData, diff --git a/src/redux/actions/stats.js b/src/redux/actions/stats.js index 14f96fa..ac00620 100644 --- a/src/redux/actions/stats.js +++ b/src/redux/actions/stats.js @@ -14,19 +14,3 @@ export const doFetchViewCount = (claimId: string) => dispatch => { dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_FAILED, data: error }); }); }; - -export const doFetchSubCount = (claimId: string) => dispatch => { - dispatch({ type: ACTIONS.FETCH_SUB_COUNT_STARTED }); - - return Lbryio.call('subscription', 'sub_count', { claim_id: claimId }) - .then((result: Array) => { - const subCount = result[0]; - dispatch({ - type: ACTIONS.FETCH_SUB_COUNT_COMPLETED, - data: { claimId, subCount }, - }); - }) - .catch(error => { - dispatch({ type: ACTIONS.FETCH_SUB_COUNT_FAILED, data: error }); - }); -}; diff --git a/src/redux/actions/subscriptions.js b/src/redux/actions/subscriptions.js index de462b3..d2ab38c 100644 --- a/src/redux/actions/subscriptions.js +++ b/src/redux/actions/subscriptions.js @@ -141,6 +141,7 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool const savedSubscription = state.subscriptions.subscriptions.find( sub => sub.uri === subscriptionUri ); + const subscriptionLatest = state.subscriptions.latest[subscriptionUri]; if (!savedSubscription) { throw Error( @@ -165,7 +166,7 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool // Determine if the latest subscription currently saved is actually the latest subscription const latestIndex = claimsInChannel.findIndex( - claim => claim.permanent_url === savedSubscription.latest + claim => claim.permanent_url === subscriptionLatest ); // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed @@ -173,7 +174,7 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool // If latest is 0, nothing has changed // Do not download/notify about new content, it would download/notify 10 claims per channel - if (latestIndex !== 0 && savedSubscription.latest) { + if (latestIndex !== 0 && subscriptionLatest) { let downloadCount = 0; const newUnread = []; diff --git a/src/redux/reducers/stats.js b/src/redux/reducers/stats.js index 0b4cfe5..134e2b2 100644 --- a/src/redux/reducers/stats.js +++ b/src/redux/reducers/stats.js @@ -5,9 +5,6 @@ const defaultState = { fetchingViewCount: false, viewCountError: undefined, viewCountById: {}, - fetchingSubCount: false, - subCountError: undefined, - subCountById: {}, }; export const statsReducer = handleActions( @@ -27,21 +24,6 @@ export const statsReducer = handleActions( viewCountById, }; }, - [ACTIONS.FETCH_SUB_COUNT_STARTED]: state => ({ ...state, fetchingSubCount: true }), - [ACTIONS.FETCH_SUB_COUNT_FAILED]: (state, action) => ({ - ...state, - subCountError: action.data, - }), - [ACTIONS.FETCH_SUB_COUNT_COMPLETED]: (state, action) => { - const { claimId, subCount } = action.data; - - const subCountById = { ...state.subCountById, [claimId]: subCount }; - return { - ...state, - fetchingSubCount: false, - subCountById, - }; - }, }, defaultState ); diff --git a/src/redux/reducers/subscriptions.js b/src/redux/reducers/subscriptions.js index ec7c5f3..6dc1f14 100644 --- a/src/redux/reducers/subscriptions.js +++ b/src/redux/reducers/subscriptions.js @@ -7,6 +7,7 @@ import { handleActions } from 'util/redux-utils'; const defaultState: SubscriptionState = { enabledChannelNotifications: [], subscriptions: [], + latest: {}, unread: {}, suggested: {}, loading: false, @@ -54,15 +55,16 @@ export default handleActions( [ACTIONS.SET_SUBSCRIPTION_LATEST]: ( state: SubscriptionState, action: SetSubscriptionLatest - ): SubscriptionState => ({ - ...state, - subscriptions: state.subscriptions.map( - subscription => - subscription.channelName === action.data.subscription.channelName - ? { ...subscription, latest: action.data.uri } - : subscription - ), - }), + ): SubscriptionState => { + const { subscription, uri } = action.data; + const newLatest = Object.assign({}, state.latest); + newLatest[subscription.uri] = uri; + + return { + ...state, + latest: newLatest, + }; + }, [ACTIONS.UPDATE_SUBSCRIPTION_UNREADS]: ( state: SubscriptionState, action: DoUpdateSubscriptionUnreads diff --git a/src/redux/selectors/stats.js b/src/redux/selectors/stats.js index 3071471..b5301c8 100644 --- a/src/redux/selectors/stats.js +++ b/src/redux/selectors/stats.js @@ -3,7 +3,6 @@ import { makeSelectClaimForUri } from 'lbry-redux'; const selectState = state => state.stats || {}; export const selectViewCount = createSelector(selectState, state => state.viewCountById); -export const selectSubCount = createSelector(selectState, state => state.subCountById); export const makeSelectViewCountForUri = uri => createSelector( @@ -11,10 +10,3 @@ export const makeSelectViewCountForUri = uri => selectViewCount, (claim, viewCountById) => viewCountById[claim.claim_id] || 0 ); - -export const makeSelectSubCountForUri = uri => - createSelector( - makeSelectClaimForUri(uri), - selectSubCount, - (claim, subCountById) => subCountById[claim.claim_id] || 0 - );