aboutsummaryrefslogtreecommitdiff
path: root/src/services/api/api.service.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/api/api.service.js')
-rw-r--r--src/services/api/api.service.js66
1 files changed, 51 insertions, 15 deletions
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 3a4f21a6..eac151eb 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -5,17 +5,10 @@ const ALL_FOLLOWING_URL = '/api/qvitter/allfollowing'
const PUBLIC_TIMELINE_URL = '/api/statuses/public_timeline.json'
const PUBLIC_AND_EXTERNAL_TIMELINE_URL = '/api/statuses/public_and_external_timeline.json'
const TAG_TIMELINE_URL = '/api/statusnet/tags/timeline'
-const FAVORITE_URL = '/api/favorites/create'
-const UNFAVORITE_URL = '/api/favorites/destroy'
-const RETWEET_URL = '/api/statuses/retweet'
-const UNRETWEET_URL = '/api/statuses/unretweet'
-const STATUS_DELETE_URL = '/api/statuses/destroy'
const MENTIONS_URL = '/api/statuses/mentions.json'
const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json'
const FOLLOWERS_URL = '/api/statuses/followers.json'
const FRIENDS_URL = '/api/statuses/friends.json'
-const FOLLOWING_URL = '/api/friendships/create.json'
-const UNFOLLOWING_URL = '/api/friendships/destroy.json'
const REGISTRATION_URL = '/api/account/register.json'
const AVATAR_UPDATE_URL = '/api/qvitter/update_avatar.json'
const BG_UPDATE_URL = '/api/qvitter/update_background_image.json'
@@ -33,6 +26,17 @@ const DENY_USER_URL = '/api/pleroma/friendships/deny'
const SUGGESTIONS_URL = '/api/v1/suggestions'
const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites'
+const MASTODON_FAVORITE_URL = id => `/api/v1/statuses/${id}/favourite`
+const MASTODON_UNFAVORITE_URL = id => `/api/v1/statuses/${id}/unfavourite`
+const MASTODON_RETWEET_URL = id => `/api/v1/statuses/${id}/reblog`
+const MASTODON_UNRETWEET_URL = id => `/api/v1/statuses/${id}/unreblog`
+const MASTODON_DELETE_URL = id => `/api/v1/statuses/${id}`
+const MASTODON_FOLLOW_URL = id => `/api/v1/accounts/${id}/follow`
+const MASTODON_UNFOLLOW_URL = id => `/api/v1/accounts/${id}/unfollow`
+const MASTODON_BLOCK_URL = id => `/api/v1/accounts/${id}/block`
+const MASTODON_UNBLOCK_URL = id => `/api/v1/accounts/${id}/unblock`
+const MASTODON_MUTE_URL = id => `/api/v1/accounts/${id}/mute`
+const MASTODON_UNMUTE_URL = id => `/api/v1/accounts/${id}/unmute`
const MASTODON_STATUS_URL = id => `/api/v1/statuses/${id}`
const MASTODON_STATUS_CONTEXT_URL = id => `/api/v1/statuses/${id}/context`
const MASTODON_USER_URL = '/api/v1/accounts'
@@ -211,7 +215,7 @@ const externalProfile = ({profileUrl, credentials}) => {
}
const followUser = ({id, credentials}) => {
- let url = `${FOLLOWING_URL}?user_id=${id}`
+ let url = MASTODON_FOLLOW_URL(id)
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST'
@@ -219,7 +223,7 @@ const followUser = ({id, credentials}) => {
}
const unfollowUser = ({id, credentials}) => {
- let url = `${UNFOLLOWING_URL}?user_id=${id}`
+ let url = MASTODON_UNFOLLOW_URL(id)
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST'
@@ -415,31 +419,63 @@ const verifyCredentials = (user) => {
}
const favorite = ({ id, credentials }) => {
- return fetch(`${FAVORITE_URL}/${id}.json`, {
+ return fetch(MASTODON_FAVORITE_URL(id), {
headers: authHeaders(credentials),
method: 'POST'
})
+ .then(response => {
+ if (response.ok) {
+ return response.json()
+ } else {
+ return {}
+ }
+ })
+ .then((data) => parseStatus(data))
}
const unfavorite = ({ id, credentials }) => {
- return fetch(`${UNFAVORITE_URL}/${id}.json`, {
+ return fetch(MASTODON_UNFAVORITE_URL(id), {
headers: authHeaders(credentials),
method: 'POST'
})
+ .then(response => {
+ if (response.ok) {
+ return response.json()
+ } else {
+ return {}
+ }
+ })
+ .then((data) => parseStatus(data))
}
const retweet = ({ id, credentials }) => {
- return fetch(`${RETWEET_URL}/${id}.json`, {
+ return fetch(MASTODON_RETWEET_URL(id), {
headers: authHeaders(credentials),
method: 'POST'
})
+ .then(response => {
+ if (response.ok) {
+ return response.json()
+ } else {
+ return {}
+ }
+ })
+ .then((data) => parseStatus(data))
}
const unretweet = ({ id, credentials }) => {
- return fetch(`${UNRETWEET_URL}/${id}.json`, {
+ return fetch(MASTODON_UNRETWEET_URL(id), {
headers: authHeaders(credentials),
method: 'POST'
})
+ .then(response => {
+ if (response.ok) {
+ return response.json()
+ } else {
+ return {}
+ }
+ })
+ .then((data) => parseStatus(data))
}
const postStatus = ({credentials, status, spoilerText, visibility, sensitive, mediaIds = [], inReplyToStatusId, contentType}) => {
@@ -476,9 +512,9 @@ const postStatus = ({credentials, status, spoilerText, visibility, sensitive, me
}
const deleteStatus = ({ id, credentials }) => {
- return fetch(`${STATUS_DELETE_URL}/${id}.json`, {
+ return fetch(MASTODON_DELETE_URL(id), {
headers: authHeaders(credentials),
- method: 'POST'
+ method: 'DELETE'
})
}