From e49dc6a06eb18af023da82d60e485cd3c382fc96 Mon Sep 17 00:00:00 2001
From: unarist <m.unarist@gmail.com>
Date: Wed, 31 May 2017 22:30:26 +0900
Subject: [PATCH] Fix load more on account timelines (regression from #3311)
 (#3475)

This prevents `next` state from being overridden on the loading *new* statuses.
---
 app/javascript/mastodon/actions/accounts.js   | 8 ++++++--
 app/javascript/mastodon/reducers/timelines.js | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/app/javascript/mastodon/actions/accounts.js b/app/javascript/mastodon/actions/accounts.js
index 48ab7b6ed..405032460 100644
--- a/app/javascript/mastodon/actions/accounts.js
+++ b/app/javascript/mastodon/actions/accounts.js
@@ -107,7 +107,9 @@ export function fetchAccountTimeline(id, replace = false) {
     let params = {};
     let skipLoading = false;
 
-    if (newestId !== null && !replace) {
+    replace = replace || newestId === null;
+
+    if (!replace) {
       params.since_id = newestId;
       skipLoading = true;
     }
@@ -131,7 +133,9 @@ export function fetchAccountMediaTimeline(id, replace = false) {
     let params = { only_media: 'true', limit: 12 };
     let skipLoading = false;
 
-    if (newestId !== null && !replace) {
+    replace = replace || newestId === null;
+
+    if (!replace) {
       params.since_id = newestId;
       skipLoading = true;
     }
diff --git a/app/javascript/mastodon/reducers/timelines.js b/app/javascript/mastodon/reducers/timelines.js
index 0087a06ce..ab756b854 100644
--- a/app/javascript/mastodon/reducers/timelines.js
+++ b/app/javascript/mastodon/reducers/timelines.js
@@ -138,7 +138,7 @@ const normalizeAccountTimeline = (state, accountId, statuses, replace, next) =>
   return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
     .set('isLoading', false)
     .set('loaded', true)
-    .set('next', next)
+    .update('next', null, v => replace ? next : v)
     .update('items', Immutable.List(), list => (replace ? ids : ids.concat(list))));
 };
 
@@ -152,7 +152,7 @@ const normalizeAccountMediaTimeline = (state, accountId, statuses, replace, next
 
   return state.updateIn(['accounts_media_timelines', accountId], Immutable.Map(), map => map
     .set('isLoading', false)
-    .set('next', next)
+    .update('next', null, v => replace ? next : v)
     .update('items', Immutable.List(), list => (replace ? ids : ids.concat(list))));
 };