.
This commit is contained in:
parent
191c02af1e
commit
4c2764c747
19 changed files with 2605 additions and 95 deletions
53
src/services/timeline_fetcher/timeline_fetcher.service.js
Normal file
53
src/services/timeline_fetcher/timeline_fetcher.service.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { upperFirst, camelCase } from 'lodash';
|
||||
|
||||
const timelineFetcherServiceFactory = ($ngRedux, apiService, $interval) => {
|
||||
let fetcher;
|
||||
|
||||
const update = ({statuses, timeline, showImmediately}) => {
|
||||
const ccTimeline = camelCase(timeline);
|
||||
|
||||
const action = {
|
||||
type: 'ADD_NEW_STATUSES',
|
||||
data: {
|
||||
statuses,
|
||||
timeline: ccTimeline,
|
||||
showImmediately
|
||||
}
|
||||
};
|
||||
|
||||
$ngRedux.dispatch(action);
|
||||
$ngRedux.dispatch({type: 'UPDATE_TIMESTAMPS'});
|
||||
};
|
||||
|
||||
const fetchAndUpdate = ({timeline = 'friends', older = false, showImmediately = false}) => {
|
||||
const args = { timeline };
|
||||
const timelineData = $ngRedux.getState().statuses.timelines[camelCase(timeline)];
|
||||
|
||||
if(older) {
|
||||
args['until'] = timelineData.minVisibleId;
|
||||
} else {
|
||||
args['since'] = timelineData.maxId;
|
||||
}
|
||||
|
||||
apiService.fetchTimeline(args).
|
||||
then((statuses) => update({statuses, timeline, showImmediately}));
|
||||
};
|
||||
|
||||
const startFetching = ({timeline = 'friends'}) => {
|
||||
fetchAndUpdate({timeline, showImmediately: true});
|
||||
|
||||
const boundFetchAndUpdate = () => fetchAndUpdate({timeline});
|
||||
fetcher = $interval(boundFetchAndUpdate, 10000);
|
||||
};
|
||||
|
||||
const timelineFetcherService = {
|
||||
startFetching,
|
||||
fetchAndUpdate
|
||||
};
|
||||
|
||||
return timelineFetcherService;
|
||||
};
|
||||
|
||||
timelineFetcherServiceFactory.$inject = ['$ngRedux', 'apiService', '$interval'];
|
||||
|
||||
export default timelineFetcherServiceFactory;
|
Loading…
Add table
Add a link
Reference in a new issue