aboutsummaryrefslogtreecommitdiff
path: root/src/services/api/api.service.js
diff options
context:
space:
mode:
authorTae Hoon <th.dev91@gmail.com>2019-07-10 16:58:49 +0000
committerShpuld Shpludson <shp@cock.li>2019-07-10 16:58:49 +0000
commit532b76eb64119848d424d6d0d644a72d817fba59 (patch)
tree6fa46aa43455ce5df0a1ff64747083be8af1f924 /src/services/api/api.service.js
parent2f87540612e5e46b6cd0fb343d8f9bfdb0dad333 (diff)
Refactor user search api, better api error response handling
Diffstat (limited to 'src/services/api/api.service.js')
-rw-r--r--src/services/api/api.service.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 22db671e..304fc869 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -65,6 +65,7 @@ const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials'
const MASTODON_REPORT_USER_URL = '/api/v1/reports'
const MASTODON_PIN_OWN_STATUS = id => `/api/v1/statuses/${id}/pin`
const MASTODON_UNPIN_OWN_STATUS = id => `/api/v1/statuses/${id}/unpin`
+const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search'
const oldfetch = window.fetch
@@ -76,7 +77,7 @@ let fetch = (url, options) => {
return oldfetch(fullUrl, options)
}
-const promisedRequest = ({ method, url, payload, credentials, headers = {} }) => {
+const promisedRequest = ({ method, url, params, payload, credentials, headers = {} }) => {
const options = {
method,
headers: {
@@ -85,6 +86,11 @@ const promisedRequest = ({ method, url, payload, credentials, headers = {} }) =>
...headers
}
}
+ if (params) {
+ url += '?' + Object.entries(params)
+ .map(([key, value]) => encodeURIComponent(key) + '=' + encodeURIComponent(value))
+ .join('&')
+ }
if (payload) {
options.body = JSON.stringify(payload)
}
@@ -837,6 +843,18 @@ const reportUser = ({ credentials, userId, statusIds, comment, forward }) => {
})
}
+const searchUsers = ({ credentials, query }) => {
+ return promisedRequest({
+ url: MASTODON_USER_SEARCH_URL,
+ params: {
+ q: query,
+ resolve: true
+ },
+ credentials
+ })
+ .then((data) => data.map(parseUser))
+}
+
const apiService = {
verifyCredentials,
fetchTimeline,
@@ -899,7 +917,8 @@ const apiService = {
fetchFavoritedByUsers,
fetchRebloggedByUsers,
reportUser,
- updateNotificationSettings
+ updateNotificationSettings,
+ searchUsers
}
export default apiService