|
|
@ -76,7 +76,7 @@ const MASTODON_PIN_OWN_STATUS = id => `/api/v1/statuses/${id}/pin`
|
|
|
|
const MASTODON_UNPIN_OWN_STATUS = id => `/api/v1/statuses/${id}/unpin`
|
|
|
|
const MASTODON_UNPIN_OWN_STATUS = id => `/api/v1/statuses/${id}/unpin`
|
|
|
|
const MASTODON_MUTE_CONVERSATION = id => `/api/v1/statuses/${id}/mute`
|
|
|
|
const MASTODON_MUTE_CONVERSATION = id => `/api/v1/statuses/${id}/mute`
|
|
|
|
const MASTODON_UNMUTE_CONVERSATION = id => `/api/v1/statuses/${id}/unmute`
|
|
|
|
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_USER_SEARCH_URL = '/api/v1/accounts/search'
|
|
|
|
const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks'
|
|
|
|
const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks'
|
|
|
|
const MASTODON_STREAMING = '/api/v1/streaming'
|
|
|
|
const MASTODON_STREAMING = '/api/v1/streaming'
|
|
|
@ -84,7 +84,7 @@ 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_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_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_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_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_MESSAGES_URL = id => `/api/v1/pleroma/chats/${id}/messages`
|
|
|
|
const PLEROMA_CHAT_READ_URL = id => `/api/v1/pleroma/chats/${id}/read`
|
|
|
|
const PLEROMA_CHAT_READ_URL = id => `/api/v1/pleroma/chats/${id}/read`
|
|
|
@ -93,7 +93,7 @@ const PLEROMA_BACKUP_URL = '/api/v1/pleroma/backups'
|
|
|
|
|
|
|
|
|
|
|
|
const oldfetch = window.fetch
|
|
|
|
const oldfetch = window.fetch
|
|
|
|
|
|
|
|
|
|
|
|
let fetch = (url, options) => {
|
|
|
|
const fetch = (url, options) => {
|
|
|
|
options = options || {}
|
|
|
|
options = options || {}
|
|
|
|
const baseUrl = ''
|
|
|
|
const baseUrl = ''
|
|
|
|
const fullUrl = baseUrl + url
|
|
|
|
const fullUrl = baseUrl + url
|
|
|
@ -105,7 +105,7 @@ const promisedRequest = ({ method, url, params, payload, credentials, headers =
|
|
|
|
const options = {
|
|
|
|
const options = {
|
|
|
|
method,
|
|
|
|
method,
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...headers
|
|
|
|
...headers
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -229,16 +229,16 @@ const getCaptcha = () => fetch('/api/pleroma/captcha').then(resp => resp.json())
|
|
|
|
|
|
|
|
|
|
|
|
const authHeaders = (accessToken) => {
|
|
|
|
const authHeaders = (accessToken) => {
|
|
|
|
if (accessToken) {
|
|
|
|
if (accessToken) {
|
|
|
|
return { 'Authorization': `Bearer ${accessToken}` }
|
|
|
|
return { Authorization: `Bearer ${accessToken}` }
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return { }
|
|
|
|
return { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const followUser = ({ id, credentials, ...options }) => {
|
|
|
|
const followUser = ({ id, credentials, ...options }) => {
|
|
|
|
let url = MASTODON_FOLLOW_URL(id)
|
|
|
|
const url = MASTODON_FOLLOW_URL(id)
|
|
|
|
const form = {}
|
|
|
|
const form = {}
|
|
|
|
if (options.reblogs !== undefined) { form['reblogs'] = options.reblogs }
|
|
|
|
if (options.reblogs !== undefined) { form.reblogs = options.reblogs }
|
|
|
|
return fetch(url, {
|
|
|
|
return fetch(url, {
|
|
|
|
body: JSON.stringify(form),
|
|
|
|
body: JSON.stringify(form),
|
|
|
|
headers: {
|
|
|
|
headers: {
|
|
|
@ -250,7 +250,7 @@ const followUser = ({ id, credentials, ...options }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const unfollowUser = ({ id, credentials }) => {
|
|
|
|
const unfollowUser = ({ id, credentials }) => {
|
|
|
|
let url = MASTODON_UNFOLLOW_URL(id)
|
|
|
|
const url = MASTODON_UNFOLLOW_URL(id)
|
|
|
|
return fetch(url, {
|
|
|
|
return fetch(url, {
|
|
|
|
headers: authHeaders(credentials),
|
|
|
|
headers: authHeaders(credentials),
|
|
|
|
method: 'POST'
|
|
|
|
method: 'POST'
|
|
|
@ -292,7 +292,7 @@ const unblockUser = ({ id, credentials }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const approveUser = ({ id, credentials }) => {
|
|
|
|
const approveUser = ({ id, credentials }) => {
|
|
|
|
let url = MASTODON_APPROVE_USER_URL(id)
|
|
|
|
const url = MASTODON_APPROVE_USER_URL(id)
|
|
|
|
return fetch(url, {
|
|
|
|
return fetch(url, {
|
|
|
|
headers: authHeaders(credentials),
|
|
|
|
headers: authHeaders(credentials),
|
|
|
|
method: 'POST'
|
|
|
|
method: 'POST'
|
|
|
@ -300,7 +300,7 @@ const approveUser = ({ id, credentials }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const denyUser = ({ id, credentials }) => {
|
|
|
|
const denyUser = ({ id, credentials }) => {
|
|
|
|
let url = MASTODON_DENY_USER_URL(id)
|
|
|
|
const url = MASTODON_DENY_USER_URL(id)
|
|
|
|
return fetch(url, {
|
|
|
|
return fetch(url, {
|
|
|
|
headers: authHeaders(credentials),
|
|
|
|
headers: authHeaders(credentials),
|
|
|
|
method: 'POST'
|
|
|
|
method: 'POST'
|
|
|
@ -308,13 +308,13 @@ const denyUser = ({ id, credentials }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fetchUser = ({ id, credentials }) => {
|
|
|
|
const fetchUser = ({ id, credentials }) => {
|
|
|
|
let url = `${MASTODON_USER_URL}/${id}`
|
|
|
|
const url = `${MASTODON_USER_URL}/${id}`
|
|
|
|
return promisedRequest({ url, credentials })
|
|
|
|
return promisedRequest({ url, credentials })
|
|
|
|
.then((data) => parseUser(data))
|
|
|
|
.then((data) => parseUser(data))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fetchUserRelationship = ({ 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) })
|
|
|
|
return fetch(url, { headers: authHeaders(credentials) })
|
|
|
|
.then((response) => {
|
|
|
|
.then((response) => {
|
|
|
|
return new Promise((resolve, reject) => response.json()
|
|
|
|
return new Promise((resolve, reject) => response.json()
|
|
|
@ -333,7 +333,7 @@ const fetchFriends = ({ id, maxId, sinceId, limit = 20, credentials }) => {
|
|
|
|
maxId && `max_id=${maxId}`,
|
|
|
|
maxId && `max_id=${maxId}`,
|
|
|
|
sinceId && `since_id=${sinceId}`,
|
|
|
|
sinceId && `since_id=${sinceId}`,
|
|
|
|
limit && `limit=${limit}`,
|
|
|
|
limit && `limit=${limit}`,
|
|
|
|
`with_relationships=true`
|
|
|
|
'with_relationships=true'
|
|
|
|
].filter(_ => _).join('&')
|
|
|
|
].filter(_ => _).join('&')
|
|
|
|
|
|
|
|
|
|
|
|
url = url + (args ? '?' + args : '')
|
|
|
|
url = url + (args ? '?' + args : '')
|
|
|
@ -368,7 +368,7 @@ const fetchFollowers = ({ id, maxId, sinceId, limit = 20, credentials }) => {
|
|
|
|
maxId && `max_id=${maxId}`,
|
|
|
|
maxId && `max_id=${maxId}`,
|
|
|
|
sinceId && `since_id=${sinceId}`,
|
|
|
|
sinceId && `since_id=${sinceId}`,
|
|
|
|
limit && `limit=${limit}`,
|
|
|
|
limit && `limit=${limit}`,
|
|
|
|
`with_relationships=true`
|
|
|
|
'with_relationships=true'
|
|
|
|
].filter(_ => _).join('&')
|
|
|
|
].filter(_ => _).join('&')
|
|
|
|
|
|
|
|
|
|
|
|
url += args ? '?' + args : ''
|
|
|
|
url += args ? '?' + args : ''
|
|
|
@ -385,7 +385,7 @@ const fetchFollowRequests = ({ credentials }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fetchConversation = ({ id, 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) })
|
|
|
|
return fetch(urlContext, { headers: authHeaders(credentials) })
|
|
|
|
.then((data) => {
|
|
|
|
.then((data) => {
|
|
|
|
if (data.ok) {
|
|
|
|
if (data.ok) {
|
|
|
@ -401,7 +401,7 @@ const fetchConversation = ({ id, credentials }) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fetchStatus = ({ id, credentials }) => {
|
|
|
|
const fetchStatus = ({ id, credentials }) => {
|
|
|
|
let url = MASTODON_STATUS_URL(id)
|
|
|
|
const url = MASTODON_STATUS_URL(id)
|
|
|
|
return fetch(url, { headers: authHeaders(credentials) })
|
|
|
|
return fetch(url, { headers: authHeaders(credentials) })
|
|
|
|
.then((data) => {
|
|
|
|
.then((data) => {
|
|
|
|
if (data.ok) {
|
|
|
|
if (data.ok) {
|
|
|
@ -425,7 +425,7 @@ const tagUser = ({ tag, credentials, user }) => {
|
|
|
|
|
|
|
|
|
|
|
|
return fetch(TAG_USER_URL, {
|
|
|
|
return fetch(TAG_USER_URL, {
|
|
|
|
method: 'PUT',
|
|
|
|
method: 'PUT',
|
|
|
|
headers: headers,
|
|
|
|
headers,
|
|
|
|
body: JSON.stringify(form)
|
|
|
|
body: JSON.stringify(form)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -442,7 +442,7 @@ const untagUser = ({ tag, credentials, user }) => {
|
|
|
|
|
|
|
|
|
|
|
|
return fetch(TAG_USER_URL, {
|
|
|
|
return fetch(TAG_USER_URL, {
|
|
|
|
method: 'DELETE',
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: headers,
|
|
|
|
headers,
|
|
|
|
body: JSON.stringify(body)
|
|
|
|
body: JSON.stringify(body)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -495,7 +495,7 @@ const deleteUser = ({ credentials, user }) => {
|
|
|
|
|
|
|
|
|
|
|
|
return fetch(`${ADMIN_USERS_URL}?nickname=${screenName}`, {
|
|
|
|
return fetch(`${ADMIN_USERS_URL}?nickname=${screenName}`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: headers
|
|
|
|
headers
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -514,7 +514,7 @@ const fetchTimeline = ({
|
|
|
|
friends: MASTODON_USER_HOME_TIMELINE_URL,
|
|
|
|
friends: MASTODON_USER_HOME_TIMELINE_URL,
|
|
|
|
dms: MASTODON_DIRECT_MESSAGES_TIMELINE_URL,
|
|
|
|
dms: MASTODON_DIRECT_MESSAGES_TIMELINE_URL,
|
|
|
|
notifications: MASTODON_USER_NOTIFICATIONS_URL,
|
|
|
|
notifications: MASTODON_USER_NOTIFICATIONS_URL,
|
|
|
|
'publicAndExternal': MASTODON_PUBLIC_TIMELINE,
|
|
|
|
publicAndExternal: MASTODON_PUBLIC_TIMELINE,
|
|
|
|
user: MASTODON_USER_TIMELINE_URL,
|
|
|
|
user: MASTODON_USER_TIMELINE_URL,
|
|
|
|
media: MASTODON_USER_TIMELINE_URL,
|
|
|
|
media: MASTODON_USER_TIMELINE_URL,
|
|
|
|
favorites: MASTODON_USER_FAVORITES_TIMELINE_URL,
|
|
|
|
favorites: MASTODON_USER_FAVORITES_TIMELINE_URL,
|
|
|
@ -688,7 +688,7 @@ const postStatus = ({
|
|
|
|
form.append('preview', 'true')
|
|
|
|
form.append('preview', 'true')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let postHeaders = authHeaders(credentials)
|
|
|
|
const postHeaders = authHeaders(credentials)
|
|
|
|
if (idempotencyKey) {
|
|
|
|
if (idempotencyKey) {
|
|
|
|
postHeaders['idempotency-key'] = idempotencyKey
|
|
|
|
postHeaders['idempotency-key'] = idempotencyKey
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -993,7 +993,7 @@ const vote = ({ pollId, choices, credentials }) => {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
credentials,
|
|
|
|
credentials,
|
|
|
|
payload: {
|
|
|
|
payload: {
|
|
|
|
choices: choices
|
|
|
|
choices
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1053,8 +1053,8 @@ const reportUser = ({ credentials, userId, statusIds, comment, forward }) => {
|
|
|
|
url: MASTODON_REPORT_USER_URL,
|
|
|
|
url: MASTODON_REPORT_USER_URL,
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
payload: {
|
|
|
|
payload: {
|
|
|
|
'account_id': userId,
|
|
|
|
account_id: userId,
|
|
|
|
'status_ids': statusIds,
|
|
|
|
status_ids: statusIds,
|
|
|
|
comment,
|
|
|
|
comment,
|
|
|
|
forward
|
|
|
|
forward
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -1076,7 +1076,7 @@ const searchUsers = ({ credentials, query }) => {
|
|
|
|
|
|
|
|
|
|
|
|
const search2 = ({ credentials, q, resolve, limit, offset, following }) => {
|
|
|
|
const search2 = ({ credentials, q, resolve, limit, offset, following }) => {
|
|
|
|
let url = MASTODON_SEARCH_2
|
|
|
|
let url = MASTODON_SEARCH_2
|
|
|
|
let params = []
|
|
|
|
const params = []
|
|
|
|
|
|
|
|
|
|
|
|
if (q) {
|
|
|
|
if (q) {
|
|
|
|
params.push(['q', encodeURIComponent(q)])
|
|
|
|
params.push(['q', encodeURIComponent(q)])
|
|
|
@ -1100,7 +1100,7 @@ const search2 = ({ credentials, q, resolve, limit, offset, following }) => {
|
|
|
|
|
|
|
|
|
|
|
|
params.push(['with_relationships', true])
|
|
|
|
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}`
|
|
|
|
url += `?${queryString}`
|
|
|
|
|
|
|
|
|
|
|
|
return fetch(url, { headers: authHeaders(credentials) })
|
|
|
|
return fetch(url, { headers: authHeaders(credentials) })
|
|
|
@ -1254,12 +1254,12 @@ export const handleMastoWS = (wsEvent) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const WSConnectionStatus = Object.freeze({
|
|
|
|
export const WSConnectionStatus = Object.freeze({
|
|
|
|
'JOINED': 1,
|
|
|
|
JOINED: 1,
|
|
|
|
'CLOSED': 2,
|
|
|
|
CLOSED: 2,
|
|
|
|
'ERROR': 3,
|
|
|
|
ERROR: 3,
|
|
|
|
'DISABLED': 4,
|
|
|
|
DISABLED: 4,
|
|
|
|
'STARTING': 5,
|
|
|
|
STARTING: 5,
|
|
|
|
'STARTING_INITIAL': 6
|
|
|
|
STARTING_INITIAL: 6
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const chats = ({ credentials }) => {
|
|
|
|
const chats = ({ credentials }) => {
|
|
|
@ -1297,11 +1297,11 @@ const chatMessages = ({ id, credentials, maxId, sinceId, limit = 20 }) => {
|
|
|
|
|
|
|
|
|
|
|
|
const sendChatMessage = ({ id, content, mediaId = null, idempotencyKey, credentials }) => {
|
|
|
|
const sendChatMessage = ({ id, content, mediaId = null, idempotencyKey, credentials }) => {
|
|
|
|
const payload = {
|
|
|
|
const payload = {
|
|
|
|
'content': content
|
|
|
|
content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mediaId) {
|
|
|
|
if (mediaId) {
|
|
|
|
payload['media_id'] = mediaId
|
|
|
|
payload.media_id = mediaId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const headers = {}
|
|
|
|
const headers = {}
|
|
|
@ -1313,7 +1313,7 @@ const sendChatMessage = ({ id, content, mediaId = null, idempotencyKey, credenti
|
|
|
|
return promisedRequest({
|
|
|
|
return promisedRequest({
|
|
|
|
url: PLEROMA_CHAT_MESSAGES_URL(id),
|
|
|
|
url: PLEROMA_CHAT_MESSAGES_URL(id),
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
payload: payload,
|
|
|
|
payload,
|
|
|
|
credentials,
|
|
|
|
credentials,
|
|
|
|
headers
|
|
|
|
headers
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -1324,7 +1324,7 @@ const readChat = ({ id, lastReadId, credentials }) => {
|
|
|
|
url: PLEROMA_CHAT_READ_URL(id),
|
|
|
|
url: PLEROMA_CHAT_READ_URL(id),
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
payload: {
|
|
|
|
payload: {
|
|
|
|
'last_read_id': lastReadId
|
|
|
|
last_read_id: lastReadId
|
|
|
|
},
|
|
|
|
},
|
|
|
|
credentials
|
|
|
|
credentials
|
|
|
|
})
|
|
|
|
})
|
|
|
|