move subscription latest to separate property #61
4 changed files with 46 additions and 32 deletions
22
dist/bundle.es.js
vendored
22
dist/bundle.es.js
vendored
|
@ -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 => {
|
||||
|
|
31
dist/bundle.js
vendored
31
dist/bundle.js
vendored
|
@ -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) {
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue