pleroma-fe/src/services/status_poster/status_poster.service.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-10-31 02:53:58 +11:00
import { map } from 'lodash'
import apiService from '../api/api.service.js'
2019-06-19 06:28:31 +10:00
const postStatus = ({ store, status, spoilerText, visibility, sensitive, poll, media = [], inReplyToStatusId = undefined, contentType = 'text/plain' }) => {
2016-10-31 02:53:58 +11:00
const mediaIds = map(media, 'id')
2019-06-19 06:28:31 +10:00
return apiService.postStatus({
credentials: store.state.users.currentUser.credentials,
status,
spoilerText,
visibility,
sensitive,
mediaIds,
inReplyToStatusId,
contentType,
poll})
2016-10-31 02:53:58 +11:00
.then((data) => {
if (!data.error) {
store.dispatch('addNewStatuses', {
statuses: [data],
timeline: 'friends',
showImmediately: true,
noIdUpdate: true // To prevent missing notices on next pull.
})
}
return data
2016-10-31 02:53:58 +11:00
})
.catch((err) => {
return {
error: err.message
}
})
2016-10-31 02:53:58 +11:00
}
const uploadMedia = ({ store, formData }) => {
const credentials = store.state.users.currentUser.credentials
return apiService.uploadMedia({ credentials, formData })
}
2016-10-31 02:53:58 +11:00
const statusPosterService = {
postStatus,
uploadMedia
2016-10-31 02:53:58 +11:00
}
export default statusPosterService