Commiting
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import api from '../api'
|
||||
import { importFetchedAccounts, importFetchedStatus } from './importer'
|
||||
import api, { getLinks } from '../api'
|
||||
import {
|
||||
importFetchedAccounts,
|
||||
importFetchedStatus,
|
||||
} from './importer'
|
||||
import { fetchRelationships } from './accounts'
|
||||
import { updateStatusStats } from './statuses'
|
||||
import { me } from '../initial_state'
|
||||
|
||||
@@ -23,6 +27,10 @@ export const REPOSTS_FETCH_REQUEST = 'REPOSTS_FETCH_REQUEST'
|
||||
export const REPOSTS_FETCH_SUCCESS = 'REPOSTS_FETCH_SUCCESS'
|
||||
export const REPOSTS_FETCH_FAIL = 'REPOSTS_FETCH_FAIL'
|
||||
|
||||
export const REPOSTS_EXPAND_REQUEST = 'REPOSTS_EXPAND_REQUEST'
|
||||
export const REPOSTS_EXPAND_SUCCESS = 'REPOSTS_EXPAND_SUCCESS'
|
||||
export const REPOSTS_EXPAND_FAIL = 'REPOSTS_EXPAND_FAIL'
|
||||
|
||||
export const PIN_REQUEST = 'PIN_REQUEST'
|
||||
export const PIN_SUCCESS = 'PIN_SUCCESS'
|
||||
export const PIN_FAIL = 'PIN_FAIL'
|
||||
@@ -31,6 +39,10 @@ export const UNPIN_REQUEST = 'UNPIN_REQUEST'
|
||||
export const UNPIN_SUCCESS = 'UNPIN_SUCCESS'
|
||||
export const UNPIN_FAIL = 'UNPIN_FAIL'
|
||||
|
||||
export const IS_PIN_REQUEST = 'IS_PIN_REQUEST'
|
||||
export const IS_PIN_SUCCESS = 'IS_PIN_SUCCESS'
|
||||
export const IS_PIN_FAIL = 'IS_PIN_FAIL'
|
||||
|
||||
export const BOOKMARK_REQUEST = 'BOOKMARK_REQUEST'
|
||||
export const BOOKMARK_SUCCESS = 'BOOKMARK_SUCCESS'
|
||||
export const BOOKMARK_FAIL = 'BOOKMARK_FAIL'
|
||||
@@ -39,342 +51,512 @@ export const UNBOOKMARK_REQUEST = 'UNBOOKMARK_REQUEST'
|
||||
export const UNBOOKMARK_SUCCESS = 'UNBOOKMARK_SUCCESS'
|
||||
export const UNBOOKMARK_FAIL = 'UNBOOKMARK_FAIL'
|
||||
|
||||
export const IS_BOOKMARK_REQUEST = 'IS_BOOKMARK_REQUEST'
|
||||
export const IS_BOOKMARK_SUCCESS = 'IS_BOOKMARK_SUCCESS'
|
||||
export const IS_BOOKMARK_FAIL = 'IS_BOOKMARK_FAIL'
|
||||
|
||||
export const LIKES_FETCH_REQUEST = 'LIKES_FETCH_REQUEST'
|
||||
export const LIKES_FETCH_SUCCESS = 'LIKES_FETCH_SUCCESS'
|
||||
export const LIKES_FETCH_FAIL = 'LIKES_FETCH_FAIL'
|
||||
|
||||
export const LIKES_EXPAND_REQUEST = 'LIKES_EXPAND_REQUEST'
|
||||
export const LIKES_EXPAND_SUCCESS = 'LIKES_EXPAND_SUCCESS'
|
||||
export const LIKES_EXPAND_FAIL = 'LIKES_EXPAND_FAIL'
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Repost the given status. Set status to status.reblogged:true and
|
||||
* increment status.reblogs_count by 1 on success.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const repost = (status) => (dispatch, getState) => {
|
||||
if (!me) return
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(repostRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then((response) => {
|
||||
// The reblog API method returns a new status wrapped around the original. In this case we are only
|
||||
// interested in how the original is modified, hence passing it skipping the wrapper
|
||||
dispatch(importFetchedStatus(response.data.reblog))
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(repostSuccess(status))
|
||||
}).catch((error) => {
|
||||
dispatch(repostFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const repostRequest = (status) => ({
|
||||
const repostRequest = (status) => ({
|
||||
type: REPOST_REQUEST,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
status,
|
||||
})
|
||||
|
||||
export const repostSuccess = (status) => ({
|
||||
const repostSuccess = (status) => ({
|
||||
type: REPOST_SUCCESS,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
status,
|
||||
})
|
||||
|
||||
export const repostFail = (status, error) => ({
|
||||
const repostFail = (status, error) => ({
|
||||
type: REPOST_FAIL,
|
||||
status: status,
|
||||
error: error,
|
||||
skipLoading: true,
|
||||
status,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Unrepost the given status. Set status to status.reblogged:false and
|
||||
* decrement status.reblogs_count by 1 on success.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const unrepost = (status) => (dispatch, getState) => {
|
||||
if (!me) return
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(unrepostRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then((response) => {
|
||||
dispatch(importFetchedStatus(response.data))
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(unrepostSuccess(status))
|
||||
}).catch((error) => {
|
||||
dispatch(unrepostFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const unrepostRequest = (status) => ({
|
||||
const unrepostRequest = (status) => ({
|
||||
type: UNREPOST_REQUEST,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
status,
|
||||
})
|
||||
|
||||
export const unrepostSuccess = (status) => ({
|
||||
const unrepostSuccess = (status) => ({
|
||||
type: UNREPOST_SUCCESS,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
status,
|
||||
})
|
||||
|
||||
export const unrepostFail = (status, error) => ({
|
||||
const unrepostFail = (status, error) => ({
|
||||
type: UNREPOST_FAIL,
|
||||
status: status,
|
||||
error: error,
|
||||
skipLoading: true,
|
||||
status,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Favorite the given status. Set status to status.favourited:true and
|
||||
* increment status.favourites_count by 1 on success.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const favorite = (status) => (dispatch, getState) => {
|
||||
if (!me) return
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(favoriteRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then((response) => {
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(favoriteSuccess(status))
|
||||
dispatch(favoriteSuccess(response.data))
|
||||
}).catch((error) => {
|
||||
dispatch(favoriteFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const favoriteRequest = (status) => ({
|
||||
const favoriteRequest = (status) => ({
|
||||
type: FAVORITE_REQUEST,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
status,
|
||||
})
|
||||
|
||||
export const favoriteSuccess = (status) => ({
|
||||
const favoriteSuccess = (data) => ({
|
||||
type: FAVORITE_SUCCESS,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
data,
|
||||
})
|
||||
|
||||
export const favoriteFail = (status, error) => ({
|
||||
const favoriteFail = (status, error) => ({
|
||||
type: FAVORITE_FAIL,
|
||||
status: status,
|
||||
error: error,
|
||||
skipLoading: true,
|
||||
status,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Unfavorite the given status. Set status to status.favourited:false and
|
||||
* decrement status.favourites_count by 1 on success.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const unfavorite = (status) => (dispatch, getState) => {
|
||||
if (!me) return
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(unfavoriteRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then((response) => {
|
||||
dispatch(importFetchedStatus(response.data))
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(unfavoriteSuccess(status))
|
||||
}).catch((error) => {
|
||||
dispatch(unfavoriteFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const unfavoriteRequest = (status) => ({
|
||||
const unfavoriteRequest = (status) => ({
|
||||
type: UNFAVORITE_REQUEST,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
status,
|
||||
})
|
||||
|
||||
export const unfavoriteSuccess = (status) => ({
|
||||
const unfavoriteSuccess = (status) => ({
|
||||
type: UNFAVORITE_SUCCESS,
|
||||
status: status,
|
||||
skipLoading: true,
|
||||
status,
|
||||
})
|
||||
|
||||
export const unfavoriteFail = (status, error) => ({
|
||||
const unfavoriteFail = (status, error) => ({
|
||||
type: UNFAVORITE_FAIL,
|
||||
status: status,
|
||||
error: error,
|
||||
skipLoading: true,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export const fetchReposts = (id) => (dispatch, getState) => {
|
||||
if (!me) return
|
||||
|
||||
dispatch(fetchRepostsRequest(id))
|
||||
|
||||
api(getState).get(`/api/v1/statuses/${id}/reblogged_by`).then((response) => {
|
||||
dispatch(importFetchedAccounts(response.data))
|
||||
dispatch(fetchRepostsSuccess(id, response.data))
|
||||
}).catch((error) => {
|
||||
dispatch(fetchRepostsFail(id, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchRepostsRequest = (id) => ({
|
||||
type: REPOSTS_FETCH_REQUEST,
|
||||
id,
|
||||
})
|
||||
|
||||
export const fetchRepostsSuccess = (id, accounts) => ({
|
||||
type: REPOSTS_FETCH_SUCCESS,
|
||||
id,
|
||||
accounts,
|
||||
})
|
||||
|
||||
export const fetchRepostsFail = (id, error) => ({
|
||||
type: REPOSTS_FETCH_FAIL,
|
||||
status,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Pin the given status to your profile. Set status to status.pinned:true
|
||||
* on success.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const pin = (status) => (dispatch, getState) => {
|
||||
if (!me) return
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(pinRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/pin`).then((response) => {
|
||||
dispatch(importFetchedStatus(response.data))
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(pinSuccess(status))
|
||||
}).catch((error) => {
|
||||
dispatch(pinFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const pinRequest = (status) => ({
|
||||
const pinRequest = (status) => ({
|
||||
type: PIN_REQUEST,
|
||||
status,
|
||||
skipLoading: true,
|
||||
})
|
||||
|
||||
export const pinSuccess = (status) => ({
|
||||
const pinSuccess = (status) => ({
|
||||
type: PIN_SUCCESS,
|
||||
status,
|
||||
skipLoading: true,
|
||||
})
|
||||
|
||||
export const pinFail = (status, error) => ({
|
||||
const pinFail = (status, error) => ({
|
||||
type: PIN_FAIL,
|
||||
status,
|
||||
error,
|
||||
skipLoading: true,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Unpin the given status from your profile. Set status to status.pinned:false
|
||||
* on success and remove from account pins in timeline reducer.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const unpin = (status) => (dispatch, getState) => {
|
||||
if (!me) return
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(unpinRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/unpin`).then((response) => {
|
||||
dispatch(importFetchedStatus(response.data))
|
||||
dispatch(unpinSuccess(status))
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(unpinSuccess(status, response.data.account_id))
|
||||
}).catch((error) => {
|
||||
dispatch(unpinFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const unpinRequest = (status) => ({
|
||||
const unpinRequest = (status) => ({
|
||||
type: UNPIN_REQUEST,
|
||||
status,
|
||||
skipLoading: true,
|
||||
})
|
||||
|
||||
export const unpinSuccess = (status) => ({
|
||||
const unpinSuccess = (status, accountId) => ({
|
||||
type: UNPIN_SUCCESS,
|
||||
accountId,
|
||||
status,
|
||||
skipLoading: true,
|
||||
})
|
||||
|
||||
export const unpinFail = (status, error) => ({
|
||||
const unpinFail = (status, error) => ({
|
||||
type: UNPIN_FAIL,
|
||||
status,
|
||||
error,
|
||||
skipLoading: true,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Check if a status is pinned to the current user account.
|
||||
* @param {String} statusId
|
||||
*/
|
||||
export const fetchLikes = (id) => (dispatch, getState) => {
|
||||
dispatch(fetchLikesRequest(id))
|
||||
export const isPin = (statusId) => (dispatch, getState) => {
|
||||
if (!me || !statusId) return
|
||||
|
||||
api(getState).get(`/api/v1/statuses/${id}/favourited_by`).then((response) => {
|
||||
dispatch(importFetchedAccounts(response.data))
|
||||
dispatch(fetchLikesSuccess(id, response.data))
|
||||
dispatch(isPinRequest(statusId))
|
||||
|
||||
api(getState).get(`/api/v1/statuses/${statusId}/pin`).then((response) => {
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(isPinSuccess(statusId))
|
||||
}).catch((error) => {
|
||||
dispatch(fetchLikesFail(id, error))
|
||||
dispatch(isPinFail(statusId, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchLikesRequest = (id) => ({
|
||||
type: LIKES_FETCH_REQUEST,
|
||||
id,
|
||||
const isPinRequest = (statusId) => ({
|
||||
type: IS_PIN_REQUEST,
|
||||
statusId,
|
||||
})
|
||||
|
||||
export const fetchLikesSuccess = (id, accounts) => ({
|
||||
type: LIKES_FETCH_SUCCESS,
|
||||
id,
|
||||
accounts,
|
||||
const isPinSuccess = (statusId) => ({
|
||||
type: IS_PIN_SUCCESS,
|
||||
statusId,
|
||||
})
|
||||
|
||||
export const fetchLikesFail = (id, error) => ({
|
||||
type: LIKES_FETCH_FAIL,
|
||||
const isPinFail = (statusId, error) => ({
|
||||
type: IS_PIN_FAIL,
|
||||
statusId,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Bookmark the given status in your profile if PRO. Set status to
|
||||
* status.bookmarked:true on success.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const bookmark = (status) => (dispatch, getState) => {
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(bookmarkRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/bookmark`).then((response) => {
|
||||
dispatch(importFetchedStatus(response.data))
|
||||
dispatch(bookmarkSuccess(status, response.data))
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(bookmarkSuccess(status))
|
||||
}).catch((error) => {
|
||||
dispatch(bookmarkFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const bookmarkRequest = (status) => ({
|
||||
const bookmarkRequest = (status) => ({
|
||||
type: BOOKMARK_REQUEST,
|
||||
status: status,
|
||||
status,
|
||||
})
|
||||
|
||||
export const bookmarkSuccess = (status, response) => ({
|
||||
const bookmarkSuccess = (status) => ({
|
||||
type: BOOKMARK_SUCCESS,
|
||||
status: status,
|
||||
response: response,
|
||||
status,
|
||||
})
|
||||
|
||||
export const bookmarkFail = (status, error) => ({
|
||||
const bookmarkFail = (status, error) => ({
|
||||
type: BOOKMARK_FAIL,
|
||||
status: status,
|
||||
error: error,
|
||||
status,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
*
|
||||
* @description Unbookmark the given status in your profile if PRO. Set status to
|
||||
* status.bookmarked:false on success.
|
||||
* @param {ImmutableMap} status
|
||||
*/
|
||||
export const unbookmark = (status) => (dispatch, getState) => {
|
||||
if (!me || !status) return
|
||||
|
||||
dispatch(unbookmarkRequest(status))
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${status.get('id')}/unbookmark`).then((response) => {
|
||||
dispatch(importFetchedStatus(response.data))
|
||||
dispatch(unbookmarkSuccess(status, response.data))
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(unbookmarkSuccess(status))
|
||||
}).catch((error) => {
|
||||
dispatch(unbookmarkFail(status, error))
|
||||
})
|
||||
}
|
||||
|
||||
export const unbookmarkRequest = (status) => ({
|
||||
const unbookmarkRequest = (status) => ({
|
||||
type: UNBOOKMARK_REQUEST,
|
||||
status: status,
|
||||
status,
|
||||
})
|
||||
|
||||
export const unbookmarkSuccess = (status, response) => ({
|
||||
const unbookmarkSuccess = (status) => ({
|
||||
type: UNBOOKMARK_SUCCESS,
|
||||
status: status,
|
||||
response: response,
|
||||
status,
|
||||
})
|
||||
|
||||
export const unbookmarkFail = (status, error) => ({
|
||||
const unbookmarkFail = (status, error) => ({
|
||||
type: UNBOOKMARK_FAIL,
|
||||
status: status,
|
||||
error: error,
|
||||
})
|
||||
status,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
* @description Check if a status is bookmarked to the current user account.
|
||||
* @param {String} statusId
|
||||
*/
|
||||
export const isBookmark = (statusId) => (dispatch, getState) => {
|
||||
if (!me || !statusId) return
|
||||
|
||||
dispatch(isBookmarkRequest(statusId))
|
||||
|
||||
api(getState).get(`/api/v1/statuses/${statusId}/bookmark`).then((response) => {
|
||||
dispatch(updateStatusStats(response.data))
|
||||
dispatch(isBookmarkSuccess(statusId))
|
||||
}).catch((error) => {
|
||||
dispatch(isBookmarkFail(statusId, error))
|
||||
})
|
||||
}
|
||||
|
||||
const isBookmarkRequest = (statusId) => ({
|
||||
type: IS_BOOKMARK_REQUEST,
|
||||
statusId,
|
||||
})
|
||||
|
||||
const isBookmarkSuccess = (statusId) => ({
|
||||
type: IS_BOOKMARK_SUCCESS,
|
||||
statusId,
|
||||
})
|
||||
|
||||
const isBookmarkFail = (statusId, error) => ({
|
||||
type: IS_BOOKMARK_FAIL,
|
||||
statusId,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
* @description Fetch reposts for the given statusId and imports paginated accounts
|
||||
* and sets in user_lists reducer.
|
||||
* @param {String} statusId
|
||||
*/
|
||||
export const fetchReposts = (statusId) => (dispatch, getState) => {
|
||||
if (!me || !statusId) return
|
||||
|
||||
dispatch(fetchRepostsRequest(statusId))
|
||||
|
||||
api(getState).get(`/api/v1/statuses/${statusId}/reblogged_by`).then((response) => {
|
||||
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
||||
dispatch(importFetchedAccounts(response.data))
|
||||
dispatch(fetchRepostsSuccess(statusId, response.data, next ? next.uri : null))
|
||||
dispatch(fetchRelationships(response.data.map(item => item.id)))
|
||||
}).catch((error) => {
|
||||
dispatch(fetchRepostsFail(statusId, error))
|
||||
})
|
||||
}
|
||||
|
||||
const fetchRepostsRequest = (statusId) => ({
|
||||
type: REPOSTS_FETCH_REQUEST,
|
||||
statusId,
|
||||
})
|
||||
|
||||
const fetchRepostsSuccess = (statusId, accounts, next) => ({
|
||||
type: REPOSTS_FETCH_SUCCESS,
|
||||
statusId,
|
||||
accounts,
|
||||
next,
|
||||
})
|
||||
|
||||
const fetchRepostsFail = (statusId, error) => ({
|
||||
type: REPOSTS_FETCH_FAIL,
|
||||
statusId,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
* @description Expand reposts for the given statusId and imports paginated accounts
|
||||
* and sets in user_lists reducer.
|
||||
* @param {String} statusId
|
||||
*/
|
||||
export const expandReposts = (statusId) => (dispatch, getState) => {
|
||||
if (!me || !statusId) return
|
||||
|
||||
const url = getState().getIn(['user_lists', 'reblogged_by', statusId, 'next'])
|
||||
const isLoading = getState().getIn(['user_lists', 'reblogged_by', statusId, 'isLoading'])
|
||||
|
||||
if (url === null || isLoading) return
|
||||
|
||||
dispatch(expandRepostsRequest(statusId))
|
||||
|
||||
api(getState).get(url).then(response => {
|
||||
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
||||
dispatch(importFetchedAccounts(response.data))
|
||||
dispatch(expandRepostsSuccess(statusId, response.data, next ? next.uri : null))
|
||||
dispatch(fetchRelationships(response.data.map(item => item.id)))
|
||||
}).catch(error => dispatch(expandRepostsFail(error)))
|
||||
}
|
||||
|
||||
const expandRepostsRequest = (statusId) => ({
|
||||
type: REPOSTS_EXPAND_REQUEST,
|
||||
statusId,
|
||||
})
|
||||
|
||||
const expandRepostsSuccess = (statusId, accounts, next) => ({
|
||||
type: REPOSTS_EXPAND_SUCCESS,
|
||||
statusId,
|
||||
accounts,
|
||||
next,
|
||||
})
|
||||
|
||||
const expandRepostsFail = (statusId, error) => ({
|
||||
type: REPOSTS_EXPAND_FAIL,
|
||||
statusId,
|
||||
error,
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* @description Fetch likes for the given statusId and imports paginated accounts
|
||||
* and sets in user_lists reducer.
|
||||
* @param {String} statusId
|
||||
*/
|
||||
export const fetchLikes = (statusId) => (dispatch, getState) => {
|
||||
if (!me || !statusId) return
|
||||
|
||||
dispatch(fetchLikesRequest(statusId))
|
||||
|
||||
api(getState).get(`/api/v1/statuses/${statusId}/favourited_by`).then((response) => {
|
||||
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
||||
dispatch(importFetchedAccounts(response.data))
|
||||
dispatch(fetchLikesSuccess(statusId, response.data, next ? next.uri : null))
|
||||
dispatch(fetchRelationships(response.data.map(item => item.id)))
|
||||
}).catch((error) => {
|
||||
dispatch(fetchLikesFail(statusId, error))
|
||||
})
|
||||
}
|
||||
|
||||
const fetchLikesRequest = (statusId) => ({
|
||||
type: LIKES_FETCH_REQUEST,
|
||||
statusId,
|
||||
})
|
||||
|
||||
const fetchLikesSuccess = (statusId, accounts, next) => ({
|
||||
type: LIKES_FETCH_SUCCESS,
|
||||
statusId,
|
||||
accounts,
|
||||
next,
|
||||
})
|
||||
|
||||
const fetchLikesFail = (statusId, error) => ({
|
||||
type: LIKES_FETCH_FAIL,
|
||||
statusId,
|
||||
error,
|
||||
})
|
||||
|
||||
/**
|
||||
* @description Expand likes for the given statusId and imports paginated accounts
|
||||
* and sets in user_lists reducer.
|
||||
* @param {String} statusId
|
||||
*/
|
||||
export const expandLikes = (statusId) => (dispatch, getState) => {
|
||||
if (!me || !statusId) return
|
||||
|
||||
const url = getState().getIn(['user_lists', 'liked_by', statusId, 'next'])
|
||||
const isLoading = getState().getIn(['user_lists', 'liked_by', statusId, 'isLoading'])
|
||||
|
||||
if (url === null || isLoading) return
|
||||
|
||||
dispatch(expandLikesRequest(statusId))
|
||||
|
||||
api(getState).get(url).then(response => {
|
||||
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
||||
dispatch(importFetchedAccounts(response.data))
|
||||
dispatch(expandLikesSuccess(statusId, response.data, next ? next.uri : null))
|
||||
dispatch(fetchRelationships(response.data.map(item => item.id)))
|
||||
}).catch(error => dispatch(expandLikesFail(error)))
|
||||
}
|
||||
|
||||
const expandLikesRequest = (statusId) => ({
|
||||
type: LIKES_EXPAND_REQUEST,
|
||||
statusId,
|
||||
})
|
||||
|
||||
const expandLikesSuccess = (statusId, accounts, next) => ({
|
||||
type: LIKES_EXPAND_SUCCESS,
|
||||
statusId,
|
||||
accounts,
|
||||
next,
|
||||
})
|
||||
|
||||
const expandLikesFail = (statusId, error) => ({
|
||||
type: LIKES_EXPAND_FAIL,
|
||||
statusId,
|
||||
error,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user