You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.5 KiB

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