app/actions/views/channel.js
// Returns true if there are more posts to load
Returns true if there are more posts to load
Returns true if there are more posts to load
function increasePostVisibility(channelId, focusedPostId) {
    return async (dispatch, getState) => {
        const state = getState();
        const {loadingPosts, postVisibility} = state.views.channel;
        const currentPostVisibility = postVisibility[channelId] || 0;
        if (loadingPosts[channelId]) {
            return true;
        }
        dispatch(batchActions([
            {
                type: ViewTypes.LOADING_POSTS,
                data: true,
                channelId
            }
        ]));
        const page = Math.floor(currentPostVisibility / ViewTypes.POST_VISIBILITY_CHUNK_SIZE);
        let posts;
        if (focusedPostId) {
            posts = await getPostsBefore(channelId, focusedPostId, page, ViewTypes.POST_VISIBILITY_CHUNK_SIZE)(dispatch, getState);
        } else {
            posts = await getPosts(channelId, page, ViewTypes.POST_VISIBILITY_CHUNK_SIZE)(dispatch, getState);
        }
        if (posts) {
            dispatch({
                type: ViewTypes.INCREASE_POST_VISIBILITY,
                data: channelId,
                amount: ViewTypes.POST_VISIBILITY_CHUNK_SIZE
            });
        }
        dispatch({
            type: ViewTypes.LOADING_POSTS,
            data: false,
            channelId
        });
        return posts && posts.order.length >= ViewTypes.POST_VISIBILITY_CHUNK_SIZE;
    };
}
function increasePostVisibility ( channelId , focusedPostId ) { return async ( dispatch , getState ) => { const state = getState ( ) ; const { loadingPosts , postVisibility } = state . views . channel ; const currentPostVisibility = postVisibility [ channelId ] || 0 ; if ( loadingPosts [ channelId ] ) { return true ; } dispatch ( batchActions ( [ { type : ViewTypes . LOADING_POSTS , data : true , channelId } ] ) ) ; const page = Math . floor ( currentPostVisibility / ViewTypes . POST_VISIBILITY_CHUNK_SIZE ) ; let posts ; if ( focusedPostId ) { posts = await getPostsBefore ( channelId , focusedPostId , page , ViewTypes . POST_VISIBILITY_CHUNK_SIZE ) ( dispatch , getState ) ; } else { posts = await getPosts ( channelId , page , ViewTypes . POST_VISIBILITY_CHUNK_SIZE ) ( dispatch , getState ) ; } if ( posts ) { dispatch ( { type : ViewTypes . INCREASE_POST_VISIBILITY , data : channelId , amount : ViewTypes . POST_VISIBILITY_CHUNK_SIZE } ) ; } dispatch ( { type : ViewTypes . LOADING_POSTS , data : false , channelId } ) ; return posts && posts . order . length >= ViewTypes . POST_VISIBILITY_CHUNK_SIZE ; } ; }
Returns true if there are more posts to load
Returns true if there are more posts to load
// make sure to increment the posts visibility // only if we got results