2021-05-08 12:25:55 +00:00
/ *
GoToSocial
2023-01-05 11:43:00 +00:00
Copyright ( C ) 2021 - 2023 GoToSocial Authors admin @ gotosocial . org
2021-05-08 12:25:55 +00:00
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Affero General Public License for more details .
You should have received a copy of the GNU Affero General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2021-05-30 11:12:00 +00:00
package processing
2021-05-08 12:25:55 +00:00
import (
2021-05-15 09:58:11 +00:00
"context"
2021-05-08 12:25:55 +00:00
"net/http"
2021-07-05 11:23:03 +00:00
"net/url"
2022-10-08 12:00:39 +00:00
"time"
2021-05-08 12:25:55 +00:00
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
2022-05-15 09:16:43 +00:00
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
2021-05-08 12:25:55 +00:00
"github.com/superseriousbusiness/gotosocial/internal/db"
2021-10-31 14:46:23 +00:00
"github.com/superseriousbusiness/gotosocial/internal/email"
2021-05-08 12:25:55 +00:00
"github.com/superseriousbusiness/gotosocial/internal/federation"
2021-06-13 16:42:28 +00:00
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
2021-05-08 12:25:55 +00:00
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
2021-08-31 13:59:12 +00:00
"github.com/superseriousbusiness/gotosocial/internal/messages"
2021-05-08 12:25:55 +00:00
"github.com/superseriousbusiness/gotosocial/internal/oauth"
2021-07-05 11:23:03 +00:00
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
"github.com/superseriousbusiness/gotosocial/internal/processing/admin"
2021-10-24 09:57:39 +00:00
federationProcessor "github.com/superseriousbusiness/gotosocial/internal/processing/federation"
2021-07-05 11:23:03 +00:00
mediaProcessor "github.com/superseriousbusiness/gotosocial/internal/processing/media"
2023-01-23 12:14:21 +00:00
"github.com/superseriousbusiness/gotosocial/internal/processing/report"
2021-07-05 11:23:03 +00:00
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
"github.com/superseriousbusiness/gotosocial/internal/processing/streaming"
2021-10-14 12:26:04 +00:00
"github.com/superseriousbusiness/gotosocial/internal/processing/user"
2022-07-03 10:08:30 +00:00
"github.com/superseriousbusiness/gotosocial/internal/storage"
2021-09-01 16:29:25 +00:00
"github.com/superseriousbusiness/gotosocial/internal/stream"
2021-06-13 16:42:28 +00:00
"github.com/superseriousbusiness/gotosocial/internal/timeline"
2021-05-08 12:25:55 +00:00
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
2021-06-17 16:02:33 +00:00
"github.com/superseriousbusiness/gotosocial/internal/visibility"
2023-01-02 12:10:50 +00:00
"github.com/superseriousbusiness/oauth2/v4"
2021-05-08 12:25:55 +00:00
)
// Processor should be passed to api modules (see internal/apimodule/...). It is used for
// passing messages back and forth from the client API and the federating interface, via channels.
// It also contains logic for filtering which messages should end up where.
// It is designed to be used asynchronously: the client API and the federating API should just be able to
// fire messages into the processor and not wait for a reply before proceeding with other work. This allows
// for clean distribution of messages without slowing down the client API and harming the user experience.
type Processor interface {
// Start starts the Processor, reading from its channels and passing messages back and forth.
2022-04-28 12:23:11 +00:00
Start ( ) error
2021-05-08 12:25:55 +00:00
// Stop stops the processor cleanly, finishing handling any remaining messages before closing down.
Stop ( ) error
2021-09-04 11:29:56 +00:00
// ProcessFromClientAPI processes one message coming from the clientAPI channel, and triggers appropriate side effects.
ProcessFromClientAPI ( ctx context . Context , clientMsg messages . FromClientAPI ) error
// ProcessFromFederator processes one message coming from the federator channel, and triggers appropriate side effects.
ProcessFromFederator ( ctx context . Context , federatorMsg messages . FromFederator ) error
2021-05-08 12:25:55 +00:00
/ *
CLIENT API - FACING PROCESSING FUNCTIONS
These functions are intended to be called when the API client needs an immediate ( ie . , synchronous ) reply
to an HTTP request . As such , they will only do the bare - minimum of work necessary to give a properly
formed reply . For more intensive ( and time - consuming ) calls , where you don ' t require an immediate
response , pass work to the processor using a channel instead .
* /
// AccountCreate processes the given form for creating a new account, returning an oauth token for that account if successful.
2022-06-08 18:38:03 +00:00
AccountCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . AccountCreateRequest ) ( * apimodel . Token , gtserror . WithCode )
2022-03-15 15:12:35 +00:00
// AccountDeleteLocal processes the delete of a LOCAL account using the given form.
AccountDeleteLocal ( ctx context . Context , authed * oauth . Auth , form * apimodel . AccountDeleteRequest ) gtserror . WithCode
2021-05-08 12:25:55 +00:00
// AccountGet processes the given request for account information.
2022-04-15 12:33:01 +00:00
AccountGet ( ctx context . Context , authed * oauth . Auth , targetAccountID string ) ( * apimodel . Account , gtserror . WithCode )
// AccountGet processes the given request for account information.
AccountGetLocalByUsername ( ctx context . Context , authed * oauth . Auth , username string ) ( * apimodel . Account , gtserror . WithCode )
2022-09-12 11:14:29 +00:00
AccountGetCustomCSSForUsername ( ctx context . Context , username string ) ( string , gtserror . WithCode )
2022-10-08 12:00:39 +00:00
// AccountGetRSSFeedForUsername returns a function to get the RSS feed of latest posts for given local account username.
// This function should only be called if necessary: the given lastModified time can be used to check this.
// Will return 404 if an rss feed for that user is not available, or a different error if something else goes wrong.
AccountGetRSSFeedForUsername ( ctx context . Context , username string ) ( func ( ) ( string , gtserror . WithCode ) , time . Time , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
// AccountUpdate processes the update of an account with the given form
2022-06-08 18:38:03 +00:00
AccountUpdate ( ctx context . Context , authed * oauth . Auth , form * apimodel . UpdateCredentialsRequest ) ( * apimodel . Account , gtserror . WithCode )
2021-05-17 17:06:58 +00:00
// AccountStatusesGet fetches a number of statuses (in time descending order) from the given account, filtered by visibility for
// the account given in authed.
2022-10-10 13:52:49 +00:00
AccountStatusesGet ( ctx context . Context , authed * oauth . Auth , targetAccountID string , limit int , excludeReplies bool , excludeReblogs bool , maxID string , minID string , pinned bool , mediaOnly bool , publicOnly bool ) ( * apimodel . PageableResponse , gtserror . WithCode )
2022-07-13 07:57:47 +00:00
// AccountWebStatusesGet fetches a number of statuses (in descending order) from the given account. It selects only
// statuses which are suitable for showing on the public web profile of an account.
2022-10-10 13:52:49 +00:00
AccountWebStatusesGet ( ctx context . Context , targetAccountID string , maxID string ) ( * apimodel . PageableResponse , gtserror . WithCode )
2021-05-21 13:48:26 +00:00
// AccountFollowersGet fetches a list of the target account's followers.
2021-08-25 13:34:33 +00:00
AccountFollowersGet ( ctx context . Context , authed * oauth . Auth , targetAccountID string ) ( [ ] apimodel . Account , gtserror . WithCode )
2021-05-21 13:48:26 +00:00
// AccountFollowingGet fetches a list of the accounts that target account is following.
2021-08-25 13:34:33 +00:00
AccountFollowingGet ( ctx context . Context , authed * oauth . Auth , targetAccountID string ) ( [ ] apimodel . Account , gtserror . WithCode )
2021-05-21 13:48:26 +00:00
// AccountRelationshipGet returns a relationship model describing the relationship of the targetAccount to the Authed account.
2021-08-25 13:34:33 +00:00
AccountRelationshipGet ( ctx context . Context , authed * oauth . Auth , targetAccountID string ) ( * apimodel . Relationship , gtserror . WithCode )
2021-05-21 13:48:26 +00:00
// AccountFollowCreate handles a follow request to an account, either remote or local.
2021-08-25 13:34:33 +00:00
AccountFollowCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . AccountFollowRequest ) ( * apimodel . Relationship , gtserror . WithCode )
2021-05-21 13:48:26 +00:00
// AccountFollowRemove handles the removal of a follow/follow request to an account, either remote or local.
2021-08-25 13:34:33 +00:00
AccountFollowRemove ( ctx context . Context , authed * oauth . Auth , targetAccountID string ) ( * apimodel . Relationship , gtserror . WithCode )
2021-07-11 14:22:21 +00:00
// AccountBlockCreate handles the creation of a block from authed account to target account, either remote or local.
2021-08-25 13:34:33 +00:00
AccountBlockCreate ( ctx context . Context , authed * oauth . Auth , targetAccountID string ) ( * apimodel . Relationship , gtserror . WithCode )
2021-07-11 14:22:21 +00:00
// AccountBlockRemove handles the removal of a block from authed account to target account, either remote or local.
2021-08-25 13:34:33 +00:00
AccountBlockRemove ( ctx context . Context , authed * oauth . Auth , targetAccountID string ) ( * apimodel . Relationship , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
2022-03-19 11:01:40 +00:00
// AdminAccountAction handles the creation/execution of an action on an account.
AdminAccountAction ( ctx context . Context , authed * oauth . Auth , form * apimodel . AdminAccountActionRequest ) gtserror . WithCode
2021-05-09 12:06:06 +00:00
// AdminEmojiCreate handles the creation of a new instance emoji by an admin, using the given form.
2022-01-15 16:36:15 +00:00
AdminEmojiCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . EmojiCreateRequest ) ( * apimodel . Emoji , gtserror . WithCode )
2022-10-12 13:01:42 +00:00
// AdminEmojisGet allows admins to view emojis based on various filters.
AdminEmojisGet ( ctx context . Context , authed * oauth . Auth , domain string , includeDisabled bool , includeEnabled bool , shortcode string , maxShortcodeDomain string , minShortcodeDomain string , limit int ) ( * apimodel . PageableResponse , gtserror . WithCode )
2022-10-13 14:37:55 +00:00
// AdminEmojiGet returns the admin view of an emoji with the given ID
AdminEmojiGet ( ctx context . Context , authed * oauth . Auth , id string ) ( * apimodel . AdminEmoji , gtserror . WithCode )
2022-10-14 15:30:04 +00:00
// AdminEmojiDelete deletes one *local* emoji with the given key. Remote emojis will not be deleted this way.
// Only admin users in good standing should be allowed to access this function -- check this before calling it.
AdminEmojiDelete ( ctx context . Context , authed * oauth . Auth , id string ) ( * apimodel . AdminEmoji , gtserror . WithCode )
2022-11-24 18:12:07 +00:00
// AdminEmojiUpdate updates one local or remote emoji with the given key.
// Only admin users in good standing should be allowed to access this function -- check this before calling it.
AdminEmojiUpdate ( ctx context . Context , id string , form * apimodel . EmojiUpdateRequest ) ( * apimodel . AdminEmoji , gtserror . WithCode )
2022-11-14 22:47:27 +00:00
// AdminEmojiCategoriesGet gets a list of all existing emoji categories.
AdminEmojiCategoriesGet ( ctx context . Context ) ( [ ] * apimodel . EmojiCategory , gtserror . WithCode )
2021-07-05 11:23:03 +00:00
// AdminDomainBlockCreate handles the creation of a new domain block by an admin, using the given form.
2021-08-25 13:34:33 +00:00
AdminDomainBlockCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . DomainBlockCreateRequest ) ( * apimodel . DomainBlock , gtserror . WithCode )
2021-07-06 11:29:11 +00:00
// AdminDomainBlocksImport handles the import of multiple domain blocks by an admin, using the given form.
2021-08-25 13:34:33 +00:00
AdminDomainBlocksImport ( ctx context . Context , authed * oauth . Auth , form * apimodel . DomainBlockCreateRequest ) ( [ ] * apimodel . DomainBlock , gtserror . WithCode )
2021-07-05 11:23:03 +00:00
// AdminDomainBlocksGet returns a list of currently blocked domains.
2021-08-25 13:34:33 +00:00
AdminDomainBlocksGet ( ctx context . Context , authed * oauth . Auth , export bool ) ( [ ] * apimodel . DomainBlock , gtserror . WithCode )
2021-07-05 11:23:03 +00:00
// AdminDomainBlockGet returns one domain block, specified by ID.
2021-08-25 13:34:33 +00:00
AdminDomainBlockGet ( ctx context . Context , authed * oauth . Auth , id string , export bool ) ( * apimodel . DomainBlock , gtserror . WithCode )
2021-07-05 11:23:03 +00:00
// AdminDomainBlockDelete deletes one domain block, specified by ID, returning the deleted domain block.
2021-08-25 13:34:33 +00:00
AdminDomainBlockDelete ( ctx context . Context , authed * oauth . Auth , id string ) ( * apimodel . DomainBlock , gtserror . WithCode )
2022-05-03 09:56:18 +00:00
// AdminMediaRemotePrune triggers a prune of remote media according to the given number of mediaRemoteCacheDays
2022-05-15 14:45:04 +00:00
AdminMediaPrune ( ctx context . Context , mediaRemoteCacheDays int ) gtserror . WithCode
2022-12-10 21:43:11 +00:00
// AdminMediaRefetch triggers a refetch of remote media for the given domain (or all if domain is empty).
AdminMediaRefetch ( ctx context . Context , authed * oauth . Auth , domain string ) gtserror . WithCode
2023-01-25 10:12:17 +00:00
// AdminReportsGet returns a list of user moderation reports.
AdminReportsGet ( ctx context . Context , authed * oauth . Auth , resolved * bool , accountID string , targetAccountID string , maxID string , sinceID string , minID string , limit int ) ( * apimodel . PageableResponse , gtserror . WithCode )
// AdminReportGet returns a single user moderation report, specified by id.
AdminReportGet ( ctx context . Context , authed * oauth . Auth , id string ) ( * apimodel . AdminReport , gtserror . WithCode )
// AdminReportResolve marks a single user moderation report as resolved, with the given id.
// actionTakenComment is optional: if set, this will be stored as a comment on the action taken.
AdminReportResolve ( ctx context . Context , authed * oauth . Auth , id string , actionTakenComment * string ) ( * apimodel . AdminReport , gtserror . WithCode )
2021-05-09 12:06:06 +00:00
2021-05-08 12:25:55 +00:00
// AppCreate processes the creation of a new API application
2022-06-08 18:38:03 +00:00
AppCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . ApplicationCreateRequest ) ( * apimodel . Application , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
2021-07-11 14:22:21 +00:00
// BlocksGet returns a list of accounts blocked by the requesting account.
2021-08-25 13:34:33 +00:00
BlocksGet ( ctx context . Context , authed * oauth . Auth , maxID string , sinceID string , limit int ) ( * apimodel . BlocksResponse , gtserror . WithCode )
2022-05-20 08:34:36 +00:00
// CustomEmojisGet returns an array of info about the custom emojis on this server
CustomEmojisGet ( ctx context . Context ) ( [ ] * apimodel . Emoji , gtserror . WithCode )
2021-07-11 14:22:21 +00:00
2022-12-09 10:37:12 +00:00
// BookmarksGet returns a pageable response of statuses that have been bookmarked
BookmarksGet ( ctx context . Context , authed * oauth . Auth , maxID string , minID string , limit int ) ( * apimodel . PageableResponse , gtserror . WithCode )
2021-05-10 14:29:05 +00:00
// FileGet handles the fetching of a media attachment file via the fileserver.
2022-03-07 10:08:26 +00:00
FileGet ( ctx context . Context , authed * oauth . Auth , form * apimodel . GetContentRequestForm ) ( * apimodel . Content , gtserror . WithCode )
2021-05-10 14:29:05 +00:00
2021-05-15 09:58:11 +00:00
// FollowRequestsGet handles the getting of the authed account's incoming follow requests
2021-08-25 13:34:33 +00:00
FollowRequestsGet ( ctx context . Context , auth * oauth . Auth ) ( [ ] apimodel . Account , gtserror . WithCode )
2021-10-16 11:27:43 +00:00
// FollowRequestAccept handles the acceptance of a follow request from the given account ID.
2021-08-25 13:34:33 +00:00
FollowRequestAccept ( ctx context . Context , auth * oauth . Auth , accountID string ) ( * apimodel . Relationship , gtserror . WithCode )
2021-10-16 11:27:43 +00:00
// FollowRequestReject handles the rejection of a follow request from the given account ID.
FollowRequestReject ( ctx context . Context , auth * oauth . Auth , accountID string ) ( * apimodel . Relationship , gtserror . WithCode )
2021-05-15 09:58:11 +00:00
2021-05-09 12:06:06 +00:00
// InstanceGet retrieves instance information for serving at api/v1/instance
2021-08-25 13:34:33 +00:00
InstanceGet ( ctx context . Context , domain string ) ( * apimodel . Instance , gtserror . WithCode )
2023-01-25 17:06:41 +00:00
InstancePeersGet ( ctx context . Context , includeSuspended bool , includeOpen bool , flat bool ) ( interface { } , gtserror . WithCode )
2021-06-23 14:35:57 +00:00
// InstancePatch updates this instance according to the given form.
//
// It should already be ascertained that the requesting account is authenticated and an admin.
2021-08-25 13:34:33 +00:00
InstancePatch ( ctx context . Context , form * apimodel . InstanceSettingsUpdateRequest ) ( * apimodel . Instance , gtserror . WithCode )
2021-05-09 12:06:06 +00:00
// MediaCreate handles the creation of a media attachment, using the given form.
2022-06-08 18:38:03 +00:00
MediaCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . AttachmentRequest ) ( * apimodel . Attachment , gtserror . WithCode )
2021-05-10 14:29:05 +00:00
// MediaGet handles the GET of a media attachment with the given ID
2021-08-25 13:34:33 +00:00
MediaGet ( ctx context . Context , authed * oauth . Auth , attachmentID string ) ( * apimodel . Attachment , gtserror . WithCode )
2021-05-10 14:29:05 +00:00
// MediaUpdate handles the PUT of a media attachment with the given ID and form
2021-08-25 13:34:33 +00:00
MediaUpdate ( ctx context . Context , authed * oauth . Auth , attachmentID string , form * apimodel . AttachmentUpdateRequest ) ( * apimodel . Attachment , gtserror . WithCode )
2021-05-09 12:06:06 +00:00
2021-05-27 14:06:24 +00:00
// NotificationsGet
2022-10-10 13:52:49 +00:00
NotificationsGet ( ctx context . Context , authed * oauth . Auth , excludeTypes [ ] string , limit int , maxID string , sinceID string ) ( * apimodel . PageableResponse , gtserror . WithCode )
2022-08-01 09:13:49 +00:00
// NotificationsClear
NotificationsClear ( ctx context . Context , authed * oauth . Auth ) gtserror . WithCode
2021-05-27 14:06:24 +00:00
2022-06-11 08:39:39 +00:00
OAuthHandleTokenRequest ( r * http . Request ) ( map [ string ] interface { } , gtserror . WithCode )
2022-10-08 11:49:56 +00:00
OAuthHandleAuthorizeRequest ( w http . ResponseWriter , r * http . Request ) gtserror . WithCode
2023-01-02 12:10:50 +00:00
OAuthValidateBearerToken ( r * http . Request ) ( oauth2 . TokenInfo , error )
2022-06-11 08:39:39 +00:00
2021-05-29 17:36:54 +00:00
// SearchGet performs a search with the given params, resolving/dereferencing remotely as desired
2021-08-25 13:34:33 +00:00
SearchGet ( ctx context . Context , authed * oauth . Auth , searchQuery * apimodel . SearchQuery ) ( * apimodel . SearchResult , gtserror . WithCode )
2021-05-29 17:36:54 +00:00
2021-05-08 12:25:55 +00:00
// StatusCreate processes the given form to create a new status, returning the api model representation of that status if it's OK.
2022-06-08 18:38:03 +00:00
StatusCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . AdvancedStatusCreateForm ) ( * apimodel . Status , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
// StatusDelete processes the delete of a given status, returning the deleted status if the delete goes through.
2022-06-08 18:38:03 +00:00
StatusDelete ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
// StatusFave processes the faving of a given status, returning the updated status if the fave goes through.
2022-06-08 18:38:03 +00:00
StatusFave ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
2021-05-08 13:16:24 +00:00
// StatusBoost processes the boost/reblog of a given status, returning the newly-created boost if all is well.
2021-08-25 13:34:33 +00:00
StatusBoost ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
2021-06-21 13:56:00 +00:00
// StatusUnboost processes the unboost/unreblog of a given status, returning the status if all is well.
2021-08-25 13:34:33 +00:00
StatusUnboost ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
2021-05-31 15:36:35 +00:00
// StatusBoostedBy returns a slice of accounts that have boosted the given status, filtered according to privacy settings.
2021-08-25 13:34:33 +00:00
StatusBoostedBy ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( [ ] * apimodel . Account , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
// StatusFavedBy returns a slice of accounts that have liked the given status, filtered according to privacy settings.
2022-06-08 18:38:03 +00:00
StatusFavedBy ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( [ ] * apimodel . Account , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
// StatusGet gets the given status, taking account of privacy settings and blocks etc.
2022-06-08 18:38:03 +00:00
StatusGet ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
// StatusUnfave processes the unfaving of a given status, returning the updated status if the fave goes through.
2022-06-08 18:38:03 +00:00
StatusUnfave ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
2021-05-31 15:36:35 +00:00
// StatusGetContext returns the context (previous and following posts) from the given status ID
2021-08-25 13:34:33 +00:00
StatusGetContext ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Context , gtserror . WithCode )
2022-12-09 10:37:12 +00:00
// StatusBookmark process a bookmark for a status
StatusBookmark ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
// StatusUnbookmark removes a bookmark for a status
StatusUnbookmark ( ctx context . Context , authed * oauth . Auth , targetStatusID string ) ( * apimodel . Status , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
2021-05-21 21:04:59 +00:00
// HomeTimelineGet returns statuses from the home timeline, with the given filters/parameters.
2022-10-10 13:52:49 +00:00
HomeTimelineGet ( ctx context . Context , authed * oauth . Auth , maxID string , sinceID string , minID string , limit int , local bool ) ( * apimodel . PageableResponse , gtserror . WithCode )
2021-05-31 15:36:35 +00:00
// PublicTimelineGet returns statuses from the public/local timeline, with the given filters/parameters.
2022-10-10 13:52:49 +00:00
PublicTimelineGet ( ctx context . Context , authed * oauth . Auth , maxID string , sinceID string , minID string , limit int , local bool ) ( * apimodel . PageableResponse , gtserror . WithCode )
2021-07-09 16:32:48 +00:00
// FavedTimelineGet returns faved statuses, with the given filters/parameters.
2022-10-10 13:52:49 +00:00
FavedTimelineGet ( ctx context . Context , authed * oauth . Auth , maxID string , minID string , limit int ) ( * apimodel . PageableResponse , gtserror . WithCode )
2021-05-21 21:04:59 +00:00
2021-06-19 09:18:55 +00:00
// AuthorizeStreamingRequest returns a gotosocial account in exchange for an access token, or an error if the given token is not valid.
2022-06-08 18:38:03 +00:00
AuthorizeStreamingRequest ( ctx context . Context , accessToken string ) ( * gtsmodel . Account , gtserror . WithCode )
2021-06-19 09:18:55 +00:00
// OpenStreamForAccount opens a new stream for the given account, with the given stream type.
2021-09-01 16:29:25 +00:00
OpenStreamForAccount ( ctx context . Context , account * gtsmodel . Account , streamType string ) ( * stream . Stream , gtserror . WithCode )
2021-06-19 09:18:55 +00:00
2021-10-14 12:26:04 +00:00
// UserChangePassword changes the password for the given user, with the given form.
UserChangePassword ( ctx context . Context , authed * oauth . Auth , form * apimodel . PasswordChangeRequest ) gtserror . WithCode
2021-10-31 14:46:23 +00:00
// UserConfirmEmail confirms an email address using the given token.
// The user belonging to the confirmed email is also returned.
UserConfirmEmail ( ctx context . Context , token string ) ( * gtsmodel . User , gtserror . WithCode )
2021-10-14 12:26:04 +00:00
2023-01-23 12:14:21 +00:00
// ReportsGet returns reports created by the given user.
ReportsGet ( ctx context . Context , authed * oauth . Auth , resolved * bool , targetAccountID string , maxID string , sinceID string , minID string , limit int ) ( * apimodel . PageableResponse , gtserror . WithCode )
// ReportGet returns one report created by the given user.
ReportGet ( ctx context . Context , authed * oauth . Auth , id string ) ( * apimodel . Report , gtserror . WithCode )
// ReportCreate creates a new report using the given account and form.
ReportCreate ( ctx context . Context , authed * oauth . Auth , form * apimodel . ReportCreateRequest ) ( * apimodel . Report , gtserror . WithCode )
2021-05-08 12:25:55 +00:00
/ *
FEDERATION API - FACING PROCESSING FUNCTIONS
These functions are intended to be called when the federating client needs an immediate ( ie . , synchronous ) reply
to an HTTP request . As such , they will only do the bare - minimum of work necessary to give a properly
formed reply . For more intensive ( and time - consuming ) calls , where you don ' t require an immediate
response , pass work to the processor using a channel instead .
* /
// GetFediUser handles the getting of a fedi/activitypub representation of a user/account, performing appropriate authentication
// before returning a JSON serializable interface to the caller.
2021-07-05 11:23:03 +00:00
GetFediUser ( ctx context . Context , requestedUsername string , requestURL * url . URL ) ( interface { } , gtserror . WithCode )
2021-05-21 13:48:26 +00:00
// GetFediFollowers handles the getting of a fedi/activitypub representation of a user/account's followers, performing appropriate
// authentication before returning a JSON serializable interface to the caller.
2021-07-05 11:23:03 +00:00
GetFediFollowers ( ctx context . Context , requestedUsername string , requestURL * url . URL ) ( interface { } , gtserror . WithCode )
2021-05-23 16:07:04 +00:00
// GetFediFollowing handles the getting of a fedi/activitypub representation of a user/account's following, performing appropriate
// authentication before returning a JSON serializable interface to the caller.
2021-07-05 11:23:03 +00:00
GetFediFollowing ( ctx context . Context , requestedUsername string , requestURL * url . URL ) ( interface { } , gtserror . WithCode )
2021-05-21 13:48:26 +00:00
// GetFediStatus handles the getting of a fedi/activitypub representation of a particular status, performing appropriate
// authentication before returning a JSON serializable interface to the caller.
2021-07-05 11:23:03 +00:00
GetFediStatus ( ctx context . Context , requestedUsername string , requestedStatusID string , requestURL * url . URL ) ( interface { } , gtserror . WithCode )
2021-08-10 11:32:39 +00:00
// GetFediStatus handles the getting of a fedi/activitypub representation of replies to a status, performing appropriate
// authentication before returning a JSON serializable interface to the caller.
GetFediStatusReplies ( ctx context . Context , requestedUsername string , requestedStatusID string , page bool , onlyOtherAccounts bool , minID string , requestURL * url . URL ) ( interface { } , gtserror . WithCode )
2021-10-24 09:57:39 +00:00
// GetFediOutbox returns the public outbox of the requested user, with the given parameters.
GetFediOutbox ( ctx context . Context , requestedUsername string , page bool , maxID string , minID string , requestURL * url . URL ) ( interface { } , gtserror . WithCode )
2022-09-06 10:42:55 +00:00
// GetFediEmoji returns the AP representation of an emoji on this instance.
GetFediEmoji ( ctx context . Context , requestedEmojiID string , requestURL * url . URL ) ( interface { } , gtserror . WithCode )
2021-05-09 18:34:27 +00:00
// GetWebfingerAccount handles the GET for a webfinger resource. Most commonly, it will be used for returning account lookups.
2021-09-20 14:46:45 +00:00
GetWebfingerAccount ( ctx context . Context , requestedUsername string ) ( * apimodel . WellKnownResponse , gtserror . WithCode )
2021-06-24 12:26:08 +00:00
// GetNodeInfoRel returns a well known response giving the path to node info.
2023-01-02 12:10:50 +00:00
GetNodeInfoRel ( ctx context . Context ) ( * apimodel . WellKnownResponse , gtserror . WithCode )
2021-06-24 12:26:08 +00:00
// GetNodeInfo returns a node info struct in response to a node info request.
2023-01-02 12:10:50 +00:00
GetNodeInfo ( ctx context . Context ) ( * apimodel . Nodeinfo , gtserror . WithCode )
2021-05-15 09:58:11 +00:00
// InboxPost handles POST requests to a user's inbox for new activitypub messages.
//
// InboxPost returns true if the request was handled as an ActivityPub POST to an actor's inbox.
// If false, the request was not an ActivityPub request and may still be handled by the caller in another way, such as serving a web page.
//
// If the error is nil, then the ResponseWriter's headers and response has already been written. If a non-nil error is returned, then no response has been written.
//
// If the Actor was constructed with the Federated Protocol enabled, side effects will occur.
//
// If the Federated Protocol is not enabled, writes the http.StatusMethodNotAllowed status code in the response. No side effects occur.
InboxPost ( ctx context . Context , w http . ResponseWriter , r * http . Request ) ( bool , error )
2021-05-08 12:25:55 +00:00
}
// processor just implements the Processor interface
type processor struct {
2022-05-15 09:16:43 +00:00
clientWorker * concurrency . WorkerPool [ messages . FromClientAPI ]
fedWorker * concurrency . WorkerPool [ messages . FromFederator ]
2022-04-28 12:23:11 +00:00
2021-06-13 16:42:28 +00:00
federator federation . Federator
tc typeutils . TypeConverter
oauthServer oauth . Server
2021-12-28 15:36:00 +00:00
mediaManager media . Manager
2022-11-24 08:35:46 +00:00
storage * storage . Driver
2022-02-05 11:47:38 +00:00
statusTimelines timeline . Manager
2021-06-13 16:42:28 +00:00
db db . DB
2021-06-17 16:02:33 +00:00
filter visibility . Filter
2021-05-08 12:25:55 +00:00
2021-06-13 16:42:28 +00:00
/ *
SUB - PROCESSORS
* /
2021-10-24 09:57:39 +00:00
accountProcessor account . Processor
adminProcessor admin . Processor
statusProcessor status . Processor
streamingProcessor streaming . Processor
mediaProcessor mediaProcessor . Processor
userProcessor user . Processor
federationProcessor federationProcessor . Processor
2023-01-23 12:14:21 +00:00
reportProcessor report . Processor
2021-05-08 12:25:55 +00:00
}
2021-10-31 14:46:23 +00:00
// NewProcessor returns a new Processor.
func NewProcessor (
tc typeutils . TypeConverter ,
federator federation . Federator ,
oauthServer oauth . Server ,
2021-12-28 15:36:00 +00:00
mediaManager media . Manager ,
2022-11-24 08:35:46 +00:00
storage * storage . Driver ,
2021-10-31 14:46:23 +00:00
db db . DB ,
2022-04-28 12:23:11 +00:00
emailSender email . Sender ,
2022-05-15 09:16:43 +00:00
clientWorker * concurrency . WorkerPool [ messages . FromClientAPI ] ,
fedWorker * concurrency . WorkerPool [ messages . FromFederator ] ,
2022-04-28 12:23:11 +00:00
) Processor {
2022-03-29 09:54:56 +00:00
parseMentionFunc := GetParseMentionFunc ( db , federator )
2021-05-08 12:25:55 +00:00
2022-04-28 12:23:11 +00:00
statusProcessor := status . New ( db , tc , clientWorker , parseMentionFunc )
2021-10-11 12:37:33 +00:00
streamingProcessor := streaming . New ( db , oauthServer )
2022-04-28 12:23:11 +00:00
accountProcessor := account . New ( db , tc , mediaManager , oauthServer , clientWorker , federator , parseMentionFunc )
2022-12-10 21:43:11 +00:00
adminProcessor := admin . New ( db , tc , mediaManager , federator . TransportController ( ) , storage , clientWorker )
2022-03-07 10:08:26 +00:00
mediaProcessor := mediaProcessor . New ( db , tc , mediaManager , federator . TransportController ( ) , storage )
2021-12-07 12:31:39 +00:00
userProcessor := user . New ( db , emailSender )
2022-04-28 12:23:11 +00:00
federationProcessor := federationProcessor . New ( db , tc , federator )
2023-01-23 12:14:21 +00:00
reportProcessor := report . New ( db , tc , clientWorker )
2022-02-05 11:47:38 +00:00
filter := visibility . NewFilter ( db )
2021-05-08 12:25:55 +00:00
2021-06-13 16:42:28 +00:00
return & processor {
2022-04-28 12:23:11 +00:00
clientWorker : clientWorker ,
fedWorker : fedWorker ,
2021-06-13 16:42:28 +00:00
federator : federator ,
tc : tc ,
oauthServer : oauthServer ,
2021-12-28 15:36:00 +00:00
mediaManager : mediaManager ,
2021-09-11 19:18:06 +00:00
storage : storage ,
2022-02-05 11:47:38 +00:00
statusTimelines : timeline . NewManager ( StatusGrabFunction ( db ) , StatusFilterFunction ( db , filter ) , StatusPrepareFunction ( db , tc ) , StatusSkipInsertFunction ( ) ) ,
2021-06-13 16:42:28 +00:00
db : db ,
2021-10-11 12:37:33 +00:00
filter : visibility . NewFilter ( db ) ,
2021-06-13 16:42:28 +00:00
2021-10-24 09:57:39 +00:00
accountProcessor : accountProcessor ,
adminProcessor : adminProcessor ,
statusProcessor : statusProcessor ,
streamingProcessor : streamingProcessor ,
mediaProcessor : mediaProcessor ,
userProcessor : userProcessor ,
federationProcessor : federationProcessor ,
2023-01-23 12:14:21 +00:00
reportProcessor : reportProcessor ,
2021-06-13 16:42:28 +00:00
}
2021-05-08 12:25:55 +00:00
}
// Start starts the Processor, reading from its channels and passing messages back and forth.
2022-04-28 12:23:11 +00:00
func ( p * processor ) Start ( ) error {
// Setup and start the client API worker pool
p . clientWorker . SetProcessor ( p . ProcessFromClientAPI )
if err := p . clientWorker . Start ( ) ; err != nil {
return err
}
// Setup and start the federator worker pool
p . fedWorker . SetProcessor ( p . ProcessFromFederator )
if err := p . fedWorker . Start ( ) ; err != nil {
return err
}
2022-11-22 18:38:10 +00:00
// Start status timelines
if err := p . statusTimelines . Start ( ) ; err != nil {
return err
}
2021-08-15 16:43:08 +00:00
return nil
2021-05-08 12:25:55 +00:00
}
// Stop stops the processor cleanly, finishing handling any remaining messages before closing down.
func ( p * processor ) Stop ( ) error {
2022-04-28 12:23:11 +00:00
if err := p . clientWorker . Stop ( ) ; err != nil {
return err
}
2022-11-22 18:38:10 +00:00
2022-04-28 12:23:11 +00:00
if err := p . fedWorker . Stop ( ) ; err != nil {
return err
}
2022-11-22 18:38:10 +00:00
if err := p . statusTimelines . Stop ( ) ; err != nil {
return err
}
2021-05-08 12:25:55 +00:00
return nil
}