@@ -89,46 +89,37 @@ const setFailed = (state: State, timelineId: string, failed: boolean) => {
8989 return state . update ( timelineId , TimelineRecord ( ) , timeline => timeline . set ( 'loadingFailed' , failed ) ) ;
9090} ;
9191
92- const expandNormalizedTimeline = ( state : State , timelineId : string , statuses : ImmutableList < ImmutableMap < string , any > > , next : string | null , isPartial : boolean , isLoadingRecent : boolean , isLoadingMore : boolean ) => {
93- let newIds = getStatusIds ( statuses ) ;
94- let unseens = ImmutableOrderedSet < any > ( ) ;
95-
92+ const expandNormalizedTimeline = ( state : State , timelineId : string , retrievedStatus : ImmutableList < ImmutableMap < string , any > > , next : string | null , isPartial : boolean , isLoadingNewer : boolean , isLoadingOlder : boolean ) => {
93+ let retrievedStatusIds = getStatusIds ( retrievedStatus ) ;
94+ let unpublishedStatusIds = ImmutableOrderedSet < any > ( ) ;
9695 return state . withMutations ( ( s ) => {
9796 s . update ( timelineId , TimelineRecord ( ) , timeline => timeline . withMutations ( timeline => {
9897 timeline . set ( 'isLoading' , false ) ;
9998 timeline . set ( 'loadingFailed' , false ) ;
10099 timeline . set ( 'isPartial' , isPartial ) ;
101-
102- if ( ! next && ! isLoadingRecent ) timeline . set ( 'hasMore' , false ) ;
103-
100+ if ( ! next && ! isLoadingNewer ) timeline . set ( 'hasMore' , false ) ;
104101 // Pinned timelines can be replaced entirely
105102 if ( timelineId . endsWith ( ':pinned' ) ) {
106- timeline . set ( 'items' , newIds ) ;
103+ timeline . set ( 'items' , retrievedStatusIds ) ;
107104 return ;
108105 }
106+ // if we arent loading older or newer posts and that we are not building the initial render
107+ if ( ! isLoadingNewer && ! isLoadingOlder && timeline . items . count ( ) > 0 ) {
108+ unpublishedStatusIds = retrievedStatusIds . subtract ( timeline . items ) ;
109+ retrievedStatusIds = retrievedStatusIds . subtract ( unpublishedStatusIds ) ;
110+ }
109111
110- if ( ! newIds . isEmpty ( ) ) {
111- // we need to sort between queue and actual list to avoid
112- // messing with user position in the timeline by inserting inseen statuses
113- unseens = ImmutableOrderedSet < any > ( ) ;
114- if ( ! isLoadingMore
115- && timeline . items . count ( ) > 0
116- && newIds . first ( ) > timeline . items . first ( )
117- ) {
118- unseens = newIds . subtract ( timeline . items ) ;
119- }
120-
121- newIds = newIds . subtract ( unseens ) ;
122- timeline . update ( 'items' , oldIds => {
123- if ( newIds . first ( ) > oldIds . first ( ) ! ) {
124- return mergeStatusIds ( oldIds , newIds ) ;
112+ if ( ! retrievedStatusIds . isEmpty ( ) ) {
113+ timeline . update ( 'items' , statusInTimelineIds => {
114+ if ( isLoadingOlder ) {
115+ return mergeStatusIds ( retrievedStatusIds , statusInTimelineIds ) ;
125116 } else {
126- return mergeStatusIds ( newIds , oldIds ) ;
117+ return mergeStatusIds ( statusInTimelineIds , retrievedStatusIds ) ;
127118 }
128119 } ) ;
129120 }
130121 } ) ) ;
131- unseens . forEach ( ( statusId ) => s . set ( timelineId , updateTimelineQueue ( s , timelineId , statusId ) . get ( timelineId ) ) ) ;
122+ unpublishedStatusIds . forEach ( ( statusId ) => s . set ( timelineId , updateTimelineQueue ( s , timelineId , statusId ) . get ( timelineId ) ) ) ;
132123 } ) ;
133124} ;
134125
@@ -341,7 +332,7 @@ export default function timelines(state: State = initialState, action: AnyAction
341332 case TIMELINE_EXPAND_FAIL :
342333 return handleExpandFail ( state , action . timeline ) ;
343334 case TIMELINE_EXPAND_SUCCESS :
344- return expandNormalizedTimeline ( state , action . timeline , fromJS ( action . statuses ) as ImmutableList < ImmutableMap < string , any > > , action . next , action . partial , action . isLoadingRecent , action . isLoadingMore ) ;
335+ return expandNormalizedTimeline ( state , action . timeline , fromJS ( action . statuses ) as ImmutableList < ImmutableMap < string , any > > , action . next , action . partial , action . isLoadingNewer , action . isLoadingOlder ) ;
345336 case TIMELINE_UPDATE :
346337 return updateTimeline ( state , action . timeline , action . statusId ) ;
347338 case TIMELINE_UPDATE_QUEUE :
0 commit comments