logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

mutes.js (2716B)


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