11import { importFetchedStatus , importFetchedStatuses } from './importer' ;
2- import api , { getLinks } from '.. /api' ;
2+ import api , { getLinks } from 'mastodon /api' ;
33import { Map as ImmutableMap , List as ImmutableList } from 'immutable' ;
4+ import compareId from 'mastodon/compare_id' ;
5+ import { usePendingItems as preferPendingItems } from 'mastodon/initial_state' ;
46
57export const TIMELINE_UPDATE = 'TIMELINE_UPDATE' ;
68export const TIMELINE_DELETE = 'TIMELINE_DELETE' ;
@@ -10,10 +12,15 @@ export const TIMELINE_EXPAND_REQUEST = 'TIMELINE_EXPAND_REQUEST';
1012export const TIMELINE_EXPAND_SUCCESS = 'TIMELINE_EXPAND_SUCCESS' ;
1113export const TIMELINE_EXPAND_FAIL = 'TIMELINE_EXPAND_FAIL' ;
1214
13- export const TIMELINE_SCROLL_TOP = 'TIMELINE_SCROLL_TOP' ;
15+ export const TIMELINE_SCROLL_TOP = 'TIMELINE_SCROLL_TOP' ;
16+ export const TIMELINE_LOAD_PENDING = 'TIMELINE_LOAD_PENDING' ;
17+ export const TIMELINE_DISCONNECT = 'TIMELINE_DISCONNECT' ;
18+ export const TIMELINE_CONNECT = 'TIMELINE_CONNECT' ;
1419
15- export const TIMELINE_CONNECT = 'TIMELINE_CONNECT' ;
16- export const TIMELINE_DISCONNECT = 'TIMELINE_DISCONNECT' ;
20+ export const loadPending = timeline => ( {
21+ type : TIMELINE_LOAD_PENDING ,
22+ timeline,
23+ } ) ;
1724
1825export function updateTimeline ( timeline , status , accept ) {
1926 return dispatch => {
@@ -27,6 +34,7 @@ export function updateTimeline(timeline, status, accept) {
2734 type : TIMELINE_UPDATE ,
2835 timeline,
2936 status,
37+ usePendingItems : preferPendingItems ,
3038 } ) ;
3139 } ;
3240} ;
@@ -71,8 +79,15 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
7179 return ;
7280 }
7381
74- if ( ! params . max_id && ! params . pinned && timeline . get ( 'items' , ImmutableList ( ) ) . size > 0 ) {
75- params . since_id = timeline . getIn ( [ 'items' , 0 ] ) ;
82+ if ( ! params . max_id && ! params . pinned && ( timeline . get ( 'items' , ImmutableList ( ) ) . size + timeline . get ( 'pendingItems' , ImmutableList ( ) ) . size ) > 0 ) {
83+ const a = timeline . getIn ( [ 'pendingItems' , 0 ] ) ;
84+ const b = timeline . getIn ( [ 'items' , 0 ] ) ;
85+
86+ if ( a && b && compareId ( a , b ) > 0 ) {
87+ params . since_id = a ;
88+ } else {
89+ params . since_id = b || a ;
90+ }
7691 }
7792
7893 const isLoadingRecent = ! ! params . since_id ;
@@ -82,7 +97,7 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
8297 api ( getState ) . get ( path , { params } ) . then ( response => {
8398 const next = getLinks ( response ) . refs . find ( link => link . rel === 'next' ) ;
8499 dispatch ( importFetchedStatuses ( response . data ) ) ;
85- dispatch ( expandTimelineSuccess ( timelineId , response . data , next ? next . uri : null , response . code === 206 , isLoadingRecent , isLoadingMore ) ) ;
100+ dispatch ( expandTimelineSuccess ( timelineId , response . data , next ? next . uri : null , response . code === 206 , isLoadingRecent , isLoadingMore , isLoadingRecent && preferPendingItems ) ) ;
86101 done ( ) ;
87102 } ) . catch ( error => {
88103 dispatch ( expandTimelineFail ( timelineId , error , isLoadingMore ) ) ;
@@ -115,14 +130,15 @@ export function expandTimelineRequest(timeline, isLoadingMore) {
115130 } ;
116131} ;
117132
118- export function expandTimelineSuccess ( timeline , statuses , next , partial , isLoadingRecent , isLoadingMore ) {
133+ export function expandTimelineSuccess ( timeline , statuses , next , partial , isLoadingRecent , isLoadingMore , usePendingItems ) {
119134 return {
120135 type : TIMELINE_EXPAND_SUCCESS ,
121136 timeline,
122137 statuses,
123138 next,
124139 partial,
125140 isLoadingRecent,
141+ usePendingItems,
126142 skipLoading : ! isLoadingMore ,
127143 } ;
128144} ;
@@ -151,9 +167,8 @@ export function connectTimeline(timeline) {
151167 } ;
152168} ;
153169
154- export function disconnectTimeline ( timeline ) {
155- return {
156- type : TIMELINE_DISCONNECT ,
157- timeline,
158- } ;
159- } ;
170+ export const disconnectTimeline = timeline => ( {
171+ type : TIMELINE_DISCONNECT ,
172+ timeline,
173+ usePendingItems : preferPendingItems ,
174+ } ) ;
0 commit comments