2016-10-30 16:53:58 +01:00
|
|
|
import { map } from 'lodash'
|
2026-01-08 17:26:52 +02:00
|
|
|
|
2026-06-13 03:10:00 +03:00
|
|
|
import {
|
|
|
|
|
editStatus as apiEditStatus,
|
|
|
|
|
postStatus as apiPostStatus,
|
|
|
|
|
setMediaDescription as apiSetMediaDescription,
|
|
|
|
|
uploadMedia as apiUploadMedia,
|
2026-06-17 14:36:45 +03:00
|
|
|
} from 'src/api/user.js'
|
2016-10-30 16:53:58 +01:00
|
|
|
|
2020-06-28 12:16:41 +03:00
|
|
|
const postStatus = ({
|
|
|
|
|
store,
|
|
|
|
|
status,
|
|
|
|
|
spoilerText,
|
|
|
|
|
visibility,
|
|
|
|
|
sensitive,
|
|
|
|
|
poll,
|
|
|
|
|
media = [],
|
|
|
|
|
inReplyToStatusId = undefined,
|
2023-07-12 21:34:19 -04:00
|
|
|
quoteId = undefined,
|
2020-06-28 12:16:41 +03:00
|
|
|
contentType = 'text/plain',
|
2020-07-15 16:19:57 +03:00
|
|
|
preview = false,
|
2026-01-06 16:22:52 +02:00
|
|
|
idempotencyKey = '',
|
2020-06-28 12:16:41 +03:00
|
|
|
}) => {
|
2016-10-30 16:53:58 +01:00
|
|
|
const mediaIds = map(media, 'id')
|
|
|
|
|
|
2026-06-13 03:10:00 +03:00
|
|
|
return apiPostStatus({
|
|
|
|
|
credentials: store.state.users.currentUser.credentials,
|
|
|
|
|
status,
|
|
|
|
|
spoilerText,
|
|
|
|
|
visibility,
|
|
|
|
|
sensitive,
|
|
|
|
|
mediaIds,
|
|
|
|
|
inReplyToStatusId,
|
|
|
|
|
quoteId,
|
|
|
|
|
contentType,
|
|
|
|
|
poll,
|
|
|
|
|
preview,
|
|
|
|
|
idempotencyKey,
|
2026-06-22 20:19:54 +03:00
|
|
|
}).then(({ data }) => {
|
2026-06-22 20:54:34 +03:00
|
|
|
if (!preview)
|
|
|
|
|
store.dispatch('addNewStatuses', {
|
|
|
|
|
statuses: [data],
|
|
|
|
|
timeline: 'friends',
|
|
|
|
|
showImmediately: true,
|
|
|
|
|
noIdUpdate: true, // To prevent missing notices on next pull.
|
|
|
|
|
})
|
2026-06-22 20:19:54 +03:00
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
})
|
2016-10-30 16:53:58 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-07 21:31:48 -06:00
|
|
|
const editStatus = ({
|
|
|
|
|
store,
|
|
|
|
|
statusId,
|
|
|
|
|
status,
|
|
|
|
|
spoilerText,
|
|
|
|
|
sensitive,
|
|
|
|
|
poll,
|
|
|
|
|
media = [],
|
2026-01-06 16:22:52 +02:00
|
|
|
contentType = 'text/plain',
|
2022-06-07 21:31:48 -06:00
|
|
|
}) => {
|
|
|
|
|
const mediaIds = map(media, 'id')
|
|
|
|
|
|
2026-06-17 17:58:14 +03:00
|
|
|
return apiEditStatus({
|
2026-06-13 03:10:00 +03:00
|
|
|
id: statusId,
|
|
|
|
|
credentials: store.state.users.currentUser.credentials,
|
|
|
|
|
status,
|
|
|
|
|
spoilerText,
|
|
|
|
|
sensitive,
|
|
|
|
|
poll,
|
|
|
|
|
mediaIds,
|
|
|
|
|
contentType,
|
|
|
|
|
})
|
2026-06-17 17:58:14 +03:00
|
|
|
.then(({ data }) => {
|
|
|
|
|
store.dispatch('addNewStatuses', {
|
|
|
|
|
statuses: [data],
|
|
|
|
|
timeline: 'friends',
|
|
|
|
|
showImmediately: true,
|
|
|
|
|
noIdUpdate: true, // To prevent missing notices on next pull.
|
|
|
|
|
})
|
|
|
|
|
|
2022-06-07 21:31:48 -06:00
|
|
|
return data
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.error('Error editing status', err)
|
|
|
|
|
return {
|
2026-01-06 16:22:52 +02:00
|
|
|
error: err.message,
|
2022-06-07 21:31:48 -06:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-06 19:30:20 +01:00
|
|
|
const uploadMedia = ({ store, formData }) => {
|
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
2026-06-17 17:58:14 +03:00
|
|
|
return apiUploadMedia({ credentials, formData }).then(({ data }) => data)
|
2016-11-06 19:30:20 +01:00
|
|
|
}
|
|
|
|
|
|
2020-07-07 09:07:20 +03:00
|
|
|
const setMediaDescription = ({ store, id, description }) => {
|
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
2026-06-17 17:58:14 +03:00
|
|
|
return apiSetMediaDescription({ credentials, id, description }).then(
|
|
|
|
|
({ data }) => data,
|
|
|
|
|
)
|
2020-07-07 09:07:20 +03:00
|
|
|
}
|
|
|
|
|
|
2016-10-30 16:53:58 +01:00
|
|
|
const statusPosterService = {
|
2016-11-06 19:30:20 +01:00
|
|
|
postStatus,
|
2022-06-07 21:31:48 -06:00
|
|
|
editStatus,
|
2020-07-07 09:07:20 +03:00
|
|
|
uploadMedia,
|
2026-01-06 16:22:52 +02:00
|
|
|
setMediaDescription,
|
2016-10-30 16:53:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default statusPosterService
|