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) => {
|
2017-08-20 20:16:41 +10:00
|
|
|
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
|
|
|
})
|
2017-08-21 22:35:14 +10:00
|
|
|
.catch((err) => {
|
|
|
|
return {
|
|
|
|
error: err.message
|
|
|
|
}
|
|
|
|
})
|
2016-10-31 02:53:58 +11:00
|
|
|
}
|
|
|
|
|
2016-11-07 05:30:20 +11:00
|
|
|
const uploadMedia = ({ store, formData }) => {
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
|
|
|
|
2019-03-16 06:02:00 +11:00
|
|
|
return apiService.uploadMedia({ credentials, formData })
|
2016-11-07 05:30:20 +11:00
|
|
|
}
|
|
|
|
|
2016-10-31 02:53:58 +11:00
|
|
|
const statusPosterService = {
|
2016-11-07 05:30:20 +11:00
|
|
|
postStatus,
|
|
|
|
uploadMedia
|
2016-10-31 02:53:58 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
export default statusPosterService
|