aboutsummaryrefslogtreecommitdiff
path: root/src/services/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/api')
-rw-r--r--src/services/api/api.service.js416
1 files changed, 374 insertions, 42 deletions
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 8341112b..1ec77b37 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -1,5 +1,5 @@
import { each, map, concat, last, get } from 'lodash'
-import { parseStatus, parseUser, parseNotification, parseAttachment, parseChat, parseLinkHeaderPagination } from '../entity_normalizer/entity_normalizer.service.js'
+import { parseStatus, parseSource, parseUser, parseNotification, parseAttachment, parseChat, parseLinkHeaderPagination } from '../entity_normalizer/entity_normalizer.service.js'
import { RegistrationError, StatusCodeError } from '../errors/errors'
/* eslint-env browser */
@@ -9,6 +9,8 @@ const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import'
const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account'
const CHANGE_EMAIL_URL = '/api/pleroma/change_email'
const CHANGE_PASSWORD_URL = '/api/pleroma/change_password'
+const MOVE_ACCOUNT_URL = '/api/pleroma/move_account'
+const ALIASES_URL = '/api/pleroma/aliases'
const TAG_USER_URL = '/api/pleroma/admin/users/tag'
const PERMISSION_GROUP_URL = (screenName, right) => `/api/pleroma/admin/users/${screenName}/permission_group/${right}`
const ACTIVATE_USER_URL = '/api/pleroma/admin/users/activate'
@@ -47,9 +49,16 @@ const MASTODON_PUBLIC_TIMELINE = '/api/v1/timelines/public'
const MASTODON_USER_HOME_TIMELINE_URL = '/api/v1/timelines/home'
const MASTODON_STATUS_URL = id => `/api/v1/statuses/${id}`
const MASTODON_STATUS_CONTEXT_URL = id => `/api/v1/statuses/${id}/context`
+const MASTODON_STATUS_SOURCE_URL = id => `/api/v1/statuses/${id}/source`
+const MASTODON_STATUS_HISTORY_URL = id => `/api/v1/statuses/${id}/history`
const MASTODON_USER_URL = '/api/v1/accounts'
+const MASTODON_USER_LOOKUP_URL = '/api/v1/accounts/lookup'
const MASTODON_USER_RELATIONSHIPS_URL = '/api/v1/accounts/relationships'
const MASTODON_USER_TIMELINE_URL = id => `/api/v1/accounts/${id}/statuses`
+const MASTODON_USER_IN_LISTS = id => `/api/v1/accounts/${id}/lists`
+const MASTODON_LIST_URL = id => `/api/v1/lists/${id}`
+const MASTODON_LIST_TIMELINE_URL = id => `/api/v1/timelines/list/${id}`
+const MASTODON_LIST_ACCOUNTS_URL = id => `/api/v1/lists/${id}/accounts`
const MASTODON_TAG_TIMELINE_URL = tag => `/api/v1/timelines/tag/${tag}`
const MASTODON_BOOKMARK_TIMELINE_URL = '/api/v1/bookmarks'
const MASTODON_USER_BLOCKS_URL = '/api/v1/blocks/'
@@ -58,6 +67,7 @@ const MASTODON_BLOCK_USER_URL = id => `/api/v1/accounts/${id}/block`
const MASTODON_UNBLOCK_USER_URL = id => `/api/v1/accounts/${id}/unblock`
const MASTODON_MUTE_USER_URL = id => `/api/v1/accounts/${id}/mute`
const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute`
+const MASTODON_REMOVE_USER_FROM_FOLLOWERS = id => `/api/v1/accounts/${id}/remove_from_followers`
const MASTODON_SUBSCRIBE_USER = id => `/api/v1/pleroma/accounts/${id}/subscribe`
const MASTODON_UNSUBSCRIBE_USER = id => `/api/v1/pleroma/accounts/${id}/unsubscribe`
const MASTODON_BOOKMARK_STATUS_URL = id => `/api/v1/statuses/${id}/bookmark`
@@ -74,23 +84,26 @@ const MASTODON_PIN_OWN_STATUS = id => `/api/v1/statuses/${id}/pin`
const MASTODON_UNPIN_OWN_STATUS = id => `/api/v1/statuses/${id}/unpin`
const MASTODON_MUTE_CONVERSATION = id => `/api/v1/statuses/${id}/mute`
const MASTODON_UNMUTE_CONVERSATION = id => `/api/v1/statuses/${id}/unmute`
-const MASTODON_SEARCH_2 = `/api/v2/search`
+const MASTODON_SEARCH_2 = '/api/v2/search'
const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search'
const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks'
+const MASTODON_LISTS_URL = '/api/v1/lists'
const MASTODON_STREAMING = '/api/v1/streaming'
const MASTODON_KNOWN_DOMAIN_LIST_URL = '/api/v1/instance/peers'
const PLEROMA_EMOJI_REACTIONS_URL = id => `/api/v1/pleroma/statuses/${id}/reactions`
const PLEROMA_EMOJI_REACT_URL = (id, emoji) => `/api/v1/pleroma/statuses/${id}/reactions/${emoji}`
const PLEROMA_EMOJI_UNREACT_URL = (id, emoji) => `/api/v1/pleroma/statuses/${id}/reactions/${emoji}`
-const PLEROMA_CHATS_URL = `/api/v1/pleroma/chats`
+const PLEROMA_CHATS_URL = '/api/v1/pleroma/chats'
const PLEROMA_CHAT_URL = id => `/api/v1/pleroma/chats/by-account-id/${id}`
const PLEROMA_CHAT_MESSAGES_URL = id => `/api/v1/pleroma/chats/${id}/messages`
const PLEROMA_CHAT_READ_URL = id => `/api/v1/pleroma/chats/${id}/read`
const PLEROMA_DELETE_CHAT_MESSAGE_URL = (chatId, messageId) => `/api/v1/pleroma/chats/${chatId}/messages/${messageId}`
+const PLEROMA_ADMIN_REPORTS = '/api/pleroma/admin/reports'
+const PLEROMA_BACKUP_URL = '/api/v1/pleroma/backups'
const oldfetch = window.fetch
-let fetch = (url, options) => {
+const fetch = (url, options) => {
options = options || {}
const baseUrl = ''
const fullUrl = baseUrl + url
@@ -102,7 +115,7 @@ const promisedRequest = ({ method, url, params, payload, credentials, headers =
const options = {
method,
headers: {
- 'Accept': 'application/json',
+ Accept: 'application/json',
'Content-Type': 'application/json',
...headers
}
@@ -151,9 +164,15 @@ const updateNotificationSettings = ({ credentials, settings }) => {
}).then((data) => data.json())
}
-const updateProfileImages = ({ credentials, avatar = null, banner = null, background = null }) => {
+const updateProfileImages = ({ credentials, avatar = null, avatarName = null, banner = null, background = null }) => {
const form = new FormData()
- if (avatar !== null) form.append('avatar', avatar)
+ if (avatar !== null) {
+ if (avatarName !== null) {
+ form.append('avatar', avatar, avatarName)
+ } else {
+ form.append('avatar', avatar)
+ }
+ }
if (banner !== null) form.append('header', banner)
if (background !== null) form.append('pleroma_background_image', background)
return fetch(MASTODON_PROFILE_UPDATE_URL, {
@@ -191,6 +210,7 @@ const updateProfile = ({ credentials, params }) => {
// homepage
// location
// token
+// language
const register = ({ params, credentials }) => {
const { nickname, ...rest } = params
return fetch(MASTODON_REGISTRATION_URL, {
@@ -219,16 +239,16 @@ const getCaptcha = () => fetch('/api/pleroma/captcha').then(resp => resp.json())
const authHeaders = (accessToken) => {
if (accessToken) {
- return { 'Authorization': `Bearer ${accessToken}` }
+ return { Authorization: `Bearer ${accessToken}` }
} else {
return { }
}
}
const followUser = ({ id, credentials, ...options }) => {
- let url = MASTODON_FOLLOW_URL(id)
+ const url = MASTODON_FOLLOW_URL(id)
const form = {}
- if (options.reblogs !== undefined) { form['reblogs'] = options.reblogs }
+ if (options.reblogs !== undefined) { form.reblogs = options.reblogs }
return fetch(url, {
body: JSON.stringify(form),
headers: {
@@ -240,13 +260,20 @@ const followUser = ({ id, credentials, ...options }) => {
}
const unfollowUser = ({ id, credentials }) => {
- let url = MASTODON_UNFOLLOW_URL(id)
+ const url = MASTODON_UNFOLLOW_URL(id)
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST'
}).then((data) => data.json())
}
+const fetchUserInLists = ({ id, credentials }) => {
+ const url = MASTODON_USER_IN_LISTS(id)
+ return fetch(url, {
+ headers: authHeaders(credentials)
+ }).then((data) => data.json())
+}
+
const pinOwnStatus = ({ id, credentials }) => {
return promisedRequest({ url: MASTODON_PIN_OWN_STATUS(id), credentials, method: 'POST' })
.then((data) => parseStatus(data))
@@ -281,8 +308,15 @@ const unblockUser = ({ id, credentials }) => {
}).then((data) => data.json())
}
+const removeUserFromFollowers = ({ id, credentials }) => {
+ return fetch(MASTODON_REMOVE_USER_FROM_FOLLOWERS(id), {
+ headers: authHeaders(credentials),
+ method: 'POST'
+ }).then((data) => data.json())
+}
+
const approveUser = ({ id, credentials }) => {
- let url = MASTODON_APPROVE_USER_URL(id)
+ const url = MASTODON_APPROVE_USER_URL(id)
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST'
@@ -290,7 +324,7 @@ const approveUser = ({ id, credentials }) => {
}
const denyUser = ({ id, credentials }) => {
- let url = MASTODON_DENY_USER_URL(id)
+ const url = MASTODON_DENY_USER_URL(id)
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST'
@@ -298,13 +332,32 @@ const denyUser = ({ id, credentials }) => {
}
const fetchUser = ({ id, credentials }) => {
- let url = `${MASTODON_USER_URL}/${id}`
+ const url = `${MASTODON_USER_URL}/${id}`
return promisedRequest({ url, credentials })
.then((data) => parseUser(data))
}
+const fetchUserByName = ({ name, credentials }) => {
+ return promisedRequest({
+ url: MASTODON_USER_LOOKUP_URL,
+ credentials,
+ params: { acct: name }
+ })
+ .then(data => data.id)
+ .catch(error => {
+ if (error && error.statusCode === 404) {
+ // Either the backend does not support lookup endpoint,
+ // or there is no user with such name. Fallback and treat name as id.
+ return name
+ } else {
+ throw error
+ }
+ })
+ .then(id => fetchUser({ id, credentials }))
+}
+
const fetchUserRelationship = ({ id, credentials }) => {
- let url = `${MASTODON_USER_RELATIONSHIPS_URL}/?id=${id}`
+ const url = `${MASTODON_USER_RELATIONSHIPS_URL}/?id=${id}`
return fetch(url, { headers: authHeaders(credentials) })
.then((response) => {
return new Promise((resolve, reject) => response.json()
@@ -323,7 +376,7 @@ const fetchFriends = ({ id, maxId, sinceId, limit = 20, credentials }) => {
maxId && `max_id=${maxId}`,
sinceId && `since_id=${sinceId}`,
limit && `limit=${limit}`,
- `with_relationships=true`
+ 'with_relationships=true'
].filter(_ => _).join('&')
url = url + (args ? '?' + args : '')
@@ -333,6 +386,7 @@ const fetchFriends = ({ id, maxId, sinceId, limit = 20, credentials }) => {
}
const exportFriends = ({ id, credentials }) => {
+ // eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
try {
let friends = []
@@ -358,7 +412,7 @@ const fetchFollowers = ({ id, maxId, sinceId, limit = 20, credentials }) => {
maxId && `max_id=${maxId}`,
sinceId && `since_id=${sinceId}`,
limit && `limit=${limit}`,
- `with_relationships=true`
+ 'with_relationships=true'
].filter(_ => _).join('&')
url += args ? '?' + args : ''
@@ -374,8 +428,83 @@ const fetchFollowRequests = ({ credentials }) => {
.then((data) => data.map(parseUser))
}
+const fetchLists = ({ credentials }) => {
+ const url = MASTODON_LISTS_URL
+ return fetch(url, { headers: authHeaders(credentials) })
+ .then((data) => data.json())
+}
+
+const createList = ({ title, credentials }) => {
+ const url = MASTODON_LISTS_URL
+ const headers = authHeaders(credentials)
+ headers['Content-Type'] = 'application/json'
+
+ return fetch(url, {
+ headers,
+ method: 'POST',
+ body: JSON.stringify({ title })
+ }).then((data) => data.json())
+}
+
+const getList = ({ listId, credentials }) => {
+ const url = MASTODON_LIST_URL(listId)
+ return fetch(url, { headers: authHeaders(credentials) })
+ .then((data) => data.json())
+}
+
+const updateList = ({ listId, title, credentials }) => {
+ const url = MASTODON_LIST_URL(listId)
+ const headers = authHeaders(credentials)
+ headers['Content-Type'] = 'application/json'
+
+ return fetch(url, {
+ headers,
+ method: 'PUT',
+ body: JSON.stringify({ title })
+ })
+}
+
+const getListAccounts = ({ listId, credentials }) => {
+ const url = MASTODON_LIST_ACCOUNTS_URL(listId)
+ return fetch(url, { headers: authHeaders(credentials) })
+ .then((data) => data.json())
+ .then((data) => data.map(({ id }) => id))
+}
+
+const addAccountsToList = ({ listId, accountIds, credentials }) => {
+ const url = MASTODON_LIST_ACCOUNTS_URL(listId)
+ const headers = authHeaders(credentials)
+ headers['Content-Type'] = 'application/json'
+
+ return fetch(url, {
+ headers,
+ method: 'POST',
+ body: JSON.stringify({ account_ids: accountIds })
+ })
+}
+
+const removeAccountsFromList = ({ listId, accountIds, credentials }) => {
+ const url = MASTODON_LIST_ACCOUNTS_URL(listId)
+ const headers = authHeaders(credentials)
+ headers['Content-Type'] = 'application/json'
+
+ return fetch(url, {
+ headers,
+ method: 'DELETE',
+ body: JSON.stringify({ account_ids: accountIds })
+ })
+}
+
+const deleteList = ({ listId, credentials }) => {
+ const url = MASTODON_LIST_URL(listId)
+ return fetch(url, {
+ method: 'DELETE',
+ headers: authHeaders(credentials)
+ })
+}
+
const fetchConversation = ({ id, credentials }) => {
- let urlContext = MASTODON_STATUS_CONTEXT_URL(id)
+ const urlContext = MASTODON_STATUS_CONTEXT_URL(id)
return fetch(urlContext, { headers: authHeaders(credentials) })
.then((data) => {
if (data.ok) {
@@ -391,7 +520,7 @@ const fetchConversation = ({ id, credentials }) => {
}
const fetchStatus = ({ id, credentials }) => {
- let url = MASTODON_STATUS_URL(id)
+ const url = MASTODON_STATUS_URL(id)
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => {
if (data.ok) {
@@ -403,6 +532,31 @@ const fetchStatus = ({ id, credentials }) => {
.then((data) => parseStatus(data))
}
+const fetchStatusSource = ({ id, credentials }) => {
+ const url = MASTODON_STATUS_SOURCE_URL(id)
+ return fetch(url, { headers: authHeaders(credentials) })
+ .then((data) => {
+ if (data.ok) {
+ return data
+ }
+ throw new Error('Error fetching source', data)
+ })
+ .then((data) => data.json())
+ .then((data) => parseSource(data))
+}
+
+const fetchStatusHistory = ({ status, credentials }) => {
+ const url = MASTODON_STATUS_HISTORY_URL(status.id)
+ return promisedRequest({ url, credentials })
+ .then((data) => {
+ data.reverse()
+ return data.map((item) => {
+ item.originalStatus = status
+ return parseStatus(item)
+ })
+ })
+}
+
const tagUser = ({ tag, credentials, user }) => {
const screenName = user.screen_name
const form = {
@@ -415,7 +569,7 @@ const tagUser = ({ tag, credentials, user }) => {
return fetch(TAG_USER_URL, {
method: 'PUT',
- headers: headers,
+ headers,
body: JSON.stringify(form)
})
}
@@ -432,7 +586,7 @@ const untagUser = ({ tag, credentials, user }) => {
return fetch(TAG_USER_URL, {
method: 'DELETE',
- headers: headers,
+ headers,
body: JSON.stringify(body)
})
}
@@ -485,7 +639,7 @@ const deleteUser = ({ credentials, user }) => {
return fetch(`${ADMIN_USERS_URL}?nickname=${screenName}`, {
method: 'DELETE',
- headers: headers
+ headers
})
}
@@ -495,18 +649,21 @@ const fetchTimeline = ({
since = false,
until = false,
userId = false,
+ listId = false,
tag = false,
withMuted = false,
- replyVisibility = 'all'
+ replyVisibility = 'all',
+ includeTypes = []
}) => {
const timelineUrls = {
public: MASTODON_PUBLIC_TIMELINE,
friends: MASTODON_USER_HOME_TIMELINE_URL,
dms: MASTODON_DIRECT_MESSAGES_TIMELINE_URL,
notifications: MASTODON_USER_NOTIFICATIONS_URL,
- 'publicAndExternal': MASTODON_PUBLIC_TIMELINE,
+ publicAndExternal: MASTODON_PUBLIC_TIMELINE,
user: MASTODON_USER_TIMELINE_URL,
media: MASTODON_USER_TIMELINE_URL,
+ list: MASTODON_LIST_TIMELINE_URL,
favorites: MASTODON_USER_FAVORITES_TIMELINE_URL,
tag: MASTODON_TAG_TIMELINE_URL,
bookmarks: MASTODON_BOOKMARK_TIMELINE_URL
@@ -520,6 +677,10 @@ const fetchTimeline = ({
url = url(userId)
}
+ if (timeline === 'list') {
+ url = url(listId)
+ }
+
if (since) {
params.push(['since_id', since])
}
@@ -544,6 +705,11 @@ const fetchTimeline = ({
if (replyVisibility !== 'all') {
params.push(['reply_visibility', replyVisibility])
}
+ if (includeTypes.length > 0) {
+ includeTypes.forEach(type => {
+ params.push(['include_types[]', type])
+ })
+ }
params.push(['limit', 20])
@@ -678,7 +844,7 @@ const postStatus = ({
form.append('preview', 'true')
}
- let postHeaders = authHeaders(credentials)
+ const postHeaders = authHeaders(credentials)
if (idempotencyKey) {
postHeaders['idempotency-key'] = idempotencyKey
}
@@ -694,6 +860,54 @@ const postStatus = ({
.then((data) => data.error ? data : parseStatus(data))
}
+const editStatus = ({
+ id,
+ credentials,
+ status,
+ spoilerText,
+ sensitive,
+ poll,
+ mediaIds = [],
+ contentType
+}) => {
+ const form = new FormData()
+ const pollOptions = poll.options || []
+
+ form.append('status', status)
+ if (spoilerText) form.append('spoiler_text', spoilerText)
+ if (sensitive) form.append('sensitive', sensitive)
+ if (contentType) form.append('content_type', contentType)
+ mediaIds.forEach(val => {
+ form.append('media_ids[]', val)
+ })
+
+ if (pollOptions.some(option => option !== '')) {
+ const normalizedPoll = {
+ expires_in: poll.expiresIn,
+ multiple: poll.multiple
+ }
+ Object.keys(normalizedPoll).forEach(key => {
+ form.append(`poll[${key}]`, normalizedPoll[key])
+ })
+
+ pollOptions.forEach(option => {
+ form.append('poll[options][]', option)
+ })
+ }
+
+ const putHeaders = authHeaders(credentials)
+
+ return fetch(MASTODON_STATUS_URL(id), {
+ body: form,
+ method: 'PUT',
+ headers: putHeaders
+ })
+ .then((response) => {
+ return response.json()
+ })
+ .then((data) => data.error ? data : parseStatus(data))
+}
+
const deleteStatus = ({ id, credentials }) => {
return fetch(MASTODON_DELETE_URL(id), {
headers: authHeaders(credentials),
@@ -782,6 +996,49 @@ const changeEmail = ({ credentials, email, password }) => {
.then((response) => response.json())
}
+const moveAccount = ({ credentials, password, targetAccount }) => {
+ const form = new FormData()
+
+ form.append('password', password)
+ form.append('target_account', targetAccount)
+
+ return fetch(MOVE_ACCOUNT_URL, {
+ body: form,
+ method: 'POST',
+ headers: authHeaders(credentials)
+ })
+ .then((response) => response.json())
+}
+
+const addAlias = ({ credentials, alias }) => {
+ return promisedRequest({
+ url: ALIASES_URL,
+ method: 'PUT',
+ credentials,
+ payload: { alias }
+ })
+}
+
+const deleteAlias = ({ credentials, alias }) => {
+ return promisedRequest({
+ url: ALIASES_URL,
+ method: 'DELETE',
+ credentials,
+ payload: { alias }
+ })
+}
+
+const listAliases = ({ credentials }) => {
+ return promisedRequest({
+ url: ALIASES_URL,
+ method: 'GET',
+ credentials,
+ params: {
+ _cacheBooster: (new Date()).getTime()
+ }
+ })
+}
+
const changePassword = ({ credentials, password, newPassword, newPasswordConfirmation }) => {
const form = new FormData()
@@ -868,6 +1125,25 @@ const fetchBlocks = ({ credentials }) => {
.then((users) => users.map(parseUser))
}
+const addBackup = ({ credentials }) => {
+ return promisedRequest({
+ url: PLEROMA_BACKUP_URL,
+ method: 'POST',
+ credentials
+ })
+}
+
+const listBackups = ({ credentials }) => {
+ return promisedRequest({
+ url: PLEROMA_BACKUP_URL,
+ method: 'GET',
+ credentials,
+ params: {
+ _cacheBooster: (new Date()).getTime()
+ }
+ })
+}
+
const fetchOAuthTokens = ({ credentials }) => {
const url = '/api/oauth_tokens.json'
@@ -921,7 +1197,7 @@ const vote = ({ pollId, choices, credentials }) => {
method: 'POST',
credentials,
payload: {
- choices: choices
+ choices
}
})
}
@@ -981,8 +1257,8 @@ const reportUser = ({ credentials, userId, statusIds, comment, forward }) => {
url: MASTODON_REPORT_USER_URL,
method: 'POST',
payload: {
- 'account_id': userId,
- 'status_ids': statusIds,
+ account_id: userId,
+ status_ids: statusIds,
comment,
forward
},
@@ -1004,7 +1280,7 @@ const searchUsers = ({ credentials, query }) => {
const search2 = ({ credentials, q, resolve, limit, offset, following, type }) => {
let url = MASTODON_SEARCH_2
- let params = []
+ const params = []
if (q) {
params.push(['q', encodeURIComponent(q)])
@@ -1032,7 +1308,7 @@ const search2 = ({ credentials, q, resolve, limit, offset, following, type }) =>
params.push(['with_relationships', true])
- let queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
+ const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
url += `?${queryString}`
return fetch(url, { headers: authHeaders(credentials) })
@@ -1102,7 +1378,8 @@ const MASTODON_STREAMING_EVENTS = new Set([
'update',
'notification',
'delete',
- 'filters_changed'
+ 'filters_changed',
+ 'status.update'
])
const PLEROMA_STREAMING_EVENTS = new Set([
@@ -1174,6 +1451,8 @@ export const handleMastoWS = (wsEvent) => {
const data = payload ? JSON.parse(payload) : null
if (event === 'update') {
return { event, status: parseStatus(data) }
+ } else if (event === 'status.update') {
+ return { event, status: parseStatus(data) }
} else if (event === 'notification') {
return { event, notification: parseNotification(data) }
} else if (event === 'pleroma:chat_update') {
@@ -1186,12 +1465,12 @@ export const handleMastoWS = (wsEvent) => {
}
export const WSConnectionStatus = Object.freeze({
- 'JOINED': 1,
- 'CLOSED': 2,
- 'ERROR': 3,
- 'DISABLED': 4,
- 'STARTING': 5,
- 'STARTING_INITIAL': 6
+ JOINED: 1,
+ CLOSED: 2,
+ ERROR: 3,
+ DISABLED: 4,
+ STARTING: 5,
+ STARTING_INITIAL: 6
})
const chats = ({ credentials }) => {
@@ -1229,11 +1508,11 @@ const chatMessages = ({ id, credentials, maxId, sinceId, limit = 20 }) => {
const sendChatMessage = ({ id, content, mediaId = null, idempotencyKey, credentials }) => {
const payload = {
- 'content': content
+ content
}
if (mediaId) {
- payload['media_id'] = mediaId
+ payload.media_id = mediaId
}
const headers = {}
@@ -1245,7 +1524,7 @@ const sendChatMessage = ({ id, content, mediaId = null, idempotencyKey, credenti
return promisedRequest({
url: PLEROMA_CHAT_MESSAGES_URL(id),
method: 'POST',
- payload: payload,
+ payload,
credentials,
headers
})
@@ -1256,7 +1535,7 @@ const readChat = ({ id, lastReadId, credentials }) => {
url: PLEROMA_CHAT_READ_URL(id),
method: 'POST',
payload: {
- 'last_read_id': lastReadId
+ last_read_id: lastReadId
},
credentials
})
@@ -1270,12 +1549,46 @@ const deleteChatMessage = ({ chatId, messageId, credentials }) => {
})
}
+const setReportState = ({ id, state, credentials }) => {
+ // TODO: Can't use promisedRequest because on OK this does not return json
+ // See https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1322
+ return fetch(PLEROMA_ADMIN_REPORTS, {
+ headers: {
+ ...authHeaders(credentials),
+ Accept: 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ method: 'PATCH',
+ body: JSON.stringify({
+ reports: [{
+ id,
+ state
+ }]
+ })
+ })
+ .then(data => {
+ if (data.status >= 500) {
+ throw Error(data.statusText)
+ } else if (data.status >= 400) {
+ return data.json()
+ }
+ return data
+ })
+ .then(data => {
+ if (data.errors) {
+ throw Error(data.errors[0].message)
+ }
+ })
+}
+
const apiService = {
verifyCredentials,
fetchTimeline,
fetchPinnedStatuses,
fetchConversation,
fetchStatus,
+ fetchStatusSource,
+ fetchStatusHistory,
fetchFriends,
exportFriends,
fetchFollowers,
@@ -1287,7 +1600,9 @@ const apiService = {
unmuteConversation,
blockUser,
unblockUser,
+ removeUserFromFollowers,
fetchUser,
+ fetchUserByName,
fetchUserRelationship,
favorite,
unfavorite,
@@ -1296,6 +1611,7 @@ const apiService = {
bookmarkStatus,
unbookmarkStatus,
postStatus,
+ editStatus,
deleteStatus,
uploadMedia,
setMediaDescription,
@@ -1323,13 +1639,27 @@ const apiService = {
importFollows,
deleteAccount,
changeEmail,
+ moveAccount,
+ addAlias,
+ deleteAlias,
+ listAliases,
changePassword,
settingsMFA,
mfaDisableOTP,
generateMfaBackupCodes,
mfaSetupOTP,
mfaConfirmOTP,
+ addBackup,
+ listBackups,
fetchFollowRequests,
+ fetchLists,
+ createList,
+ getList,
+ updateList,
+ getListAccounts,
+ addAccountsToList,
+ removeAccountsFromList,
+ deleteList,
approveUser,
denyUser,
suggestions,
@@ -1355,7 +1685,9 @@ const apiService = {
chatMessages,
sendChatMessage,
readChat,
- deleteChatMessage
+ deleteChatMessage,
+ setReportState,
+ fetchUserInLists
}
export default apiService