From 4a1647a41efc6538f98b010713fc0419047093fc Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Tue, 24 Sep 2019 22:30:53 -0400 Subject: [PATCH 1/2] feat: add sub counts --- dist/bundle.es.js | 60 ++++++++++++++++++++++++++-- dist/bundle.js | 73 +++++++++++++++++++++++++++++++++-- src/constants/action_types.js | 5 ++- src/index.js | 4 +- src/redux/actions/stats.js | 16 ++++++++ src/redux/reducers/stats.js | 18 +++++++++ src/redux/selectors/stats.js | 8 ++++ 7 files changed, 175 insertions(+), 9 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 76d73c3..4e838f0 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -72,11 +72,14 @@ 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'; // File Stats +const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // 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'; // Cross-device Sync +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 GET_SYNC_STARTED = 'GET_SYNC_STARTED'; const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; @@ -151,6 +154,9 @@ 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, @@ -2166,6 +2172,28 @@ 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 => { @@ -2864,7 +2892,10 @@ const homepageReducer = handleActions({ const defaultState$8 = { fetchingViewCount: false, viewCountError: undefined, - viewCountById: {} + viewCountById: {}, + fetchingSubCount: false, + subCountError: undefined, + subCountById: {} }; const statsReducer = handleActions({ [FETCH_VIEW_COUNT_STARTED]: state => ({ ...state, @@ -2885,6 +2916,25 @@ 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); @@ -2979,7 +3029,9 @@ 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 || {}; @@ -3020,6 +3072,7 @@ exports.doFetchInviteStatus = doFetchInviteStatus; exports.doFetchMySubscriptions = doFetchMySubscriptions; exports.doFetchRecommendedSubscriptions = doFetchRecommendedSubscriptions; exports.doFetchRewardedContent = doFetchRewardedContent; +exports.doFetchSubCount = doFetchSubCount; exports.doFetchTrendingUris = doFetchTrendingUris; exports.doFetchViewCount = doFetchViewCount; exports.doFilteredOutpointsSubscribe = doFilteredOutpointsSubscribe; @@ -3058,6 +3111,7 @@ 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 eb3b850..9d6a0fd 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -215,6 +215,8 @@ __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"]; }); @@ -416,6 +418,8 @@ __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"]; }); @@ -547,6 +551,9 @@ __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; }); @@ -620,11 +627,14 @@ 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'; // File Stats +var FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // 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'; // Cross-device Sync +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 GET_SYNC_STARTED = 'GET_SYNC_STARTED'; var GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED'; @@ -3664,6 +3674,7 @@ 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); @@ -3692,6 +3703,30 @@ 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 */ @@ -4574,7 +4609,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope var defaultState = { fetchingViewCount: false, viewCountError: undefined, - viewCountById: {} + viewCountById: {}, + fetchingSubCount: false, + subCountError: undefined, + subCountById: {} }; 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, { @@ -4595,6 +4633,25 @@ 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); /***/ }), @@ -4819,7 +4876,9 @@ 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); @@ -4834,11 +4893,19 @@ 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 ca70262..edfbf43 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -71,10 +71,13 @@ 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'; -// File Stats +// 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 c81498b..32252e9 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 } from 'redux/actions/stats'; +export { doFetchViewCount, doFetchSubCount } from 'redux/actions/stats'; export { doCheckSync, doGetSync, @@ -170,7 +170,7 @@ export { selectTrendingUris, selectFetchingTrendingUris, } from 'redux/selectors/homepage'; -export { makeSelectViewCountForUri } from 'redux/selectors/stats'; +export { makeSelectViewCountForUri, makeSelectSubCountForUri } from 'redux/selectors/stats'; export { selectHasSyncedWallet, selectSyncData, diff --git a/src/redux/actions/stats.js b/src/redux/actions/stats.js index ac00620..14f96fa 100644 --- a/src/redux/actions/stats.js +++ b/src/redux/actions/stats.js @@ -14,3 +14,19 @@ 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/reducers/stats.js b/src/redux/reducers/stats.js index 134e2b2..0b4cfe5 100644 --- a/src/redux/reducers/stats.js +++ b/src/redux/reducers/stats.js @@ -5,6 +5,9 @@ const defaultState = { fetchingViewCount: false, viewCountError: undefined, viewCountById: {}, + fetchingSubCount: false, + subCountError: undefined, + subCountById: {}, }; export const statsReducer = handleActions( @@ -24,6 +27,21 @@ 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/selectors/stats.js b/src/redux/selectors/stats.js index b5301c8..3071471 100644 --- a/src/redux/selectors/stats.js +++ b/src/redux/selectors/stats.js @@ -3,6 +3,7 @@ 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( @@ -10,3 +11,10 @@ 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 + ); -- 2.45.2 From c55a2c98ab92c72149c824ee5906aed4404fd89b Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 30 Sep 2019 17:24:24 +0100 Subject: [PATCH 2/2] move subscription latest to separate property --- dist/bundle.es.js | 22 +++++++++++++------- dist/bundle.js | 31 ++++++++++++++++------------- src/redux/actions/subscriptions.js | 5 +++-- src/redux/reducers/subscriptions.js | 20 ++++++++++--------- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index d8b4ede..82c420d 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -498,6 +498,7 @@ const handleActions = (actionMap, defaultState) => (state = defaultState, action const defaultState = { enabledChannelNotifications: [], subscriptions: [], + latest: {}, unread: {}, suggested: {}, loading: false, @@ -533,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, @@ -1702,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`); @@ -1724,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 => { diff --git a/dist/bundle.js b/dist/bundle.js index a5a85b8..86011ec 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -1224,6 +1224,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope var defaultState = { enabledChannelNotifications: [], subscriptions: [], + latest: {}, unread: {}, suggested: {}, loading: false, @@ -1256,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, @@ -1275,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; @@ -3065,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")); @@ -3086,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) { 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/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 -- 2.45.2