Merge pull request #61 from lbryio/latest-subscription
move subscription latest to separate property
This commit is contained in:
commit
d99232ebc7
4 changed files with 46 additions and 32 deletions
22
dist/bundle.es.js
vendored
22
dist/bundle.es.js
vendored
|
@ -504,6 +504,7 @@ const handleActions = (actionMap, defaultState) => (state = defaultState, action
|
|||
const defaultState = {
|
||||
enabledChannelNotifications: [],
|
||||
subscriptions: [],
|
||||
latest: {},
|
||||
unread: {},
|
||||
suggested: {},
|
||||
loading: false,
|
||||
|
@ -539,11 +540,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 +1715,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 +1738,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
|
@ -1234,6 +1234,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|||
var defaultState = {
|
||||
enabledChannelNotifications: [],
|
||||
subscriptions: [],
|
||||
latest: {},
|
||||
unread: {},
|
||||
suggested: {},
|
||||
loading: false,
|
||||
|
@ -1266,18 +1267,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 +1287,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 +3077,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 +3099,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