mutes.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import api, { getLinks } from '../api';
  2. import { fetchRelationships } from './accounts';
  3. import { importFetchedAccounts } from './importer';
  4. import { openModal } from './modal';
  5. export const MUTES_FETCH_REQUEST = 'MUTES_FETCH_REQUEST';
  6. export const MUTES_FETCH_SUCCESS = 'MUTES_FETCH_SUCCESS';
  7. export const MUTES_FETCH_FAIL = 'MUTES_FETCH_FAIL';
  8. export const MUTES_EXPAND_REQUEST = 'MUTES_EXPAND_REQUEST';
  9. export const MUTES_EXPAND_SUCCESS = 'MUTES_EXPAND_SUCCESS';
  10. export const MUTES_EXPAND_FAIL = 'MUTES_EXPAND_FAIL';
  11. export const MUTES_INIT_MODAL = 'MUTES_INIT_MODAL';
  12. export const MUTES_TOGGLE_HIDE_NOTIFICATIONS = 'MUTES_TOGGLE_HIDE_NOTIFICATIONS';
  13. export const MUTES_CHANGE_DURATION = 'MUTES_CHANGE_DURATION';
  14. export function fetchMutes() {
  15. return (dispatch, getState) => {
  16. dispatch(fetchMutesRequest());
  17. api(getState).get('/api/v1/mutes').then(response => {
  18. const next = getLinks(response).refs.find(link => link.rel === 'next');
  19. dispatch(importFetchedAccounts(response.data));
  20. dispatch(fetchMutesSuccess(response.data, next ? next.uri : null));
  21. dispatch(fetchRelationships(response.data.map(item => item.id)));
  22. }).catch(error => dispatch(fetchMutesFail(error)));
  23. };
  24. };
  25. export function fetchMutesRequest() {
  26. return {
  27. type: MUTES_FETCH_REQUEST,
  28. };
  29. };
  30. export function fetchMutesSuccess(accounts, next) {
  31. return {
  32. type: MUTES_FETCH_SUCCESS,
  33. accounts,
  34. next,
  35. };
  36. };
  37. export function fetchMutesFail(error) {
  38. return {
  39. type: MUTES_FETCH_FAIL,
  40. error,
  41. };
  42. };
  43. export function expandMutes() {
  44. return (dispatch, getState) => {
  45. const url = getState().getIn(['user_lists', 'mutes', 'next']);
  46. if (url === null) {
  47. return;
  48. }
  49. dispatch(expandMutesRequest());
  50. api(getState).get(url).then(response => {
  51. const next = getLinks(response).refs.find(link => link.rel === 'next');
  52. dispatch(importFetchedAccounts(response.data));
  53. dispatch(expandMutesSuccess(response.data, next ? next.uri : null));
  54. dispatch(fetchRelationships(response.data.map(item => item.id)));
  55. }).catch(error => dispatch(expandMutesFail(error)));
  56. };
  57. };
  58. export function expandMutesRequest() {
  59. return {
  60. type: MUTES_EXPAND_REQUEST,
  61. };
  62. };
  63. export function expandMutesSuccess(accounts, next) {
  64. return {
  65. type: MUTES_EXPAND_SUCCESS,
  66. accounts,
  67. next,
  68. };
  69. };
  70. export function expandMutesFail(error) {
  71. return {
  72. type: MUTES_EXPAND_FAIL,
  73. error,
  74. };
  75. };
  76. export function initMuteModal(account) {
  77. return dispatch => {
  78. dispatch({
  79. type: MUTES_INIT_MODAL,
  80. account,
  81. });
  82. dispatch(openModal('MUTE'));
  83. };
  84. }
  85. export function toggleHideNotifications() {
  86. return dispatch => {
  87. dispatch({ type: MUTES_TOGGLE_HIDE_NOTIFICATIONS });
  88. };
  89. }
  90. export function changeMuteDuration(duration) {
  91. return dispatch => {
  92. dispatch({
  93. type: MUTES_CHANGE_DURATION,
  94. duration,
  95. });
  96. };
  97. }