From b3263e528fa8f7dc7ea76c045ef2ae3f24c331ff Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 10 Mar 2018 10:54:16 -0800 Subject: [PATCH] fix incoming statuses, add tests --- routes/_actions/timeline.js | 35 ++++++++------- routes/_components/timeline/MoreHeader.html | 2 +- routes/_components/timeline/Timeline.html | 14 +++--- routes/_database/timelines.js | 2 +- routes/_static/media.js | 2 +- .../{_database/utils.js => _utils/sorting.js} | 6 +++ tests/serverActions.js | 10 +++++ tests/spec/104-streaming.js | 44 +++++++++++++++++++ tests/utils.js | 7 +++ 9 files changed, 98 insertions(+), 24 deletions(-) rename routes/{_database/utils.js => _utils/sorting.js} (66%) create mode 100644 tests/spec/104-streaming.js diff --git a/routes/_actions/timeline.js b/routes/_actions/timeline.js index 403181fe..2b087519 100644 --- a/routes/_actions/timeline.js +++ b/routes/_actions/timeline.js @@ -4,6 +4,7 @@ import { getTimeline } from '../_api/timelines' import { toast } from '../_utils/toast' import { mark, stop } from '../_utils/marks' import { mergeArrays } from '../_utils/arrays' +import { byItemIds } from '../_utils/sorting' const FETCH_LIMIT = 20 @@ -74,39 +75,41 @@ export async function setupTimeline () { stop('setupTimeline') } -export async function fetchTimelineItemsOnScrollToBottom () { - let timelineName = store.get('currentTimeline') - let instanceName = store.get('currentInstance') +export async function fetchTimelineItemsOnScrollToBottom (instanceName, timelineName) { store.setForTimeline(instanceName, timelineName, { runningUpdate: true }) await fetchTimelineItemsAndPossiblyFallBack() store.setForTimeline(instanceName, timelineName, { runningUpdate: false }) } -export async function showMoreItemsForCurrentTimeline () { - mark('showMoreItemsForCurrentTimeline') - let instanceName = store.get('currentInstance') - let timelineName = store.get('currentTimeline') - let itemIdsToAdd = store.get('itemIdsToAdd') +export async function showMoreItemsForTimeline (instanceName, timelineName) { + mark('showMoreItemsForTimeline') + let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') + itemIdsToAdd = itemIdsToAdd.sort(byItemIds).reverse() addTimelineItemIds(instanceName, timelineName, itemIdsToAdd) store.setForTimeline(instanceName, timelineName, { itemIdsToAdd: [], shouldShowHeader: false, showHeader: false }) - stop('showMoreItemsForCurrentTimeline') + stop('showMoreItemsForTimeline') } -export async function showMoreItemsForCurrentThread () { - mark('showMoreItemsForCurrentThread') - let instanceName = store.get('currentInstance') - let timelineName = store.get('currentTimeline') - let itemIdsToAdd = store.get('itemIdsToAdd') - // TODO: update database and do the thread merge correctly +export async function showMoreItemsForCurrentTimeline () { + return showMoreItemsForTimeline( + store.get('currentInstance'), + store.get('currentTimeline') + ) +} + +export async function showMoreItemsForThread (instanceName, timelineName) { + mark('showMoreItemsForThread') + let itemIdsToAdd = store.getForTimeline(instanceName, timelineName, 'itemIdsToAdd') let timelineItemIds = store.getForTimeline(instanceName, timelineName, 'timelineItemIds') + // TODO: update database and do the thread merge correctly timelineItemIds = timelineItemIds.concat(itemIdsToAdd) store.setForTimeline(instanceName, timelineName, { itemIdsToAdd: [], timelineItemIds: timelineItemIds }) - stop('showMoreItemsForCurrentThread') + stop('showMoreItemsForThread') } diff --git a/routes/_components/timeline/MoreHeader.html b/routes/_components/timeline/MoreHeader.html index 2c86e9cc..fc6079aa 100644 --- a/routes/_components/timeline/MoreHeader.html +++ b/routes/_components/timeline/MoreHeader.html @@ -1,6 +1,6 @@