From 47bf7a8047ce59b899d147e4483168f9852eeb7c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 11 Jun 2017 17:07:35 +0200 Subject: Fix #3665 - Refactor timelines reducer (#3686) * Move ancestors/descendants out of timelines reducer * Refactor timelines reducer All types of timelines now have a flat structure and use the same reducer functions and actions * Reintroduce some missing behaviours * Fix wrong import in reports * Fix includes typo * Fix issue related to "next" pagination in timelines and notifications * Fix bug with timeline's initial state, expandNotifications --- app/javascript/mastodon/actions/accounts.js | 215 ---------------------------- 1 file changed, 215 deletions(-) (limited to 'app/javascript/mastodon/actions/accounts.js') diff --git a/app/javascript/mastodon/actions/accounts.js b/app/javascript/mastodon/actions/accounts.js index 405032460..a862798f9 100644 --- a/app/javascript/mastodon/actions/accounts.js +++ b/app/javascript/mastodon/actions/accounts.js @@ -29,22 +29,6 @@ export const ACCOUNT_UNMUTE_REQUEST = 'ACCOUNT_UNMUTE_REQUEST'; export const ACCOUNT_UNMUTE_SUCCESS = 'ACCOUNT_UNMUTE_SUCCESS'; export const ACCOUNT_UNMUTE_FAIL = 'ACCOUNT_UNMUTE_FAIL'; -export const ACCOUNT_TIMELINE_FETCH_REQUEST = 'ACCOUNT_TIMELINE_FETCH_REQUEST'; -export const ACCOUNT_TIMELINE_FETCH_SUCCESS = 'ACCOUNT_TIMELINE_FETCH_SUCCESS'; -export const ACCOUNT_TIMELINE_FETCH_FAIL = 'ACCOUNT_TIMELINE_FETCH_FAIL'; - -export const ACCOUNT_TIMELINE_EXPAND_REQUEST = 'ACCOUNT_TIMELINE_EXPAND_REQUEST'; -export const ACCOUNT_TIMELINE_EXPAND_SUCCESS = 'ACCOUNT_TIMELINE_EXPAND_SUCCESS'; -export const ACCOUNT_TIMELINE_EXPAND_FAIL = 'ACCOUNT_TIMELINE_EXPAND_FAIL'; - -export const ACCOUNT_MEDIA_TIMELINE_FETCH_REQUEST = 'ACCOUNT_MEDIA_TIMELINE_FETCH_REQUEST'; -export const ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS = 'ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS'; -export const ACCOUNT_MEDIA_TIMELINE_FETCH_FAIL = 'ACCOUNT_MEDIA_TIMELINE_FETCH_FAIL'; - -export const ACCOUNT_MEDIA_TIMELINE_EXPAND_REQUEST = 'ACCOUNT_MEDIA_TIMELINE_EXPAND_REQUEST'; -export const ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS = 'ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS'; -export const ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL = 'ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL'; - export const FOLLOWERS_FETCH_REQUEST = 'FOLLOWERS_FETCH_REQUEST'; export const FOLLOWERS_FETCH_SUCCESS = 'FOLLOWERS_FETCH_SUCCESS'; export const FOLLOWERS_FETCH_FAIL = 'FOLLOWERS_FETCH_FAIL'; @@ -99,99 +83,6 @@ export function fetchAccount(id) { }; }; -export function fetchAccountTimeline(id, replace = false) { - return (dispatch, getState) => { - const ids = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List()); - const newestId = ids.size > 0 ? ids.first() : null; - - let params = {}; - let skipLoading = false; - - replace = replace || newestId === null; - - if (!replace) { - params.since_id = newestId; - skipLoading = true; - } - - dispatch(fetchAccountTimelineRequest(id, skipLoading)); - - api(getState).get(`/api/v1/accounts/${id}/statuses`, { params }).then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); - dispatch(fetchAccountTimelineSuccess(id, response.data, replace, skipLoading, next)); - }).catch(error => { - dispatch(fetchAccountTimelineFail(id, error, skipLoading)); - }); - }; -}; - -export function fetchAccountMediaTimeline(id, replace = false) { - return (dispatch, getState) => { - const ids = getState().getIn(['timelines', 'accounts_media_timelines', id, 'items'], Immutable.List()); - const newestId = ids.size > 0 ? ids.first() : null; - - let params = { only_media: 'true', limit: 12 }; - let skipLoading = false; - - replace = replace || newestId === null; - - if (!replace) { - params.since_id = newestId; - skipLoading = true; - } - - dispatch(fetchAccountMediaTimelineRequest(id, skipLoading)); - - api(getState).get(`/api/v1/accounts/${id}/statuses`, { params }).then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); - dispatch(fetchAccountMediaTimelineSuccess(id, response.data, replace, skipLoading, next)); - }).catch(error => { - dispatch(fetchAccountMediaTimelineFail(id, error, skipLoading)); - }); - }; -}; - -export function expandAccountTimeline(id) { - return (dispatch, getState) => { - const lastId = getState().getIn(['timelines', 'accounts_timelines', id, 'items'], Immutable.List()).last(); - - dispatch(expandAccountTimelineRequest(id)); - - api(getState).get(`/api/v1/accounts/${id}/statuses`, { - params: { - limit: 10, - max_id: lastId, - }, - }).then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); - dispatch(expandAccountTimelineSuccess(id, response.data, next)); - }).catch(error => { - dispatch(expandAccountTimelineFail(id, error)); - }); - }; -}; - -export function expandAccountMediaTimeline(id) { - return (dispatch, getState) => { - const lastId = getState().getIn(['timelines', 'accounts_media_timelines', id, 'items'], Immutable.List()).last(); - - dispatch(expandAccountMediaTimelineRequest(id)); - - api(getState).get(`/api/v1/accounts/${id}/statuses`, { - params: { - limit: 12, - only_media: 'true', - max_id: lastId, - }, - }).then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); - dispatch(expandAccountMediaTimelineSuccess(id, response.data, next)); - }).catch(error => { - dispatch(expandAccountMediaTimelineFail(id, error)); - }); - }; -}; - export function fetchAccountRequest(id) { return { type: ACCOUNT_FETCH_REQUEST, @@ -281,112 +172,6 @@ export function unfollowAccountFail(error) { }; }; -export function fetchAccountTimelineRequest(id, skipLoading) { - return { - type: ACCOUNT_TIMELINE_FETCH_REQUEST, - id, - skipLoading, - }; -}; - -export function fetchAccountTimelineSuccess(id, statuses, replace, skipLoading, next) { - return { - type: ACCOUNT_TIMELINE_FETCH_SUCCESS, - id, - statuses, - replace, - skipLoading, - next, - }; -}; - -export function fetchAccountTimelineFail(id, error, skipLoading) { - return { - type: ACCOUNT_TIMELINE_FETCH_FAIL, - id, - error, - skipLoading, - skipAlert: error.response.status === 404, - }; -}; - -export function fetchAccountMediaTimelineRequest(id, skipLoading) { - return { - type: ACCOUNT_MEDIA_TIMELINE_FETCH_REQUEST, - id, - skipLoading, - }; -}; - -export function fetchAccountMediaTimelineSuccess(id, statuses, replace, skipLoading, next) { - return { - type: ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS, - id, - statuses, - replace, - skipLoading, - next, - }; -}; - -export function fetchAccountMediaTimelineFail(id, error, skipLoading) { - return { - type: ACCOUNT_MEDIA_TIMELINE_FETCH_FAIL, - id, - error, - skipLoading, - skipAlert: error.response.status === 404, - }; -}; - -export function expandAccountTimelineRequest(id) { - return { - type: ACCOUNT_TIMELINE_EXPAND_REQUEST, - id, - }; -}; - -export function expandAccountTimelineSuccess(id, statuses, next) { - return { - type: ACCOUNT_TIMELINE_EXPAND_SUCCESS, - id, - statuses, - next, - }; -}; - -export function expandAccountTimelineFail(id, error) { - return { - type: ACCOUNT_TIMELINE_EXPAND_FAIL, - id, - error, - }; -}; - -export function expandAccountMediaTimelineRequest(id) { - return { - type: ACCOUNT_MEDIA_TIMELINE_EXPAND_REQUEST, - id, - }; -}; - -export function expandAccountMediaTimelineSuccess(id, statuses, next) { - return { - type: ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS, - id, - statuses, - next, - }; -}; - -export function expandAccountMediaTimelineFail(id, error) { - return { - type: ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL, - id, - error, - }; -}; - export function blockAccount(id) { return (dispatch, getState) => { dispatch(blockAccountRequest(id)); -- cgit