aboutsummaryrefslogtreecommitdiff
path: root/src/services/api/api.service.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2022-08-23 21:52:17 +0300
committerHenry Jameson <me@hjkos.com>2022-08-23 21:52:17 +0300
commitcd7380efe74b791c042c2d7af307dadbc3acd99f (patch)
tree54aaf9eb79cc805ed409ddf364dad1733f957c38 /src/services/api/api.service.js
parentbd7356376ec9137da674f146a89c17ed62f56bc3 (diff)
parent361aea13998bfba512a81422d3d0ca5b13ee60ee (diff)
Merge remote-tracking branch 'origin/develop' into navigation-update
* origin/develop: Update dependency opn to v5 fix notices being under the navbar, also change offset to use variable fix modals not having proper z index reduce indexes to be below 9999 so that develop error messages appear above Do not allow to find by name in findUser() Use lookup endpoint to obtain users by nickname Use $ for id UserProfile routes Allow opening profile: multiChoiceProprties record, anonymous access Allow opening profile when clicking an avatar inside of user popover
Diffstat (limited to 'src/services/api/api.service.js')
-rw-r--r--src/services/api/api.service.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index df899827..dd85b281 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -50,6 +50,7 @@ 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_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`
@@ -326,6 +327,25 @@ const fetchUser = ({ id, 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 }) => {
const url = `${MASTODON_USER_RELATIONSHIPS_URL}/?id=${id}`
return fetch(url, { headers: authHeaders(credentials) })
@@ -1489,6 +1509,7 @@ const apiService = {
blockUser,
unblockUser,
fetchUser,
+ fetchUserByName,
fetchUserRelationship,
favorite,
unfavorite,