2016-10-31 02:53:58 +11:00
|
|
|
import { map } from 'lodash'
|
|
|
|
import apiService from '../api/api.service.js'
|
|
|
|
|
|
|
|
const postStatus = ({ store, status, media = [], inReplyToStatusId = undefined }) => {
|
|
|
|
const mediaIds = map(media, 'id')
|
|
|
|
|
|
|
|
return apiService.postStatus({credentials: store.state.users.currentUser.credentials, status, mediaIds, inReplyToStatusId})
|
|
|
|
.then((data) => data.json())
|
|
|
|
.then((data) => {
|
2016-11-19 08:56:20 +11:00
|
|
|
store.dispatch('addNewStatuses',
|
2016-10-31 02:53:58 +11:00
|
|
|
{ statuses: [data], timeline: 'friends', showImmediately: true })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-07 05:30:20 +11:00
|
|
|
const uploadMedia = ({ store, formData }) => {
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
|
|
|
|
|
|
|
return apiService.uploadMedia({ credentials, formData }).then((xml) => {
|
|
|
|
return {
|
|
|
|
id: xml.getElementsByTagName('media_id')[0].textContent,
|
|
|
|
url: xml.getElementsByTagName('media_url')[0].textContent,
|
|
|
|
image: xml.getElementsByTagName('atom:link')[0].getAttribute('href')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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
|