2019-03-19 01:53:11 -07:00
|
|
|
import filter from 'lodash/filter'
|
|
|
|
|
|
|
|
const reports = {
|
|
|
|
state: {
|
2021-01-18 05:26:08 -08:00
|
|
|
reportModal: {
|
|
|
|
userId: null,
|
|
|
|
statuses: [],
|
|
|
|
preTickedIds: [],
|
|
|
|
activated: false
|
|
|
|
},
|
|
|
|
reports: {}
|
2019-03-19 01:53:11 -07:00
|
|
|
},
|
|
|
|
mutations: {
|
2021-01-12 04:43:21 -08:00
|
|
|
openUserReportingModal (state, { userId, statuses, preTickedIds }) {
|
2021-01-18 05:26:08 -08:00
|
|
|
state.reportModal.userId = userId
|
|
|
|
state.reportModal.statuses = statuses
|
|
|
|
state.reportModal.preTickedIds = preTickedIds
|
|
|
|
state.reportModal.activated = true
|
2019-03-19 01:53:11 -07:00
|
|
|
},
|
|
|
|
closeUserReportingModal (state) {
|
2021-02-01 02:55:23 -08:00
|
|
|
state.reportModal.activated = false
|
2021-01-18 05:26:08 -08:00
|
|
|
},
|
|
|
|
setReportState (reportsState, { id, state }) {
|
|
|
|
reportsState.reports[id].state = state
|
|
|
|
},
|
|
|
|
addReport (state, report) {
|
|
|
|
state.reports[report.id] = report
|
2019-03-19 01:53:11 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
2021-01-12 04:43:21 -08:00
|
|
|
openUserReportingModal ({ rootState, commit }, { userId, statusIds = [] }) {
|
|
|
|
const preTickedStatuses = statusIds.map(id => rootState.statuses.allStatusesObject[id])
|
|
|
|
const preTickedIds = statusIds
|
|
|
|
const statuses = preTickedStatuses.concat(
|
|
|
|
filter(rootState.statuses.allStatuses,
|
|
|
|
status => status.user.id === userId && !preTickedIds.includes(status.id)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
commit('openUserReportingModal', { userId, statuses, preTickedIds })
|
2019-03-19 01:53:11 -07:00
|
|
|
},
|
|
|
|
closeUserReportingModal ({ commit }) {
|
|
|
|
commit('closeUserReportingModal')
|
2021-01-18 05:26:08 -08:00
|
|
|
},
|
2021-02-03 02:02:37 -08:00
|
|
|
setReportState ({ commit, dispatch, rootState }, { id, state }) {
|
2021-01-18 05:26:08 -08:00
|
|
|
const oldState = rootState.reports.reports[id].state
|
|
|
|
commit('setReportState', { id, state })
|
2022-02-25 16:53:01 -08:00
|
|
|
rootState.api.backendInteractor.setReportState({ id, state }).catch(e => {
|
2021-01-18 05:26:08 -08:00
|
|
|
console.error('Failed to set report state', e)
|
2021-02-03 02:02:37 -08:00
|
|
|
dispatch('pushGlobalNotice', {
|
|
|
|
level: 'error',
|
|
|
|
messageKey: 'general.generic_error_message',
|
|
|
|
messageArgs: [e.message],
|
|
|
|
timeout: 5000
|
|
|
|
})
|
2021-01-27 03:13:10 -08:00
|
|
|
commit('setReportState', { id, state: oldState })
|
2021-01-18 05:26:08 -08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
addReport ({ commit }, report) {
|
|
|
|
commit('addReport', report)
|
2019-03-19 01:53:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default reports
|