UsersController
struct UsersController : APIRouteCollection
The collection of /api/v3/user/* route endpoints and handler functions related
to a user’s own data.
Separating these from the endpoints related to users in general helps make for a
cleaner collection, since use of User.parameter in the paths here can be avoided
entirely.
-
Required. Registers routes to the incoming router.
Declaration
Swift
func registerRoutes(_ app: Application) throws
-
GET /api/v3/users/find/:usernameRetrieves a user’s
UserHeaderusing either an ID (UUID string) or a username.This endpoint is of limited utility, but is included for the case of obtaining a user’s ID from a username. If you have an ID and want the associated username, use the more efficient
/api/v3/users/IDendpoint instead.Note
Because a username can be changed, there is no guarantee that a once-valid username will result in a successful return, even though the User itself does exist.
Throws
404 error if no match is found.
Declaration
Swift
func findHandler(_ req: Request) throws -> UserHeaderParameters
STRINGin URL path. The userID or username to search for.
Return Value
UserHeadercontaining the user’s ID, username, displayName and userImage. -
GET /api/v3/users/:userIDRetrieves the specified user’s
UserHeaderinfo.This endpoint provides one-off retrieval of the user information appropriate for a header on posted content – the user’s ID, current generated
.displayedName, and filename of their current profile image.For bulk data retrieval, see the
ClientControllerendpoints.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func headerHandler(_ req: Request) throws -> UserHeaderParameters
userIDin URL path. The userID to search for.
Return Value
UserHeadercontaining the user’s ID,.displayedNameand profile image filename. -
profileHandler(_:Asynchronous) GET /api/v3/users/ID/profileRetrieves the specified user’s profile, as a
ProfilePublicDataobject.Throws
404 error if the profile is not available. A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func profileHandler(_ req: Request) async throws -> ProfilePublicDataParameters
userIDin URL path. The userID to search for.
Return Value
ProfilePublicDatacontaining the displayable properties of the specified user’s profile. -
matchAllNamesHandler(_:Asynchronous) GET /api/v3/users/match/allnames/STRINGRetrieves the first 10
User.userSearchvalues containing the specified substring, returning an array ofUserHeaderstructs.. The intended use for this endpoint is to help isolate a particular user in an auto-complete type scenario, by searching all of the.displayName,.usernameand.realNameprofile fields.Compare to
/api/v3/user/match/username/STRING, which searches just.usernameand returns an array of just strings.Note
If the search substring contains “unsafe” characters, they must be url encoded. Unicode characters are supported. A substring comprised only of whitespace is disallowed. A substring of “@” or “(@” is explicitly disallowed to prevent single-step username harvesting.For bulk
.userSearchdata retrieval, see theClientControllerendpoints.URL Query Parameters:
?favorers=BOOLEAN Show only resulting users that have favorited the requesting user.
See moreThrows
403 error if the search term is not permitted.
Declaration
Swift
func matchAllNamesHandler(_ req: Request) async throws -> [UserHeader]Parameters
STRINGin URL path. The search string to use. Must be at least 2 characters long.
Return Value
An array of
UserHeadervalues of all matching users. -
matchUsernameHandler(_:Asynchronous) GET /api/v3/users/match/username/STRINGRetrieves all usernames containing the specified substring, returning an array of
@usernamestrings. The intended use for this endpoint is to help isolate a particular user in an auto-complete type scenario.Note
An
@is prepended to each returned matching username as a convenience, but should never be included in the search itself. No base username can contain an@, thus there would never be a match.Declaration
Swift
func matchUsernameHandler(_ req: Request) async throws -> [String]Parameters
STRINGin URL path. The search string to use. Must be at least 2 characters long.
Return Value
An array of
Stringcontainng all matching usernames as “@username” strings.
-
noteCreateHandler(_:Asynchronous) POST /api/v3/users/ID/noteSaves a
UserNoteassociated with the specified user and the current user.Throws
400 error if the profile is a banned user’s. A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func noteCreateHandler(_ req: Request) async throws -> ResponseParameters
userIDin URL path. The user to associate with the note.
requestBodyNoteCreateDatastruct containing the text of the note.Return Value
NoteDatacontaining the newly created note. -
noteDeleteHandler(_:Asynchronous) POST /api/v3/users/ID/note/deleteDELETE /api/v3/users/ID/noteDeletes an existing
UserNoteassociated with the specified user’s profile and the current user.Throws
400 error if there is no existing note on the profile. A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func noteDeleteHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. Specifies the target of the note to be deleted.
Return Value
204 No Content on success.
-
noteHandler(_:Asynchronous) GET /api/v3/users/ID/noteRetrieves an existing
UserNoteassociated with the specified user’s profile and the current user.Note
In order to support the editing of a note in contexts other than when actively viewing a profile, the contents of
profile.notecannot be used to determine if there is an exiting associated UserNote, since it is possible for a valid note to contain no text at any given time. Use this GET endpoint prior to attempting a POST to it.Throws
400 error if there is no existing note on the profile. A 5xx response should be reported as a likely bug, please and thank you.
Declaration
Swift
func noteHandler(_ req: Request) async throws -> NoteDataParameters
userIDin URL path. The user the note is attached to.
Return Value
NoteEditDatacontaining the note’s ID and text. -
reportHandler(_:Asynchronous) POST /api/v3/users/ID/reportCreates a
Reportregarding the specified user’s profile, either the text fields or the avatar image.Note
The accompanying report message is optional on the part of the submitting user, but the
ReportDatais mandatory in order to allow one. If there is no message, send an empty string in the.messagefield.Declaration
Swift
func reportHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyReportDatacontaining an optional accompanying messageReturn Value
201 Created on success.
-
blocksHandler(_:Asynchronous) GET /api/v3/users/blocksReturns a list of the user’s currently blocked users as an array of
UserHeaderobjects. If the user is a sub-account, the parent user’s blocks are returned.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func blocksHandler(_ req: Request) async throws -> [UserHeader]Return Value
Array of
UserHeadercontaining the currently blocked users. -
blockHandler(_:Asynchronous) POST /api/v3/users/:userID/blockBlocks the specified
User. The blocking user and any sub-accounts will not be able to see posts from the blockedUseror any of their associated sub-accounts, and vice versa. This affects all forms of communication, public and private, as well as user searches.Only the specified user is added to the block list, so as not to explicitly expose the ownership of any other accounts the blocked user may be using. The blocking of any associated user accounts is handled under the hood.
Users with an
.accessLevelof.moderatoror higher may not be blocked. Attempting to block a moderator account directly will produce an error. A block applied to an alt account of a moderator will be accepted, but will not include the moderator in the set of blocked accounts. Similarly, moderators can block accounts, which has no effect on their moderator account but applies bidirectional blocks between their (non-moderator) alt accounts and the blocked accounts.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func blockHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. The userID to block.
Return Value
201 Created on success, 200 OK if user already in block list.
-
unblockHandler(_:Asynchronous) POST /api/v3/users/ID/unblockRemoves a block of the specified
Userand all sub-accounts by the current user and all associated accounts.Throws
400 error if the specified user was not currently blocked. A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func unblockHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. The user to unblock.
Return Value
204 No Content on success.
-
mutesHandler(_:Asynchronous) GET /api/v3/users/mutesReturns a list of the user’s currently muted users.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func mutesHandler(_ req: Request) async throws -> [UserHeader]Return Value
Array of
UserHeadercontaining the currently muted users. -
muteHandler(_:Asynchronous) POST /api/v3/users/ID/muteMutes the specified
Userfor the current user. The muting user will not see public posts from the muted user. A mute does not affect what is or is not visible to the muted user. A mute does not affect private communication channels.A mute does not mute any associated sub-accounts of the muted
User, nor is it applied to any of the muting user’s associated accounts. It is very much just this currently logged-in username muting that one username.Any user can be muted, including users with privileged
.accessLevel. Such users are not muted, however, when posting from role accounts. That is, a.moderatorcan post as@moderatorand it is visible to all users, period.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func muteHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. The userID to mute.
Return Value
201 Created on success.
-
unmuteHandler(_:Asynchronous) POST /api/v3/users/ID/unmuteRemoves a mute of the specified
Userby the current user.Throws
400 error if the specified user was not currently muted. A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func unmuteHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. The user to unmute.
Return Value
204 No Content on success.
-
favoritesHandler(_:Asynchronous) GET /api/v3/users/favoritesReturns a list of the user’s currently favorited users.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func favoritesHandler(_ req: Request) async throws -> [UserHeader]Return Value
An array of
UserHeadercontaining the currently favorited users. -
favoriteAddHandler(_:Asynchronous) POST /api/v3/users/:user_ID/favoriteFavorites the specified
Userfor the current user. Favoriting is a way to short-list friends for easy retrieval when using various Twitarr features.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func favoriteAddHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. The userID to favorite.
Return Value
201 Created on success.
-
favoriteRemoveHandler(_:Asynchronous) POST /api/v3/users/:user_ID/unfavoriteDELETE /api/v3/users/:user_id/favoriteRemoves a favorite of the specified
Userby the current user.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func favoriteRemoveHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. The user to unfavorite.
Return Value
204 No Content on success.
-
getUsersWithRole(_:Asynchronous) GET /api/v3/forum/userrole/:user_roleReturns a list of all users that have the given role. Currently, caller must have the
shutternautmanagerrole to call this, and can only query theshutternautrole.Throws
badRequest if the caller isn’t a shutternaut manager, or the user role param isn’tshutternaut.Declaration
Swift
func getUsersWithRole(_ req: Request) async throws -> [UserHeader]Return Value
Array of
UserHeader. Array may be empty if nobody has this role yet. -
addRoleForUser(_:Asynchronous) POST /api/v3/forum/userrole/:user_role/addrole/:user_idAdds the given role to the given user’s role list. Currently, caller must have the
shutternautmanagerrole to call this, and can only give a user theshutternautrole.Throws
badRequest if the target user already has the role, or if the caller role/role being set are invalid.Declaration
Swift
func addRoleForUser(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user now has the given role.
-
removeRoleForUser(_:Asynchronous) POST /api/v3/admin/userrole/:user_role/removerole/:user_idRemoves the given role from the target user’s role list. Currently, caller must have the
shutternautmanagerrole to call this, and can only remove theshutternautrole from a user’s role list.Throws
badRequest if the target user isn’t a Shutternaut Manager, the role being set isn’t Shutternaut. Does not error if the target user already doesn’t have the role.Declaration
Swift
func removeRoleForUser(_ req: Request) async throws -> HTTPStatusReturn Value
200 OK if the user was demoted successfully.
-
removeBlockFromCache(by:Asynchronousof: on: ) Updates the cache values for all accounts involved in a block removal. The currently blocked user and any associated accounts are removed from all blocking user’s associated accounts’ blocks caches, and vice versa.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Parameters
requesterThe
Userremoving the block.userThe
Usercurrently being blocked.reqThe incoming
Request, which provides theEventLoopon which this must run.Return Value
Void.
-
addBlockToCache(requestedBy:Asynchronousblocking: on: ) Updates the cache values for all accounts involved in a block. Blocked user and any associated accounts are added to all blocking user’s associated accounts’ blocks caches, and vice versa.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func addBlockToCache(requestedBy requester: User, blocking blockedUserID: UUID, on req: Request) async throwsParameters
requesterThe
Userrequesting the block.userThe
Userbeing blocked.reqThe incoming
Request, which provides theEventLoopon which this must run.Return Value
Void.
View on GitHub