From cea6ea42f0f882864e01f79a8af08c8bc59272fb Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 20 Mar 2019 11:45:19 -0400 Subject: [PATCH] add api service function --- .../user_reporting_modal.js | 6 ++--- src/modules/reports.js | 5 +++-- src/services/api/api.service.js | 22 ++++++++++++++++++- .../backend_interactor_service.js | 4 +++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/components/user_reporting_modal/user_reporting_modal.js b/src/components/user_reporting_modal/user_reporting_modal.js index fb9ea16d..87b6fde9 100644 --- a/src/components/user_reporting_modal/user_reporting_modal.js +++ b/src/components/user_reporting_modal/user_reporting_modal.js @@ -44,12 +44,12 @@ const UserReportingModal = { this.$store.dispatch('closeUserReportingModal') }, reportUser () { - const payload = { + const params = { comment: this.comment, forward: this.forward, - statusIdsToReport: this.statusIdsToReport + statusIds: this.statusIdsToReport } - this.$store.dispatch('reportUser', payload) + this.$store.dispatch('reportUser', params) }, isChecked (statusId) { return this.statusIdsToReport.indexOf(statusId) !== -1 diff --git a/src/modules/reports.js b/src/modules/reports.js index b712cfeb..0470b3be 100644 --- a/src/modules/reports.js +++ b/src/modules/reports.js @@ -24,8 +24,9 @@ const reports = { closeUserReportingModal ({ commit }) { commit('closeUserReportingModal') }, - reportUser ({ commit }, payload) { - console.log('payload', payload) + reportUser ({ state, rootState, commit }, params) { + rootState.api.backendInteractor.reportUser({ userId: state.userId, ...params }) + .then(result => console.log(result)) } } } diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index c5e2280d..9753049f 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -50,6 +50,7 @@ const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' const MASTODON_STATUS_FAVORITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by` const MASTODON_STATUS_REBLOGGEDBY_URL = id => `/api/v1/statuses/${id}/reblogged_by` const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials' +const MASTODON_REPORT_USER_URL = 'api/v1/reports' import { each, map, concat, last } from 'lodash' import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js' @@ -722,6 +723,24 @@ const fetchRebloggedByUsers = ({id}) => { return promisedRequest(MASTODON_STATUS_REBLOGGEDBY_URL(id)).then((users) => users.map(parseUser)) } +const reportUser = ({credentials, userId, statusIds, comment, forward}) => { + const payload = { + 'account_id': userId, + 'status_ids': statusIds, + comment, + forward + } + return fetch(MASTODON_REPORT_USER_URL, { + body: JSON.stringify(payload), + headers: { + ...authHeaders(credentials), + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + method: 'POST' + }).then((data) => data.json()) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -773,7 +792,8 @@ const apiService = { suggestions, markNotificationsAsSeen, fetchFavoritedByUsers, - fetchRebloggedByUsers + fetchRebloggedByUsers, + reportUser } export default apiService diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index d2b581ca..58bb1248 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -115,6 +115,7 @@ const backendInteractorService = (credentials) => { const fetchFavoritedByUsers = (id) => apiService.fetchFavoritedByUsers({id}) const fetchRebloggedByUsers = (id) => apiService.fetchRebloggedByUsers({id}) + const reportUser = (params) => apiService.reportUser({credentials, ...params}) const backendInteractorServiceInstance = { fetchStatus, @@ -159,7 +160,8 @@ const backendInteractorService = (credentials) => { approveUser, denyUser, fetchFavoritedByUsers, - fetchRebloggedByUsers + fetchRebloggedByUsers, + reportUser } return backendInteractorServiceInstance