diff options
| author | Roger Braun <roger@rogerbraun.net> | 2016-11-13 22:09:27 +0100 |
|---|---|---|
| committer | Roger Braun <roger@rogerbraun.net> | 2016-11-13 22:19:14 +0100 |
| commit | 5888697c0dccb02eb3fdefba28bc359c32ec264e (patch) | |
| tree | 2c2700d77f1e30cd9c0cd3427cf81b6192ed4899 /src | |
| parent | 5e348dc14927737fc1fceed4e66537c715997126 (diff) | |
Better maxId calculation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/modules/statuses.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 8238644d..6fe2558c 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -1,4 +1,4 @@ -import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find } from 'lodash' +import { reduce, map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy, differenceBy, each, find, flatten, maxBy } from 'lodash' import moment from 'moment' import apiService from '../services/api/api.service.js' import parse from '../services/status_parser/status_parser.js' @@ -41,7 +41,7 @@ const statusType = (status) => { return !status.is_post_verb && status.uri.match(/fave/) ? 'fave' : 'status' } -const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visibleStatuses, newStatusCount, faves, loading }) => { +const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visibleStatuses, newStatusCount, faves, loading, maxId }) => { const statusesAndFaves = groupBy(addedStatuses, statusType) const addedFaves = statusesAndFaves['fave'] || [] const unseenFaves = differenceBy(addedFaves, faves, 'id') @@ -92,9 +92,9 @@ const addStatusesToTimeline = (addedStatuses, showImmediately, { statuses, visib statuses: newStatuses, visibleStatuses: newVisibleStatuses, newStatusCount: newNewStatusCount, - maxId: newStatuses[0].id, minVisibleId: (last(newVisibleStatuses) || { id: undefined }).id, faves: unionBy(faves, addedFaves, 'id'), + maxId, loading } } @@ -109,8 +109,18 @@ const updateTimestampsInStatuses = (statuses) => { }) } + +export const findMaxId = (...args) => { + return (maxBy(flatten(args), 'id') || {}).id +} + export const mutations = { addNewStatuses (state, { statuses, showImmediately = false, timeline }) { + const timelineObject = state.timelines[timeline] + + // Set new maxId + const maxId = findMaxId(statuses, timelineObject.statuses) + timelineObject.maxId = maxId state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[timeline]) state.allStatuses = unionBy(state.timelines[timeline].statuses, state.allStatuses, 'id') |
