2021-08-25 13:34:33 +00:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2021-12-20 17:42:19 +00:00
|
|
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
2021-08-25 13:34:33 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-06-13 16:42:28 +00:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
2021-08-25 13:34:33 +00:00
|
|
|
"context"
|
|
|
|
|
2021-06-13 16:42:28 +00:00
|
|
|
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
2022-05-15 09:16:43 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
2021-06-13 16:42:28 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2021-08-31 13:59:12 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
2021-07-26 18:25:54 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/text"
|
2021-06-13 16:42:28 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
2021-06-17 16:02:33 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
2021-06-13 16:42:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Processor wraps a bunch of functions for processing statuses.
|
|
|
|
type Processor interface {
|
|
|
|
// Create processes the given form to create a new status, returning the api model representation of that status if it's OK.
|
2021-08-25 13:34:33 +00:00
|
|
|
Create(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// Delete processes the delete of a given status, returning the deleted status if the delete goes through.
|
2021-08-25 13:34:33 +00:00
|
|
|
Delete(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// Fave processes the faving of a given status, returning the updated status if the fave goes through.
|
2021-08-25 13:34:33 +00:00
|
|
|
Fave(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// Boost processes the boost/reblog of a given status, returning the newly-created boost if all is well.
|
2021-08-25 13:34:33 +00:00
|
|
|
Boost(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-21 13:56:00 +00:00
|
|
|
// Unboost processes the unboost/unreblog of a given status, returning the status if all is well.
|
2021-08-25 13:34:33 +00:00
|
|
|
Unboost(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// BoostedBy returns a slice of accounts that have boosted the given status, filtered according to privacy settings.
|
2021-08-25 13:34:33 +00:00
|
|
|
BoostedBy(ctx context.Context, account *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// FavedBy returns a slice of accounts that have liked the given status, filtered according to privacy settings.
|
2021-08-25 13:34:33 +00:00
|
|
|
FavedBy(ctx context.Context, account *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// Get gets the given status, taking account of privacy settings and blocks etc.
|
2021-08-25 13:34:33 +00:00
|
|
|
Get(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// Unfave processes the unfaving of a given status, returning the updated status if the fave goes through.
|
2021-08-25 13:34:33 +00:00
|
|
|
Unfave(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 16:42:28 +00:00
|
|
|
// Context returns the context (previous and following posts) from the given status ID
|
2021-08-25 13:34:33 +00:00
|
|
|
Context(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode)
|
2021-08-11 14:54:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
PROCESSING UTILS
|
|
|
|
*/
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
ProcessVisibility(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountDefaultVis gtsmodel.Visibility, status *gtsmodel.Status) error
|
2022-06-08 18:38:03 +00:00
|
|
|
ProcessReplyToID(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, thisAccountID string, status *gtsmodel.Status) gtserror.WithCode
|
2021-08-25 13:34:33 +00:00
|
|
|
ProcessMediaIDs(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, thisAccountID string, status *gtsmodel.Status) error
|
|
|
|
ProcessLanguage(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountDefaultLanguage string, status *gtsmodel.Status) error
|
|
|
|
ProcessMentions(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error
|
|
|
|
ProcessTags(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error
|
|
|
|
ProcessEmojis(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error
|
|
|
|
ProcessContent(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountID string, status *gtsmodel.Status) error
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type processor struct {
|
2022-04-28 12:23:11 +00:00
|
|
|
tc typeutils.TypeConverter
|
|
|
|
db db.DB
|
|
|
|
filter visibility.Filter
|
|
|
|
formatter text.Formatter
|
2022-05-15 09:16:43 +00:00
|
|
|
clientWorker *concurrency.WorkerPool[messages.FromClientAPI]
|
2022-04-28 12:23:11 +00:00
|
|
|
parseMention gtsmodel.ParseMentionFunc
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a new status processor.
|
2022-05-15 09:16:43 +00:00
|
|
|
func New(db db.DB, tc typeutils.TypeConverter, clientWorker *concurrency.WorkerPool[messages.FromClientAPI], parseMention gtsmodel.ParseMentionFunc) Processor {
|
2021-06-13 16:42:28 +00:00
|
|
|
return &processor{
|
2022-04-28 12:23:11 +00:00
|
|
|
tc: tc,
|
|
|
|
db: db,
|
|
|
|
filter: visibility.NewFilter(db),
|
|
|
|
formatter: text.NewFormatter(db),
|
|
|
|
clientWorker: clientWorker,
|
|
|
|
parseMention: parseMention,
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
|
|
|
}
|