2016-10-30 15:53:58 +00:00
|
|
|
import { map } from 'lodash'
|
|
|
|
import apiService from '../api/api.service.js'
|
|
|
|
|
2020-06-28 09:16:41 +00:00
|
|
|
const postStatus = ({
|
|
|
|
store,
|
|
|
|
status,
|
|
|
|
spoilerText,
|
|
|
|
visibility,
|
|
|
|
sensitive,
|
|
|
|
poll,
|
|
|
|
media = [],
|
|
|
|
inReplyToStatusId = undefined,
|
2022-07-25 16:25:41 +00:00
|
|
|
quoteId = undefined,
|
2020-06-28 09:16:41 +00:00
|
|
|
contentType = 'text/plain',
|
2020-07-15 13:19:57 +00:00
|
|
|
preview = false,
|
|
|
|
idempotencyKey = ''
|
2020-06-28 09:16:41 +00:00
|
|
|
}) => {
|
2016-10-30 15:53:58 +00:00
|
|
|
const mediaIds = map(media, 'id')
|
|
|
|
|
2019-06-18 20:28:31 +00:00
|
|
|
return apiService.postStatus({
|
|
|
|
credentials: store.state.users.currentUser.credentials,
|
|
|
|
status,
|
|
|
|
spoilerText,
|
|
|
|
visibility,
|
|
|
|
sensitive,
|
|
|
|
mediaIds,
|
|
|
|
inReplyToStatusId,
|
2022-07-25 16:25:41 +00:00
|
|
|
quoteId,
|
2019-06-18 20:28:31 +00:00
|
|
|
contentType,
|
2020-06-28 09:16:41 +00:00
|
|
|
poll,
|
2020-07-15 13:19:57 +00:00
|
|
|
preview,
|
|
|
|
idempotencyKey
|
2020-07-07 06:07:20 +00:00
|
|
|
})
|
2016-10-30 15:53:58 +00:00
|
|
|
.then((data) => {
|
2020-06-28 09:16:41 +00:00
|
|
|
if (!data.error && !preview) {
|
2017-08-20 10:16:41 +00:00
|
|
|
store.dispatch('addNewStatuses', {
|
|
|
|
statuses: [data],
|
|
|
|
timeline: 'friends',
|
|
|
|
showImmediately: true,
|
|
|
|
noIdUpdate: true // To prevent missing notices on next pull.
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return data
|
2016-10-30 15:53:58 +00:00
|
|
|
})
|
2017-08-21 12:35:14 +00:00
|
|
|
.catch((err) => {
|
|
|
|
return {
|
|
|
|
error: err.message
|
|
|
|
}
|
|
|
|
})
|
2016-10-30 15:53:58 +00:00
|
|
|
}
|
|
|
|
|
2022-09-06 19:25:03 +00:00
|
|
|
const editStatus = ({
|
|
|
|
store,
|
|
|
|
statusId,
|
|
|
|
status,
|
|
|
|
spoilerText,
|
|
|
|
sensitive,
|
|
|
|
poll,
|
|
|
|
media = [],
|
|
|
|
contentType = 'text/plain'
|
|
|
|
}) => {
|
|
|
|
const mediaIds = map(media, 'id')
|
|
|
|
|
|
|
|
return apiService.editStatus({
|
|
|
|
id: statusId,
|
|
|
|
credentials: store.state.users.currentUser.credentials,
|
|
|
|
status,
|
|
|
|
spoilerText,
|
|
|
|
sensitive,
|
|
|
|
poll,
|
|
|
|
mediaIds,
|
|
|
|
contentType
|
|
|
|
})
|
|
|
|
.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
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error('Error editing status', err)
|
|
|
|
return {
|
|
|
|
error: err.message
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-06 18:30:20 +00:00
|
|
|
const uploadMedia = ({ store, formData }) => {
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
2019-03-15 19:02:00 +00:00
|
|
|
return apiService.uploadMedia({ credentials, formData })
|
2016-11-06 18:30:20 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 06:07:20 +00:00
|
|
|
const setMediaDescription = ({ store, id, description }) => {
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
|
|
|
return apiService.setMediaDescription({ credentials, id, description })
|
|
|
|
}
|
|
|
|
|
2016-10-30 15:53:58 +00:00
|
|
|
const statusPosterService = {
|
2016-11-06 18:30:20 +00:00
|
|
|
postStatus,
|
2022-09-06 19:25:03 +00:00
|
|
|
editStatus,
|
2020-07-07 06:07:20 +00:00
|
|
|
uploadMedia,
|
|
|
|
setMediaDescription
|
2016-10-30 15:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default statusPosterService
|