logo

pleroma-fe

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

reports.js (2021B)


  1. import filter from 'lodash/filter'
  2. const reports = {
  3. state: {
  4. reportModal: {
  5. userId: null,
  6. statuses: [],
  7. preTickedIds: [],
  8. activated: false
  9. },
  10. reports: {}
  11. },
  12. mutations: {
  13. openUserReportingModal (state, { userId, statuses, preTickedIds }) {
  14. state.reportModal.userId = userId
  15. state.reportModal.statuses = statuses
  16. state.reportModal.preTickedIds = preTickedIds
  17. state.reportModal.activated = true
  18. },
  19. closeUserReportingModal (state) {
  20. state.reportModal.activated = false
  21. },
  22. setReportState (reportsState, { id, state }) {
  23. reportsState.reports[id].state = state
  24. },
  25. addReport (state, report) {
  26. state.reports[report.id] = report
  27. }
  28. },
  29. actions: {
  30. openUserReportingModal ({ rootState, commit }, { userId, statusIds = [] }) {
  31. const preTickedStatuses = statusIds.map(id => rootState.statuses.allStatusesObject[id])
  32. const preTickedIds = statusIds
  33. const statuses = preTickedStatuses.concat(
  34. filter(rootState.statuses.allStatuses,
  35. status => status.user.id === userId && !preTickedIds.includes(status.id)
  36. )
  37. )
  38. commit('openUserReportingModal', { userId, statuses, preTickedIds })
  39. },
  40. closeUserReportingModal ({ commit }) {
  41. commit('closeUserReportingModal')
  42. },
  43. setReportState ({ commit, dispatch, rootState }, { id, state }) {
  44. const oldState = rootState.reports.reports[id].state
  45. commit('setReportState', { id, state })
  46. rootState.api.backendInteractor.setReportState({ id, state }).catch(e => {
  47. console.error('Failed to set report state', e)
  48. dispatch('pushGlobalNotice', {
  49. level: 'error',
  50. messageKey: 'general.generic_error_message',
  51. messageArgs: [e.message],
  52. timeout: 5000
  53. })
  54. commit('setReportState', { id, state: oldState })
  55. })
  56. },
  57. addReport ({ commit }, report) {
  58. commit('addReport', report)
  59. }
  60. }
  61. }
  62. export default reports