From b6fbdc66c1ce1ec61ebfb6fcc0351ea627a1d288 Mon Sep 17 00:00:00 2001
From: tobi <31960611+tsmethurst@users.noreply.github.com>
Date: Wed, 22 Feb 2023 16:05:26 +0100
Subject: [chore] Deinterface processor and subprocessors (#1501)
* [chore] Deinterface processor and subprocessors
* expose subprocessors via function calls
* missing license header
---
internal/processing/account/account.go | 77 ++--------
internal/processing/account/block.go | 192 +++++++++++++++++++++++
internal/processing/account/bookmarks.go | 88 +++++++++++
internal/processing/account/create.go | 3 +-
internal/processing/account/createblock.go | 156 -------------------
internal/processing/account/createfollow.go | 121 ---------------
internal/processing/account/delete.go | 29 +---
internal/processing/account/follow.go | 205 +++++++++++++++++++++++++
internal/processing/account/get.go | 15 +-
internal/processing/account/getbookmarks.go | 88 -----------
internal/processing/account/getfollowers.go | 74 ---------
internal/processing/account/getfollowing.go | 74 ---------
internal/processing/account/getrelationship.go | 47 ------
internal/processing/account/getrss.go | 108 -------------
internal/processing/account/getrss_test.go | 61 --------
internal/processing/account/getstatuses.go | 155 -------------------
internal/processing/account/relationships.go | 141 +++++++++++++++++
internal/processing/account/removeblock.go | 65 --------
internal/processing/account/removefollow.go | 113 --------------
internal/processing/account/rss.go | 109 +++++++++++++
internal/processing/account/rss_test.go | 61 ++++++++
internal/processing/account/statuses.go | 159 +++++++++++++++++++
internal/processing/account/update.go | 10 +-
23 files changed, 992 insertions(+), 1159 deletions(-)
create mode 100644 internal/processing/account/block.go
create mode 100644 internal/processing/account/bookmarks.go
delete mode 100644 internal/processing/account/createblock.go
delete mode 100644 internal/processing/account/createfollow.go
create mode 100644 internal/processing/account/follow.go
delete mode 100644 internal/processing/account/getbookmarks.go
delete mode 100644 internal/processing/account/getfollowers.go
delete mode 100644 internal/processing/account/getfollowing.go
delete mode 100644 internal/processing/account/getrelationship.go
delete mode 100644 internal/processing/account/getrss.go
delete mode 100644 internal/processing/account/getrss_test.go
delete mode 100644 internal/processing/account/getstatuses.go
create mode 100644 internal/processing/account/relationships.go
delete mode 100644 internal/processing/account/removeblock.go
delete mode 100644 internal/processing/account/removefollow.go
create mode 100644 internal/processing/account/rss.go
create mode 100644 internal/processing/account/rss_test.go
create mode 100644 internal/processing/account/statuses.go
(limited to 'internal/processing/account')
diff --git a/internal/processing/account/account.go b/internal/processing/account/account.go
index 7263bacd2..41315d483 100644
--- a/internal/processing/account/account.go
+++ b/internal/processing/account/account.go
@@ -19,15 +19,9 @@
package account
import (
- "context"
- "mime/multipart"
- "time"
-
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/messages"
@@ -35,63 +29,12 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/text"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/visibility"
- "github.com/superseriousbusiness/oauth2/v4"
)
-// Processor wraps a bunch of functions for processing account actions.
-type Processor interface {
- // Create processes the given form for creating a new account, returning an oauth token for that account if successful.
- Create(ctx context.Context, applicationToken oauth2.TokenInfo, application *gtsmodel.Application, form *apimodel.AccountCreateRequest) (*apimodel.Token, gtserror.WithCode)
- // Delete deletes an account, and all of that account's statuses, media, follows, notifications, etc etc etc.
- // The origin passed here should be either the ID of the account doing the delete (can be itself), or the ID of a domain block.
- Delete(ctx context.Context, account *gtsmodel.Account, origin string) gtserror.WithCode
- // DeleteLocal is like delete, but specifically for deletion of local accounts rather than federated ones.
- // Unlike Delete, it will propagate the deletion out across the federating API to other instances.
- DeleteLocal(ctx context.Context, account *gtsmodel.Account, form *apimodel.AccountDeleteRequest) gtserror.WithCode
- // Get processes the given request for account information.
- Get(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Account, gtserror.WithCode)
- // GetLocalByUsername processes the given request for account information targeting a local account by username.
- GetLocalByUsername(ctx context.Context, requestingAccount *gtsmodel.Account, username string) (*apimodel.Account, gtserror.WithCode)
- // GetCustomCSSForUsername returns custom css for the given local username.
- GetCustomCSSForUsername(ctx context.Context, username string) (string, gtserror.WithCode)
- // GetRSSFeedForUsername returns RSS feed for the given local username.
- GetRSSFeedForUsername(ctx context.Context, username string) (func() (string, gtserror.WithCode), time.Time, gtserror.WithCode)
- // Update processes the update of an account with the given form
- Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, gtserror.WithCode)
- // StatusesGet fetches a number of statuses (in time descending order) from the given account, filtered by visibility for
- // the account given in authed.
- StatusesGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string, limit int, excludeReplies bool, excludeReblogs bool, maxID string, minID string, pinned bool, mediaOnly bool, publicOnly bool) (*apimodel.PageableResponse, gtserror.WithCode)
- // WebStatusesGet 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.
- WebStatusesGet(ctx context.Context, targetAccountID string, maxID string) (*apimodel.PageableResponse, gtserror.WithCode)
- // StatusesGet fetches a number of statuses (in time descending order) from the given account, filtered by visibility for
- // the account given in authed.
- BookmarksGet(ctx context.Context, requestingAccount *gtsmodel.Account, limit int, maxID string, minID string) (*apimodel.PageableResponse, gtserror.WithCode)
- // FollowersGet fetches a list of the target account's followers.
- FollowersGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) ([]apimodel.Account, gtserror.WithCode)
- // FollowingGet fetches a list of the accounts that target account is following.
- FollowingGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) ([]apimodel.Account, gtserror.WithCode)
- // RelationshipGet returns a relationship model describing the relationship of the targetAccount to the Authed account.
- RelationshipGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode)
- // FollowCreate handles a follow request to an account, either remote or local.
- FollowCreate(ctx context.Context, requestingAccount *gtsmodel.Account, form *apimodel.AccountFollowRequest) (*apimodel.Relationship, gtserror.WithCode)
- // FollowRemove handles the removal of a follow/follow request to an account, either remote or local.
- FollowRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode)
- // BlockCreate handles the creation of a block from requestingAccount to targetAccountID, either remote or local.
- BlockCreate(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode)
- // BlockRemove handles the removal of a block from requestingAccount to targetAccountID, either remote or local.
- BlockRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode)
- // UpdateAvatar does the dirty work of checking the avatar part of an account update form,
- // parsing and checking the image, and doing the necessary updates in the database for this to become
- // the account's new avatar image.
- UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error)
- // UpdateHeader does the dirty work of checking the header part of an account update form,
- // parsing and checking the image, and doing the necessary updates in the database for this to become
- // the account's new header image.
- UpdateHeader(ctx context.Context, header *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error)
-}
-
-type processor struct {
+// Processor wraps functionality for updating, creating, and deleting accounts in response to API requests.
+//
+// It also contains logic for actions towards accounts such as following, blocking, seeing follows, etc.
+type Processor struct {
tc typeutils.TypeConverter
mediaManager media.Manager
clientWorker *concurrency.WorkerPool[messages.FromClientAPI]
@@ -104,8 +47,16 @@ type processor struct {
}
// New returns a new account processor.
-func New(db db.DB, tc typeutils.TypeConverter, mediaManager media.Manager, oauthServer oauth.Server, clientWorker *concurrency.WorkerPool[messages.FromClientAPI], federator federation.Federator, parseMention gtsmodel.ParseMentionFunc) Processor {
- return &processor{
+func New(
+ db db.DB,
+ tc typeutils.TypeConverter,
+ mediaManager media.Manager,
+ oauthServer oauth.Server,
+ clientWorker *concurrency.WorkerPool[messages.FromClientAPI],
+ federator federation.Federator,
+ parseMention gtsmodel.ParseMentionFunc,
+) Processor {
+ return Processor{
tc: tc,
mediaManager: mediaManager,
clientWorker: clientWorker,
diff --git a/internal/processing/account/block.go b/internal/processing/account/block.go
new file mode 100644
index 000000000..99effd3a3
--- /dev/null
+++ b/internal/processing/account/block.go
@@ -0,0 +1,192 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ 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 .
+*/
+
+package account
+
+import (
+ "context"
+ "errors"
+ "fmt"
+
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
+ apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
+ "github.com/superseriousbusiness/gotosocial/internal/uris"
+)
+
+// BlockCreate handles the creation of a block from requestingAccount to targetAccountID, either remote or local.
+func (p *Processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
+ // make sure the target account actually exists in our db
+ targetAccount, err := p.db.GetAccountByID(ctx, targetAccountID)
+ if err != nil {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("BlockCreate: error getting account %s from the db: %s", targetAccountID, err))
+ }
+
+ // if requestingAccount already blocks target account, we don't need to do anything
+ if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, false); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error checking existence of block: %s", err))
+ } else if blocked {
+ return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
+ }
+
+ // don't block yourself, silly
+ if requestingAccount.ID == targetAccountID {
+ return nil, gtserror.NewErrorNotAcceptable(fmt.Errorf("BlockCreate: account %s cannot block itself", requestingAccount.ID))
+ }
+
+ // make the block
+ block := >smodel.Block{}
+ newBlockID := id.NewULID()
+ block.ID = newBlockID
+ block.AccountID = requestingAccount.ID
+ block.Account = requestingAccount
+ block.TargetAccountID = targetAccountID
+ block.TargetAccount = targetAccount
+ block.URI = uris.GenerateURIForBlock(requestingAccount.Username, newBlockID)
+
+ // whack it in the database
+ if err := p.db.PutBlock(ctx, block); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error creating block in db: %s", err))
+ }
+
+ // clear any follows or follow requests from the blocked account to the target account -- this is a simple delete
+ if err := p.db.DeleteWhere(ctx, []db.Where{
+ {Key: "account_id", Value: targetAccountID},
+ {Key: "target_account_id", Value: requestingAccount.ID},
+ }, >smodel.Follow{}); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow in db: %s", err))
+ }
+ if err := p.db.DeleteWhere(ctx, []db.Where{
+ {Key: "account_id", Value: targetAccountID},
+ {Key: "target_account_id", Value: requestingAccount.ID},
+ }, >smodel.FollowRequest{}); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow in db: %s", err))
+ }
+
+ // clear any follows or follow requests from the requesting account to the target account --
+ // this might require federation so we need to pass some messages around
+
+ // check if a follow request exists from the requesting account to the target account, and remove it if it does (storing the URI for later)
+ var frChanged bool
+ var frURI string
+ fr := >smodel.FollowRequest{}
+ if err := p.db.GetWhere(ctx, []db.Where{
+ {Key: "account_id", Value: requestingAccount.ID},
+ {Key: "target_account_id", Value: targetAccountID},
+ }, fr); err == nil {
+ frURI = fr.URI
+ if err := p.db.DeleteByID(ctx, fr.ID, fr); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow request from db: %s", err))
+ }
+ frChanged = true
+ }
+
+ // now do the same thing for any existing follow
+ var fChanged bool
+ var fURI string
+ f := >smodel.Follow{}
+ if err := p.db.GetWhere(ctx, []db.Where{
+ {Key: "account_id", Value: requestingAccount.ID},
+ {Key: "target_account_id", Value: targetAccountID},
+ }, f); err == nil {
+ fURI = f.URI
+ if err := p.db.DeleteByID(ctx, f.ID, f); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow from db: %s", err))
+ }
+ fChanged = true
+ }
+
+ // follow request status changed so send the UNDO activity to the channel for async processing
+ if frChanged {
+ p.clientWorker.Queue(messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
+ GTSModel: >smodel.Follow{
+ AccountID: requestingAccount.ID,
+ TargetAccountID: targetAccountID,
+ URI: frURI,
+ },
+ OriginAccount: requestingAccount,
+ TargetAccount: targetAccount,
+ })
+ }
+
+ // follow status changed so send the UNDO activity to the channel for async processing
+ if fChanged {
+ p.clientWorker.Queue(messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
+ GTSModel: >smodel.Follow{
+ AccountID: requestingAccount.ID,
+ TargetAccountID: targetAccountID,
+ URI: fURI,
+ },
+ OriginAccount: requestingAccount,
+ TargetAccount: targetAccount,
+ })
+ }
+
+ // handle the rest of the block process asynchronously
+ p.clientWorker.Queue(messages.FromClientAPI{
+ APObjectType: ap.ActivityBlock,
+ APActivityType: ap.ActivityCreate,
+ GTSModel: block,
+ OriginAccount: requestingAccount,
+ TargetAccount: targetAccount,
+ })
+
+ return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
+}
+
+// BlockRemove handles the removal of a block from requestingAccount to targetAccountID, either remote or local.
+func (p *Processor) BlockRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
+ // make sure the target account actually exists in our db
+ targetAccount, err := p.db.GetAccountByID(ctx, targetAccountID)
+ if err != nil {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("BlockCreate: error getting account %s from the db: %s", targetAccountID, err))
+ }
+
+ // check if a block exists, and remove it if it does
+ block, err := p.db.GetBlock(ctx, requestingAccount.ID, targetAccountID)
+ if err == nil {
+ // we got a block, remove it
+ block.Account = requestingAccount
+ block.TargetAccount = targetAccount
+ if err := p.db.DeleteBlockByID(ctx, block.ID); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockRemove: error removing block from db: %s", err))
+ }
+
+ // send the UNDO activity to the client worker for async processing
+ p.clientWorker.Queue(messages.FromClientAPI{
+ APObjectType: ap.ActivityBlock,
+ APActivityType: ap.ActivityUndo,
+ GTSModel: block,
+ OriginAccount: requestingAccount,
+ TargetAccount: targetAccount,
+ })
+ } else if !errors.Is(err, db.ErrNoEntries) {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockRemove: error getting possible block from db: %s", err))
+ }
+
+ // return whatever relationship results from all this
+ return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
+}
diff --git a/internal/processing/account/bookmarks.go b/internal/processing/account/bookmarks.go
new file mode 100644
index 000000000..7551b1e0c
--- /dev/null
+++ b/internal/processing/account/bookmarks.go
@@ -0,0 +1,88 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ 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 .
+*/
+
+package account
+
+import (
+ "context"
+ "fmt"
+
+ apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
+)
+
+func (p *Processor) BookmarksGet(ctx context.Context, requestingAccount *gtsmodel.Account, limit int, maxID string, minID string) (*apimodel.PageableResponse, gtserror.WithCode) {
+ if requestingAccount == nil {
+ return nil, gtserror.NewErrorForbidden(fmt.Errorf("cannot retrieve bookmarks without a requesting account"))
+ }
+
+ bookmarks, err := p.db.GetBookmarks(ctx, requestingAccount.ID, limit, maxID, minID)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ count := len(bookmarks)
+ filtered := make([]*gtsmodel.Status, 0, len(bookmarks))
+ nextMaxIDValue := ""
+ prevMinIDValue := ""
+ for i, b := range bookmarks {
+ s, err := p.db.GetStatusByID(ctx, b.StatusID)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ visible, err := p.filter.StatusVisible(ctx, s, requestingAccount)
+ if err == nil && visible {
+ if i == count-1 {
+ nextMaxIDValue = b.ID
+ }
+
+ if i == 0 {
+ prevMinIDValue = b.ID
+ }
+
+ filtered = append(filtered, s)
+ }
+ }
+
+ count = len(filtered)
+
+ if count == 0 {
+ return util.EmptyPageableResponse(), nil
+ }
+
+ items := []interface{}{}
+ for _, s := range filtered {
+ item, err := p.tc.StatusToAPIStatus(ctx, s, requestingAccount)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status to api: %s", err))
+ }
+ items = append(items, item)
+ }
+
+ return util.PackagePageableResponse(util.PageableResponseParams{
+ Items: items,
+ Path: "/api/v1/bookmarks",
+ NextMaxIDValue: nextMaxIDValue,
+ PrevMinIDValue: prevMinIDValue,
+ Limit: limit,
+ ExtraQueryParams: []string{},
+ })
+}
diff --git a/internal/processing/account/create.go b/internal/processing/account/create.go
index b0efccf7e..8b82bc681 100644
--- a/internal/processing/account/create.go
+++ b/internal/processing/account/create.go
@@ -33,7 +33,8 @@ import (
"github.com/superseriousbusiness/oauth2/v4"
)
-func (p *processor) Create(ctx context.Context, applicationToken oauth2.TokenInfo, application *gtsmodel.Application, form *apimodel.AccountCreateRequest) (*apimodel.Token, gtserror.WithCode) {
+// Create processes the given form for creating a new account, returning an oauth token for that account if successful.
+func (p *Processor) Create(ctx context.Context, applicationToken oauth2.TokenInfo, application *gtsmodel.Application, form *apimodel.AccountCreateRequest) (*apimodel.Token, gtserror.WithCode) {
emailAvailable, err := p.db.IsEmailAvailable(ctx, form.Email)
if err != nil {
return nil, gtserror.NewErrorBadRequest(err)
diff --git a/internal/processing/account/createblock.go b/internal/processing/account/createblock.go
deleted file mode 100644
index 68f28fafe..000000000
--- a/internal/processing/account/createblock.go
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "fmt"
-
- "github.com/superseriousbusiness/gotosocial/internal/ap"
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/id"
- "github.com/superseriousbusiness/gotosocial/internal/messages"
- "github.com/superseriousbusiness/gotosocial/internal/uris"
-)
-
-func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
- // make sure the target account actually exists in our db
- targetAccount, err := p.db.GetAccountByID(ctx, targetAccountID)
- if err != nil {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("BlockCreate: error getting account %s from the db: %s", targetAccountID, err))
- }
-
- // if requestingAccount already blocks target account, we don't need to do anything
- if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, false); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error checking existence of block: %s", err))
- } else if blocked {
- return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
- }
-
- // don't block yourself, silly
- if requestingAccount.ID == targetAccountID {
- return nil, gtserror.NewErrorNotAcceptable(fmt.Errorf("BlockCreate: account %s cannot block itself", requestingAccount.ID))
- }
-
- // make the block
- block := >smodel.Block{}
- newBlockID := id.NewULID()
- block.ID = newBlockID
- block.AccountID = requestingAccount.ID
- block.Account = requestingAccount
- block.TargetAccountID = targetAccountID
- block.TargetAccount = targetAccount
- block.URI = uris.GenerateURIForBlock(requestingAccount.Username, newBlockID)
-
- // whack it in the database
- if err := p.db.PutBlock(ctx, block); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error creating block in db: %s", err))
- }
-
- // clear any follows or follow requests from the blocked account to the target account -- this is a simple delete
- if err := p.db.DeleteWhere(ctx, []db.Where{
- {Key: "account_id", Value: targetAccountID},
- {Key: "target_account_id", Value: requestingAccount.ID},
- }, >smodel.Follow{}); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow in db: %s", err))
- }
- if err := p.db.DeleteWhere(ctx, []db.Where{
- {Key: "account_id", Value: targetAccountID},
- {Key: "target_account_id", Value: requestingAccount.ID},
- }, >smodel.FollowRequest{}); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow in db: %s", err))
- }
-
- // clear any follows or follow requests from the requesting account to the target account --
- // this might require federation so we need to pass some messages around
-
- // check if a follow request exists from the requesting account to the target account, and remove it if it does (storing the URI for later)
- var frChanged bool
- var frURI string
- fr := >smodel.FollowRequest{}
- if err := p.db.GetWhere(ctx, []db.Where{
- {Key: "account_id", Value: requestingAccount.ID},
- {Key: "target_account_id", Value: targetAccountID},
- }, fr); err == nil {
- frURI = fr.URI
- if err := p.db.DeleteByID(ctx, fr.ID, fr); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow request from db: %s", err))
- }
- frChanged = true
- }
-
- // now do the same thing for any existing follow
- var fChanged bool
- var fURI string
- f := >smodel.Follow{}
- if err := p.db.GetWhere(ctx, []db.Where{
- {Key: "account_id", Value: requestingAccount.ID},
- {Key: "target_account_id", Value: targetAccountID},
- }, f); err == nil {
- fURI = f.URI
- if err := p.db.DeleteByID(ctx, f.ID, f); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockCreate: error removing follow from db: %s", err))
- }
- fChanged = true
- }
-
- // follow request status changed so send the UNDO activity to the channel for async processing
- if frChanged {
- p.clientWorker.Queue(messages.FromClientAPI{
- APObjectType: ap.ActivityFollow,
- APActivityType: ap.ActivityUndo,
- GTSModel: >smodel.Follow{
- AccountID: requestingAccount.ID,
- TargetAccountID: targetAccountID,
- URI: frURI,
- },
- OriginAccount: requestingAccount,
- TargetAccount: targetAccount,
- })
- }
-
- // follow status changed so send the UNDO activity to the channel for async processing
- if fChanged {
- p.clientWorker.Queue(messages.FromClientAPI{
- APObjectType: ap.ActivityFollow,
- APActivityType: ap.ActivityUndo,
- GTSModel: >smodel.Follow{
- AccountID: requestingAccount.ID,
- TargetAccountID: targetAccountID,
- URI: fURI,
- },
- OriginAccount: requestingAccount,
- TargetAccount: targetAccount,
- })
- }
-
- // handle the rest of the block process asynchronously
- p.clientWorker.Queue(messages.FromClientAPI{
- APObjectType: ap.ActivityBlock,
- APActivityType: ap.ActivityCreate,
- GTSModel: block,
- OriginAccount: requestingAccount,
- TargetAccount: targetAccount,
- })
-
- return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
-}
diff --git a/internal/processing/account/createfollow.go b/internal/processing/account/createfollow.go
deleted file mode 100644
index 721cf39c7..000000000
--- a/internal/processing/account/createfollow.go
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "fmt"
-
- "github.com/superseriousbusiness/gotosocial/internal/ap"
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/id"
- "github.com/superseriousbusiness/gotosocial/internal/messages"
- "github.com/superseriousbusiness/gotosocial/internal/uris"
-)
-
-func (p *processor) FollowCreate(ctx context.Context, requestingAccount *gtsmodel.Account, form *apimodel.AccountFollowRequest) (*apimodel.Relationship, gtserror.WithCode) {
- // if there's a block between the accounts we shouldn't create the request ofc
- if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, form.ID, true); err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- } else if blocked {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
- }
-
- // make sure the target account actually exists in our db
- targetAcct, err := p.db.GetAccountByID(ctx, form.ID)
- if err != nil {
- if err == db.ErrNoEntries {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("accountfollowcreate: account %s not found in the db: %s", form.ID, err))
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- // check if a follow exists already
- if follows, err := p.db.IsFollowing(ctx, requestingAccount, targetAcct); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error checking follow in db: %s", err))
- } else if follows {
- // already follows so just return the relationship
- return p.RelationshipGet(ctx, requestingAccount, form.ID)
- }
-
- // check if a follow request exists already
- if followRequested, err := p.db.IsFollowRequested(ctx, requestingAccount, targetAcct); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error checking follow request in db: %s", err))
- } else if followRequested {
- // already follow requested so just return the relationship
- return p.RelationshipGet(ctx, requestingAccount, form.ID)
- }
-
- // check for attempt to follow self
- if requestingAccount.ID == targetAcct.ID {
- return nil, gtserror.NewErrorNotAcceptable(fmt.Errorf("accountfollowcreate: account %s cannot follow itself", requestingAccount.ID))
- }
-
- // make the follow request
- newFollowID, err := id.NewRandomULID()
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- showReblogs := true
- notify := false
- fr := >smodel.FollowRequest{
- ID: newFollowID,
- AccountID: requestingAccount.ID,
- TargetAccountID: form.ID,
- ShowReblogs: &showReblogs,
- URI: uris.GenerateURIForFollow(requestingAccount.Username, newFollowID),
- Notify: ¬ify,
- }
- if form.Reblogs != nil {
- fr.ShowReblogs = form.Reblogs
- }
- if form.Notify != nil {
- fr.Notify = form.Notify
- }
-
- // whack it in the database
- if err := p.db.Put(ctx, fr); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error creating follow request in db: %s", err))
- }
-
- // if it's a local account that's not locked we can just straight up accept the follow request
- if !*targetAcct.Locked && targetAcct.Domain == "" {
- if _, err := p.db.AcceptFollowRequest(ctx, requestingAccount.ID, form.ID); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error accepting folow request for local unlocked account: %s", err))
- }
- // return the new relationship
- return p.RelationshipGet(ctx, requestingAccount, form.ID)
- }
-
- // otherwise we leave the follow request as it is and we handle the rest of the process asynchronously
- p.clientWorker.Queue(messages.FromClientAPI{
- APObjectType: ap.ActivityFollow,
- APActivityType: ap.ActivityCreate,
- GTSModel: fr,
- OriginAccount: requestingAccount,
- TargetAccount: targetAcct,
- })
-
- // return whatever relationship results from this
- return p.RelationshipGet(ctx, requestingAccount, form.ID)
-}
diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go
index 32321e196..7a31b45d4 100644
--- a/internal/processing/account/delete.go
+++ b/internal/processing/account/delete.go
@@ -34,28 +34,9 @@ import (
"golang.org/x/crypto/bcrypt"
)
-// Delete handles the complete deletion of an account.
-//
-// To be done in this function:
-// 1. Delete account's application(s), clients, and oauth tokens
-// 2. Delete account's blocks
-// 3. Delete account's emoji
-// 4. Delete account's follow requests
-// 5. Delete account's follows
-// 6. Delete account's statuses
-// 7. Delete account's media attachments
-// 8. Delete account's mentions
-// 9. Delete account's polls
-// 10. Delete account's notifications
-// 11. Delete account's bookmarks
-// 12. Delete account's faves
-// 13. Delete account's mutes
-// 14. Delete account's streams
-// 15. Delete account's tags
-// 16. Delete account's user
-// 17. Delete account's timeline
-// 18. Delete account itself
-func (p *processor) Delete(ctx context.Context, account *gtsmodel.Account, origin string) gtserror.WithCode {
+// Delete deletes an account, and all of that account's statuses, media, follows, notifications, etc etc etc.
+// The origin passed here should be either the ID of the account doing the delete (can be itself), or the ID of a domain block.
+func (p *Processor) Delete(ctx context.Context, account *gtsmodel.Account, origin string) gtserror.WithCode {
fields := kv.Fields{{"username", account.Username}}
if account.Domain != "" {
@@ -289,7 +270,9 @@ func (p *processor) Delete(ctx context.Context, account *gtsmodel.Account, origi
return nil
}
-func (p *processor) DeleteLocal(ctx context.Context, account *gtsmodel.Account, form *apimodel.AccountDeleteRequest) gtserror.WithCode {
+// DeleteLocal is like Delete, but specifically for deletion of local accounts rather than federated ones.
+// Unlike Delete, it will propagate the deletion out across the federating API to other instances.
+func (p *Processor) DeleteLocal(ctx context.Context, account *gtsmodel.Account, form *apimodel.AccountDeleteRequest) gtserror.WithCode {
fromClientAPIMessage := messages.FromClientAPI{
APObjectType: ap.ActorPerson,
APActivityType: ap.ActivityDelete,
diff --git a/internal/processing/account/follow.go b/internal/processing/account/follow.go
new file mode 100644
index 000000000..d4d479be7
--- /dev/null
+++ b/internal/processing/account/follow.go
@@ -0,0 +1,205 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ 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 .
+*/
+
+package account
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
+ apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
+ "github.com/superseriousbusiness/gotosocial/internal/uris"
+)
+
+// FollowCreate handles a follow request to an account, either remote or local.
+func (p *Processor) FollowCreate(ctx context.Context, requestingAccount *gtsmodel.Account, form *apimodel.AccountFollowRequest) (*apimodel.Relationship, gtserror.WithCode) {
+ // if there's a block between the accounts we shouldn't create the request ofc
+ if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, form.ID, true); err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ } else if blocked {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
+ }
+
+ // make sure the target account actually exists in our db
+ targetAcct, err := p.db.GetAccountByID(ctx, form.ID)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("accountfollowcreate: account %s not found in the db: %s", form.ID, err))
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ // check if a follow exists already
+ if follows, err := p.db.IsFollowing(ctx, requestingAccount, targetAcct); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error checking follow in db: %s", err))
+ } else if follows {
+ // already follows so just return the relationship
+ return p.RelationshipGet(ctx, requestingAccount, form.ID)
+ }
+
+ // check if a follow request exists already
+ if followRequested, err := p.db.IsFollowRequested(ctx, requestingAccount, targetAcct); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error checking follow request in db: %s", err))
+ } else if followRequested {
+ // already follow requested so just return the relationship
+ return p.RelationshipGet(ctx, requestingAccount, form.ID)
+ }
+
+ // check for attempt to follow self
+ if requestingAccount.ID == targetAcct.ID {
+ return nil, gtserror.NewErrorNotAcceptable(fmt.Errorf("accountfollowcreate: account %s cannot follow itself", requestingAccount.ID))
+ }
+
+ // make the follow request
+ newFollowID, err := id.NewRandomULID()
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ showReblogs := true
+ notify := false
+ fr := >smodel.FollowRequest{
+ ID: newFollowID,
+ AccountID: requestingAccount.ID,
+ TargetAccountID: form.ID,
+ ShowReblogs: &showReblogs,
+ URI: uris.GenerateURIForFollow(requestingAccount.Username, newFollowID),
+ Notify: ¬ify,
+ }
+ if form.Reblogs != nil {
+ fr.ShowReblogs = form.Reblogs
+ }
+ if form.Notify != nil {
+ fr.Notify = form.Notify
+ }
+
+ // whack it in the database
+ if err := p.db.Put(ctx, fr); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error creating follow request in db: %s", err))
+ }
+
+ // if it's a local account that's not locked we can just straight up accept the follow request
+ if !*targetAcct.Locked && targetAcct.Domain == "" {
+ if _, err := p.db.AcceptFollowRequest(ctx, requestingAccount.ID, form.ID); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("accountfollowcreate: error accepting folow request for local unlocked account: %s", err))
+ }
+ // return the new relationship
+ return p.RelationshipGet(ctx, requestingAccount, form.ID)
+ }
+
+ // otherwise we leave the follow request as it is and we handle the rest of the process asynchronously
+ p.clientWorker.Queue(messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityCreate,
+ GTSModel: fr,
+ OriginAccount: requestingAccount,
+ TargetAccount: targetAcct,
+ })
+
+ // return whatever relationship results from this
+ return p.RelationshipGet(ctx, requestingAccount, form.ID)
+}
+
+// FollowRemove handles the removal of a follow/follow request to an account, either remote or local.
+func (p *Processor) FollowRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
+ // if there's a block between the accounts we shouldn't do anything
+ blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ if blocked {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("AccountFollowRemove: block exists between accounts"))
+ }
+
+ // make sure the target account actually exists in our db
+ targetAcct, err := p.db.GetAccountByID(ctx, targetAccountID)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("AccountFollowRemove: account %s not found in the db: %s", targetAccountID, err))
+ }
+ }
+
+ // check if a follow request exists, and remove it if it does (storing the URI for later)
+ var frChanged bool
+ var frURI string
+ fr := >smodel.FollowRequest{}
+ if err := p.db.GetWhere(ctx, []db.Where{
+ {Key: "account_id", Value: requestingAccount.ID},
+ {Key: "target_account_id", Value: targetAccountID},
+ }, fr); err == nil {
+ frURI = fr.URI
+ if err := p.db.DeleteByID(ctx, fr.ID, fr); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("AccountFollowRemove: error removing follow request from db: %s", err))
+ }
+ frChanged = true
+ }
+
+ // now do the same thing for any existing follow
+ var fChanged bool
+ var fURI string
+ f := >smodel.Follow{}
+ if err := p.db.GetWhere(ctx, []db.Where{
+ {Key: "account_id", Value: requestingAccount.ID},
+ {Key: "target_account_id", Value: targetAccountID},
+ }, f); err == nil {
+ fURI = f.URI
+ if err := p.db.DeleteByID(ctx, f.ID, f); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("AccountFollowRemove: error removing follow from db: %s", err))
+ }
+ fChanged = true
+ }
+
+ // follow request status changed so send the UNDO activity to the channel for async processing
+ if frChanged {
+ p.clientWorker.Queue(messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
+ GTSModel: >smodel.Follow{
+ AccountID: requestingAccount.ID,
+ TargetAccountID: targetAccountID,
+ URI: frURI,
+ },
+ OriginAccount: requestingAccount,
+ TargetAccount: targetAcct,
+ })
+ }
+
+ // follow status changed so send the UNDO activity to the channel for async processing
+ if fChanged {
+ p.clientWorker.Queue(messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
+ GTSModel: >smodel.Follow{
+ AccountID: requestingAccount.ID,
+ TargetAccountID: targetAccountID,
+ URI: fURI,
+ },
+ OriginAccount: requestingAccount,
+ TargetAccount: targetAcct,
+ })
+ }
+
+ // return whatever relationship results from all this
+ return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
+}
diff --git a/internal/processing/account/get.go b/internal/processing/account/get.go
index 0592555da..11de1ddac 100644
--- a/internal/processing/account/get.go
+++ b/internal/processing/account/get.go
@@ -31,7 +31,8 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
-func (p *processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Account, gtserror.WithCode) {
+// Get processes the given request for account information.
+func (p *Processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Account, gtserror.WithCode) {
targetAccount, err := p.db.GetAccountByID(ctx, targetAccountID)
if err != nil {
if err == db.ErrNoEntries {
@@ -40,10 +41,11 @@ func (p *processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account
return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error: %s", err))
}
- return p.getAccountFor(ctx, requestingAccount, targetAccount)
+ return p.getFor(ctx, requestingAccount, targetAccount)
}
-func (p *processor) GetLocalByUsername(ctx context.Context, requestingAccount *gtsmodel.Account, username string) (*apimodel.Account, gtserror.WithCode) {
+// GetLocalByUsername processes the given request for account information targeting a local account by username.
+func (p *Processor) GetLocalByUsername(ctx context.Context, requestingAccount *gtsmodel.Account, username string) (*apimodel.Account, gtserror.WithCode) {
targetAccount, err := p.db.GetAccountByUsernameDomain(ctx, username, "")
if err != nil {
if err == db.ErrNoEntries {
@@ -52,10 +54,11 @@ func (p *processor) GetLocalByUsername(ctx context.Context, requestingAccount *g
return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error: %s", err))
}
- return p.getAccountFor(ctx, requestingAccount, targetAccount)
+ return p.getFor(ctx, requestingAccount, targetAccount)
}
-func (p *processor) GetCustomCSSForUsername(ctx context.Context, username string) (string, gtserror.WithCode) {
+// GetCustomCSSForUsername returns custom css for the given local username.
+func (p *Processor) GetCustomCSSForUsername(ctx context.Context, username string) (string, gtserror.WithCode) {
customCSS, err := p.db.GetAccountCustomCSSByUsername(ctx, username)
if err != nil {
if err == db.ErrNoEntries {
@@ -67,7 +70,7 @@ func (p *processor) GetCustomCSSForUsername(ctx context.Context, username string
return customCSS, nil
}
-func (p *processor) getAccountFor(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (*apimodel.Account, gtserror.WithCode) {
+func (p *Processor) getFor(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (*apimodel.Account, gtserror.WithCode) {
var blocked bool
var err error
if requestingAccount != nil {
diff --git a/internal/processing/account/getbookmarks.go b/internal/processing/account/getbookmarks.go
deleted file mode 100644
index 0a63a074f..000000000
--- a/internal/processing/account/getbookmarks.go
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "fmt"
-
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/util"
-)
-
-func (p *processor) BookmarksGet(ctx context.Context, requestingAccount *gtsmodel.Account, limit int, maxID string, minID string) (*apimodel.PageableResponse, gtserror.WithCode) {
- if requestingAccount == nil {
- return nil, gtserror.NewErrorForbidden(fmt.Errorf("cannot retrieve bookmarks without a requesting account"))
- }
-
- bookmarks, err := p.db.GetBookmarks(ctx, requestingAccount.ID, limit, maxID, minID)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- count := len(bookmarks)
- filtered := make([]*gtsmodel.Status, 0, len(bookmarks))
- nextMaxIDValue := ""
- prevMinIDValue := ""
- for i, b := range bookmarks {
- s, err := p.db.GetStatusByID(ctx, b.StatusID)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- visible, err := p.filter.StatusVisible(ctx, s, requestingAccount)
- if err == nil && visible {
- if i == count-1 {
- nextMaxIDValue = b.ID
- }
-
- if i == 0 {
- prevMinIDValue = b.ID
- }
-
- filtered = append(filtered, s)
- }
- }
-
- count = len(filtered)
-
- if count == 0 {
- return util.EmptyPageableResponse(), nil
- }
-
- items := []interface{}{}
- for _, s := range filtered {
- item, err := p.tc.StatusToAPIStatus(ctx, s, requestingAccount)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status to api: %s", err))
- }
- items = append(items, item)
- }
-
- return util.PackagePageableResponse(util.PageableResponseParams{
- Items: items,
- Path: "/api/v1/bookmarks",
- NextMaxIDValue: nextMaxIDValue,
- PrevMinIDValue: prevMinIDValue,
- Limit: limit,
- ExtraQueryParams: []string{},
- })
-}
diff --git a/internal/processing/account/getfollowers.go b/internal/processing/account/getfollowers.go
deleted file mode 100644
index df6fcc3f9..000000000
--- a/internal/processing/account/getfollowers.go
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "fmt"
-
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-func (p *processor) FollowersGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) ([]apimodel.Account, gtserror.WithCode) {
- if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- } else if blocked {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
- }
-
- accounts := []apimodel.Account{}
- follows, err := p.db.GetAccountFollowedBy(ctx, targetAccountID, false)
- if err != nil {
- if err == db.ErrNoEntries {
- return accounts, nil
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- for _, f := range follows {
- blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, f.AccountID, true)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
- if blocked {
- continue
- }
-
- if f.Account == nil {
- a, err := p.db.GetAccountByID(ctx, f.AccountID)
- if err != nil {
- if err == db.ErrNoEntries {
- continue
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
- f.Account = a
- }
-
- account, err := p.tc.AccountToAPIAccountPublic(ctx, f.Account)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
- accounts = append(accounts, *account)
- }
- return accounts, nil
-}
diff --git a/internal/processing/account/getfollowing.go b/internal/processing/account/getfollowing.go
deleted file mode 100644
index fc584c778..000000000
--- a/internal/processing/account/getfollowing.go
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "fmt"
-
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-func (p *processor) FollowingGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) ([]apimodel.Account, gtserror.WithCode) {
- if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- } else if blocked {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
- }
-
- accounts := []apimodel.Account{}
- follows, err := p.db.GetAccountFollows(ctx, targetAccountID)
- if err != nil {
- if err == db.ErrNoEntries {
- return accounts, nil
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- for _, f := range follows {
- blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, f.AccountID, true)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
- if blocked {
- continue
- }
-
- if f.TargetAccount == nil {
- a, err := p.db.GetAccountByID(ctx, f.TargetAccountID)
- if err != nil {
- if err == db.ErrNoEntries {
- continue
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
- f.TargetAccount = a
- }
-
- account, err := p.tc.AccountToAPIAccountPublic(ctx, f.TargetAccount)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
- accounts = append(accounts, *account)
- }
- return accounts, nil
-}
diff --git a/internal/processing/account/getrelationship.go b/internal/processing/account/getrelationship.go
deleted file mode 100644
index b8406c38a..000000000
--- a/internal/processing/account/getrelationship.go
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "errors"
- "fmt"
-
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-func (p *processor) RelationshipGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
- if requestingAccount == nil {
- return nil, gtserror.NewErrorForbidden(errors.New("not authed"))
- }
-
- gtsR, err := p.db.GetRelationship(ctx, requestingAccount.ID, targetAccountID)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error getting relationship: %s", err))
- }
-
- r, err := p.tc.RelationshipToAPIRelationship(ctx, gtsR)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting relationship: %s", err))
- }
-
- return r, nil
-}
diff --git a/internal/processing/account/getrss.go b/internal/processing/account/getrss.go
deleted file mode 100644
index 2298f39ae..000000000
--- a/internal/processing/account/getrss.go
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "errors"
- "fmt"
- "time"
-
- "github.com/gorilla/feeds"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
-)
-
-const rssFeedLength = 20
-
-func (p *processor) GetRSSFeedForUsername(ctx context.Context, username string) (func() (string, gtserror.WithCode), time.Time, gtserror.WithCode) {
- account, err := p.db.GetAccountByUsernameDomain(ctx, username, "")
- if err != nil {
- if err == db.ErrNoEntries {
- return nil, time.Time{}, gtserror.NewErrorNotFound(errors.New("GetRSSFeedForUsername: account not found"))
- }
- return nil, time.Time{}, gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error: %s", err))
- }
-
- if !*account.EnableRSS {
- return nil, time.Time{}, gtserror.NewErrorNotFound(errors.New("GetRSSFeedForUsername: account RSS feed not enabled"))
- }
-
- lastModified, err := p.db.GetAccountLastPosted(ctx, account.ID, true)
- if err != nil {
- return nil, time.Time{}, gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error: %s", err))
- }
-
- return func() (string, gtserror.WithCode) {
- statuses, err := p.db.GetAccountWebStatuses(ctx, account.ID, rssFeedLength, "")
- if err != nil && err != db.ErrNoEntries {
- return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error: %s", err))
- }
-
- author := "@" + account.Username + "@" + config.GetAccountDomain()
- title := "Posts from " + author
- description := "Posts from " + author
- link := &feeds.Link{Href: account.URL}
-
- var image *feeds.Image
- if account.AvatarMediaAttachmentID != "" {
- if account.AvatarMediaAttachment == nil {
- avatar, err := p.db.GetAttachmentByID(ctx, account.AvatarMediaAttachmentID)
- if err != nil {
- return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error fetching avatar attachment: %s", err))
- }
- account.AvatarMediaAttachment = avatar
- }
- image = &feeds.Image{
- Url: account.AvatarMediaAttachment.Thumbnail.URL,
- Title: "Avatar for " + author,
- Link: account.URL,
- }
- }
-
- feed := &feeds.Feed{
- Title: title,
- Description: description,
- Link: link,
- Image: image,
- }
-
- for i, s := range statuses {
- // take the date of the first (ie., latest) status as feed updated value
- if i == 0 {
- feed.Updated = s.UpdatedAt
- }
-
- item, err := p.tc.StatusToRSSItem(ctx, s)
- if err != nil {
- return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: error converting status to feed item: %s", err))
- }
-
- feed.Add(item)
- }
-
- rss, err := feed.ToRss()
- if err != nil {
- return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: error converting feed to rss string: %s", err))
- }
-
- return rss, nil
- }, lastModified, nil
-}
diff --git a/internal/processing/account/getrss_test.go b/internal/processing/account/getrss_test.go
deleted file mode 100644
index 6c699abae..000000000
--- a/internal/processing/account/getrss_test.go
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account_test
-
-import (
- "context"
- "fmt"
- "testing"
-
- "github.com/stretchr/testify/suite"
-)
-
-type GetRSSTestSuite struct {
- AccountStandardTestSuite
-}
-
-func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() {
- getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "admin")
- suite.NoError(err)
- suite.EqualValues(1634733405, lastModified.Unix())
-
- feed, err := getFeed()
- suite.NoError(err)
-
- fmt.Println(feed)
-
- suite.Equal("\n \n Posts from @admin@localhost:8080\n http://localhost:8080/@admin\n Posts from @admin@localhost:8080\n Wed, 20 Oct 2021 12:36:45 +0000\n Wed, 20 Oct 2021 12:36:45 +0000\n \n open to see some puppies\n http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37\n @admin@localhost:8080 made a new post: "🐕🐕🐕🐕🐕"\n \n @admin@localhost:8080\n http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37\n Wed, 20 Oct 2021 12:36:45 +0000\n http://localhost:8080/@admin/feed.rss\n \n \n hello world! #welcome ! first post on the instance :rainbow: !\n http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R\n @admin@localhost:8080 posted 1 attachment: "hello world! #welcome ! first post on the instance :rainbow: !"\n !]]>\n @admin@localhost:8080\n \n http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R\n Wed, 20 Oct 2021 11:36:45 +0000\n http://localhost:8080/@admin/feed.rss\n \n \n", feed)
-}
-
-func (suite *GetRSSTestSuite) TestGetAccountRSSZork() {
- getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "the_mighty_zork")
- suite.NoError(err)
- suite.EqualValues(1634726437, lastModified.Unix())
-
- feed, err := getFeed()
- suite.NoError(err)
-
- fmt.Println(feed)
-
- suite.Equal("\n \n Posts from @the_mighty_zork@localhost:8080\n http://localhost:8080/@the_mighty_zork\n Posts from @the_mighty_zork@localhost:8080\n Wed, 20 Oct 2021 10:40:37 +0000\n Wed, 20 Oct 2021 10:40:37 +0000\n \n http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.jpg\n Avatar for @the_mighty_zork@localhost:8080\n http://localhost:8080/@the_mighty_zork\n \n \n introduction post\n http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY\n @the_mighty_zork@localhost:8080 made a new post: "hello everyone!"\n \n @the_mighty_zork@localhost:8080\n http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY\n Wed, 20 Oct 2021 10:40:37 +0000\n http://localhost:8080/@the_mighty_zork/feed.rss\n \n \n", feed)
-}
-
-func TestGetRSSTestSuite(t *testing.T) {
- suite.Run(t, new(GetRSSTestSuite))
-}
diff --git a/internal/processing/account/getstatuses.go b/internal/processing/account/getstatuses.go
deleted file mode 100644
index b231bb450..000000000
--- a/internal/processing/account/getstatuses.go
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "fmt"
-
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/util"
-)
-
-func (p *processor) StatusesGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string, limit int, excludeReplies bool, excludeReblogs bool, maxID string, minID string, pinnedOnly bool, mediaOnly bool, publicOnly bool) (*apimodel.PageableResponse, gtserror.WithCode) {
- if requestingAccount != nil {
- if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- } else if blocked {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
- }
- }
-
- statuses, err := p.db.GetAccountStatuses(ctx, targetAccountID, limit, excludeReplies, excludeReblogs, maxID, minID, pinnedOnly, mediaOnly, publicOnly)
- if err != nil {
- if err == db.ErrNoEntries {
- return util.EmptyPageableResponse(), nil
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- var filtered []*gtsmodel.Status
- for _, s := range statuses {
- visible, err := p.filter.StatusVisible(ctx, s, requestingAccount)
- if err == nil && visible {
- filtered = append(filtered, s)
- }
- }
-
- count := len(filtered)
-
- if count == 0 {
- return util.EmptyPageableResponse(), nil
- }
-
- items := []interface{}{}
- nextMaxIDValue := ""
- prevMinIDValue := ""
- for i, s := range filtered {
- item, err := p.tc.StatusToAPIStatus(ctx, s, requestingAccount)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status to api: %s", err))
- }
-
- if i == count-1 {
- nextMaxIDValue = item.GetID()
- }
-
- if i == 0 {
- prevMinIDValue = item.GetID()
- }
-
- items = append(items, item)
- }
-
- return util.PackagePageableResponse(util.PageableResponseParams{
- Items: items,
- Path: fmt.Sprintf("/api/v1/accounts/%s/statuses", targetAccountID),
- NextMaxIDValue: nextMaxIDValue,
- PrevMinIDValue: prevMinIDValue,
- Limit: limit,
- ExtraQueryParams: []string{
- fmt.Sprintf("exclude_replies=%t", excludeReplies),
- fmt.Sprintf("exclude_reblogs=%t", excludeReblogs),
- fmt.Sprintf("pinned_only=%t", pinnedOnly),
- fmt.Sprintf("only_media=%t", mediaOnly),
- fmt.Sprintf("only_public=%t", publicOnly),
- },
- })
-}
-
-func (p *processor) WebStatusesGet(ctx context.Context, targetAccountID string, maxID string) (*apimodel.PageableResponse, gtserror.WithCode) {
- acct, err := p.db.GetAccountByID(ctx, targetAccountID)
- if err != nil {
- if err == db.ErrNoEntries {
- err := fmt.Errorf("account %s not found in the db, not getting web statuses for it", targetAccountID)
- return nil, gtserror.NewErrorNotFound(err)
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- if acct.Domain != "" {
- err := fmt.Errorf("account %s was not a local account, not getting web statuses for it", targetAccountID)
- return nil, gtserror.NewErrorNotFound(err)
- }
-
- statuses, err := p.db.GetAccountWebStatuses(ctx, targetAccountID, 10, maxID)
- if err != nil {
- if err == db.ErrNoEntries {
- return util.EmptyPageableResponse(), nil
- }
- return nil, gtserror.NewErrorInternalError(err)
- }
-
- count := len(statuses)
-
- if count == 0 {
- return util.EmptyPageableResponse(), nil
- }
-
- items := []interface{}{}
- nextMaxIDValue := ""
- prevMinIDValue := ""
- for i, s := range statuses {
- item, err := p.tc.StatusToAPIStatus(ctx, s, nil)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status to api: %s", err))
- }
-
- if i == count-1 {
- nextMaxIDValue = item.GetID()
- }
-
- if i == 0 {
- prevMinIDValue = item.GetID()
- }
-
- items = append(items, item)
- }
-
- return util.PackagePageableResponse(util.PageableResponseParams{
- Items: items,
- Path: "/@" + acct.Username,
- NextMaxIDValue: nextMaxIDValue,
- PrevMinIDValue: prevMinIDValue,
- ExtraQueryParams: []string{},
- })
-}
diff --git a/internal/processing/account/relationships.go b/internal/processing/account/relationships.go
new file mode 100644
index 000000000..cb2789829
--- /dev/null
+++ b/internal/processing/account/relationships.go
@@ -0,0 +1,141 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ 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 .
+*/
+
+package account
+
+import (
+ "context"
+ "errors"
+ "fmt"
+
+ apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+)
+
+// FollowersGet fetches a list of the target account's followers.
+func (p *Processor) FollowersGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) ([]apimodel.Account, gtserror.WithCode) {
+ if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ } else if blocked {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
+ }
+
+ accounts := []apimodel.Account{}
+ follows, err := p.db.GetAccountFollowedBy(ctx, targetAccountID, false)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ return accounts, nil
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ for _, f := range follows {
+ blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, f.AccountID, true)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ if blocked {
+ continue
+ }
+
+ if f.Account == nil {
+ a, err := p.db.GetAccountByID(ctx, f.AccountID)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ continue
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ f.Account = a
+ }
+
+ account, err := p.tc.AccountToAPIAccountPublic(ctx, f.Account)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ accounts = append(accounts, *account)
+ }
+ return accounts, nil
+}
+
+// FollowingGet fetches a list of the accounts that target account is following.
+func (p *Processor) FollowingGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) ([]apimodel.Account, gtserror.WithCode) {
+ if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ } else if blocked {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
+ }
+
+ accounts := []apimodel.Account{}
+ follows, err := p.db.GetAccountFollows(ctx, targetAccountID)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ return accounts, nil
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ for _, f := range follows {
+ blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, f.AccountID, true)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ if blocked {
+ continue
+ }
+
+ if f.TargetAccount == nil {
+ a, err := p.db.GetAccountByID(ctx, f.TargetAccountID)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ continue
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ f.TargetAccount = a
+ }
+
+ account, err := p.tc.AccountToAPIAccountPublic(ctx, f.TargetAccount)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ accounts = append(accounts, *account)
+ }
+ return accounts, nil
+}
+
+// RelationshipGet returns a relationship model describing the relationship of the targetAccount to the Authed account.
+func (p *Processor) RelationshipGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
+ if requestingAccount == nil {
+ return nil, gtserror.NewErrorForbidden(errors.New("not authed"))
+ }
+
+ gtsR, err := p.db.GetRelationship(ctx, requestingAccount.ID, targetAccountID)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error getting relationship: %s", err))
+ }
+
+ r, err := p.tc.RelationshipToAPIRelationship(ctx, gtsR)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting relationship: %s", err))
+ }
+
+ return r, nil
+}
diff --git a/internal/processing/account/removeblock.go b/internal/processing/account/removeblock.go
deleted file mode 100644
index 4316af10f..000000000
--- a/internal/processing/account/removeblock.go
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "errors"
- "fmt"
-
- "github.com/superseriousbusiness/gotosocial/internal/ap"
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/messages"
-)
-
-func (p *processor) BlockRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
- // make sure the target account actually exists in our db
- targetAccount, err := p.db.GetAccountByID(ctx, targetAccountID)
- if err != nil {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("BlockCreate: error getting account %s from the db: %s", targetAccountID, err))
- }
-
- // check if a block exists, and remove it if it does
- block, err := p.db.GetBlock(ctx, requestingAccount.ID, targetAccountID)
- if err == nil {
- // we got a block, remove it
- block.Account = requestingAccount
- block.TargetAccount = targetAccount
- if err := p.db.DeleteBlockByID(ctx, block.ID); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockRemove: error removing block from db: %s", err))
- }
-
- // send the UNDO activity to the client worker for async processing
- p.clientWorker.Queue(messages.FromClientAPI{
- APObjectType: ap.ActivityBlock,
- APActivityType: ap.ActivityUndo,
- GTSModel: block,
- OriginAccount: requestingAccount,
- TargetAccount: targetAccount,
- })
- } else if !errors.Is(err, db.ErrNoEntries) {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("BlockRemove: error getting possible block from db: %s", err))
- }
-
- // return whatever relationship results from all this
- return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
-}
diff --git a/internal/processing/account/removefollow.go b/internal/processing/account/removefollow.go
deleted file mode 100644
index 83ced1238..000000000
--- a/internal/processing/account/removefollow.go
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
-
- 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 .
-*/
-
-package account
-
-import (
- "context"
- "fmt"
-
- "github.com/superseriousbusiness/gotosocial/internal/ap"
- apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/messages"
-)
-
-func (p *processor) FollowRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
- // if there's a block between the accounts we shouldn't do anything
- blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(err)
- }
- if blocked {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("AccountFollowRemove: block exists between accounts"))
- }
-
- // make sure the target account actually exists in our db
- targetAcct, err := p.db.GetAccountByID(ctx, targetAccountID)
- if err != nil {
- if err == db.ErrNoEntries {
- return nil, gtserror.NewErrorNotFound(fmt.Errorf("AccountFollowRemove: account %s not found in the db: %s", targetAccountID, err))
- }
- }
-
- // check if a follow request exists, and remove it if it does (storing the URI for later)
- var frChanged bool
- var frURI string
- fr := >smodel.FollowRequest{}
- if err := p.db.GetWhere(ctx, []db.Where{
- {Key: "account_id", Value: requestingAccount.ID},
- {Key: "target_account_id", Value: targetAccountID},
- }, fr); err == nil {
- frURI = fr.URI
- if err := p.db.DeleteByID(ctx, fr.ID, fr); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("AccountFollowRemove: error removing follow request from db: %s", err))
- }
- frChanged = true
- }
-
- // now do the same thing for any existing follow
- var fChanged bool
- var fURI string
- f := >smodel.Follow{}
- if err := p.db.GetWhere(ctx, []db.Where{
- {Key: "account_id", Value: requestingAccount.ID},
- {Key: "target_account_id", Value: targetAccountID},
- }, f); err == nil {
- fURI = f.URI
- if err := p.db.DeleteByID(ctx, f.ID, f); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("AccountFollowRemove: error removing follow from db: %s", err))
- }
- fChanged = true
- }
-
- // follow request status changed so send the UNDO activity to the channel for async processing
- if frChanged {
- p.clientWorker.Queue(messages.FromClientAPI{
- APObjectType: ap.ActivityFollow,
- APActivityType: ap.ActivityUndo,
- GTSModel: >smodel.Follow{
- AccountID: requestingAccount.ID,
- TargetAccountID: targetAccountID,
- URI: frURI,
- },
- OriginAccount: requestingAccount,
- TargetAccount: targetAcct,
- })
- }
-
- // follow status changed so send the UNDO activity to the channel for async processing
- if fChanged {
- p.clientWorker.Queue(messages.FromClientAPI{
- APObjectType: ap.ActivityFollow,
- APActivityType: ap.ActivityUndo,
- GTSModel: >smodel.Follow{
- AccountID: requestingAccount.ID,
- TargetAccountID: targetAccountID,
- URI: fURI,
- },
- OriginAccount: requestingAccount,
- TargetAccount: targetAcct,
- })
- }
-
- // return whatever relationship results from all this
- return p.RelationshipGet(ctx, requestingAccount, targetAccountID)
-}
diff --git a/internal/processing/account/rss.go b/internal/processing/account/rss.go
new file mode 100644
index 000000000..22065cf8e
--- /dev/null
+++ b/internal/processing/account/rss.go
@@ -0,0 +1,109 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ 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 .
+*/
+
+package account
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "time"
+
+ "github.com/gorilla/feeds"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+)
+
+const rssFeedLength = 20
+
+// GetRSSFeedForUsername returns RSS feed for the given local username.
+func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string) (func() (string, gtserror.WithCode), time.Time, gtserror.WithCode) {
+ account, err := p.db.GetAccountByUsernameDomain(ctx, username, "")
+ if err != nil {
+ if err == db.ErrNoEntries {
+ return nil, time.Time{}, gtserror.NewErrorNotFound(errors.New("GetRSSFeedForUsername: account not found"))
+ }
+ return nil, time.Time{}, gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error: %s", err))
+ }
+
+ if !*account.EnableRSS {
+ return nil, time.Time{}, gtserror.NewErrorNotFound(errors.New("GetRSSFeedForUsername: account RSS feed not enabled"))
+ }
+
+ lastModified, err := p.db.GetAccountLastPosted(ctx, account.ID, true)
+ if err != nil {
+ return nil, time.Time{}, gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error: %s", err))
+ }
+
+ return func() (string, gtserror.WithCode) {
+ statuses, err := p.db.GetAccountWebStatuses(ctx, account.ID, rssFeedLength, "")
+ if err != nil && err != db.ErrNoEntries {
+ return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error: %s", err))
+ }
+
+ author := "@" + account.Username + "@" + config.GetAccountDomain()
+ title := "Posts from " + author
+ description := "Posts from " + author
+ link := &feeds.Link{Href: account.URL}
+
+ var image *feeds.Image
+ if account.AvatarMediaAttachmentID != "" {
+ if account.AvatarMediaAttachment == nil {
+ avatar, err := p.db.GetAttachmentByID(ctx, account.AvatarMediaAttachmentID)
+ if err != nil {
+ return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: db error fetching avatar attachment: %s", err))
+ }
+ account.AvatarMediaAttachment = avatar
+ }
+ image = &feeds.Image{
+ Url: account.AvatarMediaAttachment.Thumbnail.URL,
+ Title: "Avatar for " + author,
+ Link: account.URL,
+ }
+ }
+
+ feed := &feeds.Feed{
+ Title: title,
+ Description: description,
+ Link: link,
+ Image: image,
+ }
+
+ for i, s := range statuses {
+ // take the date of the first (ie., latest) status as feed updated value
+ if i == 0 {
+ feed.Updated = s.UpdatedAt
+ }
+
+ item, err := p.tc.StatusToRSSItem(ctx, s)
+ if err != nil {
+ return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: error converting status to feed item: %s", err))
+ }
+
+ feed.Add(item)
+ }
+
+ rss, err := feed.ToRss()
+ if err != nil {
+ return "", gtserror.NewErrorInternalError(fmt.Errorf("GetRSSFeedForUsername: error converting feed to rss string: %s", err))
+ }
+
+ return rss, nil
+ }, lastModified, nil
+}
diff --git a/internal/processing/account/rss_test.go b/internal/processing/account/rss_test.go
new file mode 100644
index 000000000..6c699abae
--- /dev/null
+++ b/internal/processing/account/rss_test.go
@@ -0,0 +1,61 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ 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 .
+*/
+
+package account_test
+
+import (
+ "context"
+ "fmt"
+ "testing"
+
+ "github.com/stretchr/testify/suite"
+)
+
+type GetRSSTestSuite struct {
+ AccountStandardTestSuite
+}
+
+func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() {
+ getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "admin")
+ suite.NoError(err)
+ suite.EqualValues(1634733405, lastModified.Unix())
+
+ feed, err := getFeed()
+ suite.NoError(err)
+
+ fmt.Println(feed)
+
+ suite.Equal("\n \n Posts from @admin@localhost:8080\n http://localhost:8080/@admin\n Posts from @admin@localhost:8080\n Wed, 20 Oct 2021 12:36:45 +0000\n Wed, 20 Oct 2021 12:36:45 +0000\n \n open to see some puppies\n http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37\n @admin@localhost:8080 made a new post: "🐕🐕🐕🐕🐕"\n \n @admin@localhost:8080\n http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37\n Wed, 20 Oct 2021 12:36:45 +0000\n http://localhost:8080/@admin/feed.rss\n \n \n hello world! #welcome ! first post on the instance :rainbow: !\n http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R\n @admin@localhost:8080 posted 1 attachment: "hello world! #welcome ! first post on the instance :rainbow: !"\n !]]>\n @admin@localhost:8080\n \n http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R\n Wed, 20 Oct 2021 11:36:45 +0000\n http://localhost:8080/@admin/feed.rss\n \n \n", feed)
+}
+
+func (suite *GetRSSTestSuite) TestGetAccountRSSZork() {
+ getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(context.Background(), "the_mighty_zork")
+ suite.NoError(err)
+ suite.EqualValues(1634726437, lastModified.Unix())
+
+ feed, err := getFeed()
+ suite.NoError(err)
+
+ fmt.Println(feed)
+
+ suite.Equal("\n \n Posts from @the_mighty_zork@localhost:8080\n http://localhost:8080/@the_mighty_zork\n Posts from @the_mighty_zork@localhost:8080\n Wed, 20 Oct 2021 10:40:37 +0000\n Wed, 20 Oct 2021 10:40:37 +0000\n \n http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.jpg\n Avatar for @the_mighty_zork@localhost:8080\n http://localhost:8080/@the_mighty_zork\n \n \n introduction post\n http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY\n @the_mighty_zork@localhost:8080 made a new post: "hello everyone!"\n \n @the_mighty_zork@localhost:8080\n http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY\n Wed, 20 Oct 2021 10:40:37 +0000\n http://localhost:8080/@the_mighty_zork/feed.rss\n \n \n", feed)
+}
+
+func TestGetRSSTestSuite(t *testing.T) {
+ suite.Run(t, new(GetRSSTestSuite))
+}
diff --git a/internal/processing/account/statuses.go b/internal/processing/account/statuses.go
new file mode 100644
index 000000000..29833086d
--- /dev/null
+++ b/internal/processing/account/statuses.go
@@ -0,0 +1,159 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
+
+ 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 .
+*/
+
+package account
+
+import (
+ "context"
+ "fmt"
+
+ apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
+)
+
+// StatusesGet fetches a number of statuses (in time descending order) from the given account, filtered by visibility for
+// the account given in authed.
+func (p *Processor) StatusesGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string, limit int, excludeReplies bool, excludeReblogs bool, maxID string, minID string, pinnedOnly bool, mediaOnly bool, publicOnly bool) (*apimodel.PageableResponse, gtserror.WithCode) {
+ if requestingAccount != nil {
+ if blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, targetAccountID, true); err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ } else if blocked {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("block exists between accounts"))
+ }
+ }
+
+ statuses, err := p.db.GetAccountStatuses(ctx, targetAccountID, limit, excludeReplies, excludeReblogs, maxID, minID, pinnedOnly, mediaOnly, publicOnly)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ return util.EmptyPageableResponse(), nil
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ var filtered []*gtsmodel.Status
+ for _, s := range statuses {
+ visible, err := p.filter.StatusVisible(ctx, s, requestingAccount)
+ if err == nil && visible {
+ filtered = append(filtered, s)
+ }
+ }
+
+ count := len(filtered)
+
+ if count == 0 {
+ return util.EmptyPageableResponse(), nil
+ }
+
+ items := []interface{}{}
+ nextMaxIDValue := ""
+ prevMinIDValue := ""
+ for i, s := range filtered {
+ item, err := p.tc.StatusToAPIStatus(ctx, s, requestingAccount)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status to api: %s", err))
+ }
+
+ if i == count-1 {
+ nextMaxIDValue = item.GetID()
+ }
+
+ if i == 0 {
+ prevMinIDValue = item.GetID()
+ }
+
+ items = append(items, item)
+ }
+
+ return util.PackagePageableResponse(util.PageableResponseParams{
+ Items: items,
+ Path: fmt.Sprintf("/api/v1/accounts/%s/statuses", targetAccountID),
+ NextMaxIDValue: nextMaxIDValue,
+ PrevMinIDValue: prevMinIDValue,
+ Limit: limit,
+ ExtraQueryParams: []string{
+ fmt.Sprintf("exclude_replies=%t", excludeReplies),
+ fmt.Sprintf("exclude_reblogs=%t", excludeReblogs),
+ fmt.Sprintf("pinned_only=%t", pinnedOnly),
+ fmt.Sprintf("only_media=%t", mediaOnly),
+ fmt.Sprintf("only_public=%t", publicOnly),
+ },
+ })
+}
+
+// WebStatusesGet 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.
+func (p *Processor) WebStatusesGet(ctx context.Context, targetAccountID string, maxID string) (*apimodel.PageableResponse, gtserror.WithCode) {
+ acct, err := p.db.GetAccountByID(ctx, targetAccountID)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ err := fmt.Errorf("account %s not found in the db, not getting web statuses for it", targetAccountID)
+ return nil, gtserror.NewErrorNotFound(err)
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ if acct.Domain != "" {
+ err := fmt.Errorf("account %s was not a local account, not getting web statuses for it", targetAccountID)
+ return nil, gtserror.NewErrorNotFound(err)
+ }
+
+ statuses, err := p.db.GetAccountWebStatuses(ctx, targetAccountID, 10, maxID)
+ if err != nil {
+ if err == db.ErrNoEntries {
+ return util.EmptyPageableResponse(), nil
+ }
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ count := len(statuses)
+
+ if count == 0 {
+ return util.EmptyPageableResponse(), nil
+ }
+
+ items := []interface{}{}
+ nextMaxIDValue := ""
+ prevMinIDValue := ""
+ for i, s := range statuses {
+ item, err := p.tc.StatusToAPIStatus(ctx, s, nil)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting status to api: %s", err))
+ }
+
+ if i == count-1 {
+ nextMaxIDValue = item.GetID()
+ }
+
+ if i == 0 {
+ prevMinIDValue = item.GetID()
+ }
+
+ items = append(items, item)
+ }
+
+ return util.PackagePageableResponse(util.PageableResponseParams{
+ Items: items,
+ Path: "/@" + acct.Username,
+ NextMaxIDValue: nextMaxIDValue,
+ PrevMinIDValue: prevMinIDValue,
+ ExtraQueryParams: []string{},
+ })
+}
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index e6867bfd3..cffbbb0c5 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -33,10 +33,12 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/text"
+ "github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/validate"
)
-func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, gtserror.WithCode) {
+// Update processes the update of an account with the given form.
+func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, gtserror.WithCode) {
if form.Discoverable != nil {
account.Discoverable = form.Discoverable
}
@@ -138,7 +140,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
if err := validate.Privacy(*form.Source.Privacy); err != nil {
return nil, gtserror.NewErrorBadRequest(err)
}
- privacy := p.tc.APIVisToVis(apimodel.Visibility(*form.Source.Privacy))
+ privacy := typeutils.APIVisToVis(apimodel.Visibility(*form.Source.Privacy))
account.Privacy = privacy
}
@@ -185,7 +187,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
// UpdateAvatar does the dirty work of checking the avatar part of an account update form,
// parsing and checking the image, and doing the necessary updates in the database for this to become
// the account's new avatar image.
-func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error) {
+func (p *Processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error) {
maxImageSize := config.GetMediaImageMaxSize()
if avatar.Size > int64(maxImageSize) {
return nil, fmt.Errorf("UpdateAvatar: avatar with size %d exceeded max image size of %d bytes", avatar.Size, maxImageSize)
@@ -213,7 +215,7 @@ func (p *processor) UpdateAvatar(ctx context.Context, avatar *multipart.FileHead
// UpdateHeader does the dirty work of checking the header part of an account update form,
// parsing and checking the image, and doing the necessary updates in the database for this to become
// the account's new header image.
-func (p *processor) UpdateHeader(ctx context.Context, header *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error) {
+func (p *Processor) UpdateHeader(ctx context.Context, header *multipart.FileHeader, description *string, accountID string) (*gtsmodel.MediaAttachment, error) {
maxImageSize := config.GetMediaImageMaxSize()
if header.Size > int64(maxImageSize) {
return nil, fmt.Errorf("UpdateHeader: header with size %d exceeded max image size of %d bytes", header.Size, maxImageSize)
--
cgit v1.2.3