2018-03-05 01:27:15 +01:00
|
|
|
import { auth, basename } from './utils'
|
2018-08-24 20:50:40 +02:00
|
|
|
import { DEFAULT_TIMEOUT, get, post, WRITE_TIMEOUT } from '../_utils/ajax'
|
2018-03-05 01:27:15 +01:00
|
|
|
|
2018-03-05 02:16:33 +01:00
|
|
|
export async function postStatus (instanceName, accessToken, text, inReplyToId, mediaIds,
|
2018-04-19 05:43:13 +02:00
|
|
|
sensitive, spoilerText, visibility) {
|
2018-03-05 01:27:15 +01:00
|
|
|
let url = `${basename(instanceName)}/api/v1/statuses`
|
|
|
|
|
|
|
|
let body = {
|
|
|
|
status: text,
|
|
|
|
in_reply_to_id: inReplyToId,
|
|
|
|
media_ids: mediaIds,
|
|
|
|
sensitive: sensitive,
|
|
|
|
spoiler_text: spoilerText,
|
|
|
|
visibility: visibility
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let key of Object.keys(body)) {
|
|
|
|
let value = body[key]
|
2018-08-27 03:54:59 +02:00
|
|
|
// remove any unnecessary fields, except 'status' which must at least be an empty string
|
|
|
|
if (key !== 'status' && (!value || (Array.isArray(value) && !value.length))) {
|
2018-03-05 01:27:15 +01:00
|
|
|
delete body[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 16:38:36 +02:00
|
|
|
return post(url, body, auth(accessToken), {timeout: WRITE_TIMEOUT})
|
2018-03-05 02:16:33 +01:00
|
|
|
}
|
2018-08-24 20:50:40 +02:00
|
|
|
|
|
|
|
export async function getStatusContext (instanceName, accessToken, statusId) {
|
|
|
|
let url = `${basename(instanceName)}/api/v1/statuses/${statusId}/context`
|
|
|
|
return get(url, auth(accessToken), {timeout: DEFAULT_TIMEOUT})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStatus (instanceName, accessToken, statusId) {
|
|
|
|
let url = `${basename(instanceName)}/api/v1/statuses/${statusId}`
|
|
|
|
return get(url, auth(accessToken), {timeout: DEFAULT_TIMEOUT})
|
|
|
|
}
|