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

111 lines
2.3 KiB
JavaScript
Raw Normal View History

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,
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,
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) {
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
})
.catch((err) => {
return {
error: err.message
}
})
2016-10-30 15:53:58 +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
}
})
}
const uploadMedia = ({ store, formData }) => {
const credentials = store.state.users.currentUser.credentials
return apiService.uploadMedia({ credentials, formData })
}
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 = {
postStatus,
editStatus,
2020-07-07 06:07:20 +00:00
uploadMedia,
setMediaDescription
2016-10-30 15:53:58 +00:00
}
export default statusPosterService