Don't show loading bar when re-loading already loaded status. Don't even try to fetch ancestors from DB when in_reply_to_id is nil
This commit is contained in:
		@@ -14,39 +14,43 @@ export const CONTEXT_FETCH_REQUEST = 'CONTEXT_FETCH_REQUEST';
 | 
				
			|||||||
export const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS';
 | 
					export const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS';
 | 
				
			||||||
export const CONTEXT_FETCH_FAIL    = 'CONTEXT_FETCH_FAIL';
 | 
					export const CONTEXT_FETCH_FAIL    = 'CONTEXT_FETCH_FAIL';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function fetchStatusRequest(id) {
 | 
					export function fetchStatusRequest(id, skipLoading) {
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    type: STATUS_FETCH_REQUEST,
 | 
					    type: STATUS_FETCH_REQUEST,
 | 
				
			||||||
    id: id
 | 
					    id,
 | 
				
			||||||
 | 
					    skipLoading
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function fetchStatus(id) {
 | 
					export function fetchStatus(id) {
 | 
				
			||||||
  return (dispatch, getState) => {
 | 
					  return (dispatch, getState) => {
 | 
				
			||||||
    dispatch(fetchStatusRequest(id));
 | 
					    const skipLoading = getState().getIn(['statuses', id], null) !== null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dispatch(fetchStatusRequest(id, skipLoading));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    api(getState).get(`/api/v1/statuses/${id}`).then(response => {
 | 
					    api(getState).get(`/api/v1/statuses/${id}`).then(response => {
 | 
				
			||||||
      dispatch(fetchStatusSuccess(response.data));
 | 
					      dispatch(fetchStatusSuccess(response.data, skipLoading));
 | 
				
			||||||
      dispatch(fetchContext(id));
 | 
					      dispatch(fetchContext(id));
 | 
				
			||||||
    }).catch(error => {
 | 
					    }).catch(error => {
 | 
				
			||||||
      dispatch(fetchStatusFail(id, error));
 | 
					      dispatch(fetchStatusFail(id, error, skipLoading));
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function fetchStatusSuccess(status, context) {
 | 
					export function fetchStatusSuccess(status, skipLoading) {
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    type: STATUS_FETCH_SUCCESS,
 | 
					    type: STATUS_FETCH_SUCCESS,
 | 
				
			||||||
    status: status,
 | 
					    status,
 | 
				
			||||||
    context: context
 | 
					    skipLoading
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function fetchStatusFail(id, error) {
 | 
					export function fetchStatusFail(id, error, skipLoading) {
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
    type: STATUS_FETCH_FAIL,
 | 
					    type: STATUS_FETCH_FAIL,
 | 
				
			||||||
    id: id,
 | 
					    id,
 | 
				
			||||||
    error: error
 | 
					    error,
 | 
				
			||||||
 | 
					    skipLoading
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@ class Api::V1::StatusesController < ApiController
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def context
 | 
					  def context
 | 
				
			||||||
    @context = OpenStruct.new(ancestors: @status.ancestors(current_account), descendants: @status.descendants(current_account))
 | 
					    @context = OpenStruct.new(ancestors: @status.in_reply_to_id.nil? ? [] : @status.ancestors(current_account), descendants: @status.descendants(current_account))
 | 
				
			||||||
    statuses = [@status] + @context[:ancestors] + @context[:descendants]
 | 
					    statuses = [@status] + @context[:ancestors] + @context[:descendants]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set_maps(statuses)
 | 
					    set_maps(statuses)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user