Skip to content

Commit

Permalink
Fix direct timeline pagination in the WebUI (mastodon#10126)
Browse files Browse the repository at this point in the history
The `hasMore` property of timelines in redux store was set whenever an API
request returned only one page of results, *even* if the query only requested
newer conversations (using `since_id`), causing `hasMore` to be incorrectly set to
false whenever fetching new toots in the direct timeline, which happens each time
the direct message column is opened.

(Basically mastodon#9516 for direct messages)
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 414a687 commit 1bcdb53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions app/javascript/mastodon/actions/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ export const expandConversations = ({ maxId } = {}) => (dispatch, getState) => {
params.since_id = getState().getIn(['conversations', 'items', 0, 'last_status']);
}

const isLoadingRecent = !!params.since_id;

api(getState).get('/api/v1/conversations', { params })
.then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');

dispatch(importFetchedAccounts(response.data.reduce((aggr, item) => aggr.concat(item.accounts), [])));
dispatch(importFetchedStatuses(response.data.map(item => item.last_status).filter(x => !!x)));
dispatch(expandConversationsSuccess(response.data, next ? next.uri : null));
dispatch(expandConversationsSuccess(response.data, next ? next.uri : null, isLoadingRecent));
})
.catch(err => dispatch(expandConversationsFail(err)));
};
Expand All @@ -56,10 +58,11 @@ export const expandConversationsRequest = () => ({
type: CONVERSATIONS_FETCH_REQUEST,
});

export const expandConversationsSuccess = (conversations, next) => ({
export const expandConversationsSuccess = (conversations, next, isLoadingRecent) => ({
type: CONVERSATIONS_FETCH_SUCCESS,
conversations,
next,
isLoadingRecent,
});

export const expandConversationsFail = error => ({
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/mastodon/reducers/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const updateConversation = (state, item) => state.update('items', list => {
}
});

const expandNormalizedConversations = (state, conversations, next) => {
const expandNormalizedConversations = (state, conversations, next, isLoadingRecent) => {
let items = ImmutableList(conversations.map(conversationToMap));

return state.withMutations(mutable => {
Expand Down Expand Up @@ -66,7 +66,7 @@ const expandNormalizedConversations = (state, conversations, next) => {
});
}

if (!next) {
if (!next && !isLoadingRecent) {
mutable.set('hasMore', false);
}

Expand All @@ -81,7 +81,7 @@ export default function conversations(state = initialState, action) {
case CONVERSATIONS_FETCH_FAIL:
return state.set('isLoading', false);
case CONVERSATIONS_FETCH_SUCCESS:
return expandNormalizedConversations(state, action.conversations, action.next);
return expandNormalizedConversations(state, action.conversations, action.next, action.isLoadingRecent);
case CONVERSATIONS_UPDATE:
return updateConversation(state, action.conversation);
case CONVERSATIONS_MOUNT:
Expand Down

0 comments on commit 1bcdb53

Please sign in to comment.