2021-08-25 16:34:33 +03:00
|
|
|
/*
|
|
|
|
GoToSocial
|
|
|
|
Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-06-13 19:42:28 +03:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
2021-08-25 16:34:33 +03:00
|
|
|
"context"
|
|
|
|
|
2021-06-13 19:42:28 +03:00
|
|
|
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2021-08-31 16:59:12 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
2021-07-26 21:25:54 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/text"
|
2021-06-13 19:42:28 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
2021-06-17 19:02:33 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
2021-06-13 19:42:28 +03: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 16:34:33 +03:00
|
|
|
Create(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// Delete processes the delete of a given status, returning the deleted status if the delete goes through.
|
2021-08-25 16:34:33 +03:00
|
|
|
Delete(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// Fave processes the faving of a given status, returning the updated status if the fave goes through.
|
2021-08-25 16:34:33 +03:00
|
|
|
Fave(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// Boost processes the boost/reblog of a given status, returning the newly-created boost if all is well.
|
2021-08-25 16:34:33 +03:00
|
|
|
Boost(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-21 16:56:00 +03:00
|
|
|
// Unboost processes the unboost/unreblog of a given status, returning the status if all is well.
|
2021-08-25 16:34:33 +03:00
|
|
|
Unboost(ctx context.Context, account *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// BoostedBy returns a slice of accounts that have boosted the given status, filtered according to privacy settings.
|
2021-08-25 16:34:33 +03:00
|
|
|
BoostedBy(ctx context.Context, account *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// FavedBy returns a slice of accounts that have liked the given status, filtered according to privacy settings.
|
2021-08-25 16:34:33 +03:00
|
|
|
FavedBy(ctx context.Context, account *gtsmodel.Account, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// Get gets the given status, taking account of privacy settings and blocks etc.
|
2021-08-25 16:34:33 +03:00
|
|
|
Get(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// Unfave processes the unfaving of a given status, returning the updated status if the fave goes through.
|
2021-08-25 16:34:33 +03:00
|
|
|
Unfave(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode)
|
2021-06-13 19:42:28 +03:00
|
|
|
// Context returns the context (previous and following posts) from the given status ID
|
2021-08-25 16:34:33 +03:00
|
|
|
Context(ctx context.Context, account *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode)
|
2021-08-11 17:54:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
PROCESSING UTILS
|
|
|
|
*/
|
|
|
|
|
2021-08-25 16:34:33 +03:00
|
|
|
ProcessVisibility(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountDefaultVis gtsmodel.Visibility, status *gtsmodel.Status) error
|
|
|
|
ProcessReplyToID(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, thisAccountID string, status *gtsmodel.Status) error
|
|
|
|
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 19:42:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type processor struct {
|
|
|
|
tc typeutils.TypeConverter
|
|
|
|
config *config.Config
|
|
|
|
db db.DB
|
2021-06-17 19:02:33 +03:00
|
|
|
filter visibility.Filter
|
2021-07-26 21:25:54 +03:00
|
|
|
formatter text.Formatter
|
2021-08-31 16:59:12 +03:00
|
|
|
fromClientAPI chan messages.FromClientAPI
|
2021-06-13 19:42:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a new status processor.
|
2021-10-11 15:37:33 +03:00
|
|
|
func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, fromClientAPI chan messages.FromClientAPI) Processor {
|
2021-06-13 19:42:28 +03:00
|
|
|
return &processor{
|
|
|
|
tc: tc,
|
|
|
|
config: config,
|
|
|
|
db: db,
|
2021-10-11 15:37:33 +03:00
|
|
|
filter: visibility.NewFilter(db),
|
|
|
|
formatter: text.NewFormatter(config, db),
|
2021-06-13 19:42:28 +03:00
|
|
|
fromClientAPI: fromClientAPI,
|
|
|
|
}
|
|
|
|
}
|