2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-05-08 13:25:55 +01:00
|
|
|
|
2021-05-30 12:12:00 +01:00
|
|
|
package processing
|
2021-05-08 13:25:55 +01:00
|
|
|
|
|
|
|
import (
|
2023-03-01 18:26:53 +00:00
|
|
|
"context"
|
|
|
|
|
2021-10-31 14:46:23 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/email"
|
2021-05-08 13:25:55 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/federation"
|
2023-03-01 18:26:53 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
2023-02-22 15:05:26 +00:00
|
|
|
mm "github.com/superseriousbusiness/gotosocial/internal/media"
|
2021-08-31 14:59:12 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
2021-05-08 13:25:55 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
2021-07-05 12:23:03 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/admin"
|
2023-02-22 15:05:26 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/fedi"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/media"
|
2023-01-23 12:14:21 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/report"
|
2021-07-05 12:23:03 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
|
2023-02-22 15:05:26 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/stream"
|
2021-10-14 13:26:04 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/user"
|
2023-03-01 18:26:53 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/state"
|
2021-06-13 17:42:28 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
2021-05-08 13:25:55 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
2021-06-17 17:02:33 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
2021-05-08 13:25:55 +01:00
|
|
|
)
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
type Processor struct {
|
2021-06-13 17:42:28 +01:00
|
|
|
federator federation.Federator
|
|
|
|
tc typeutils.TypeConverter
|
|
|
|
oauthServer oauth.Server
|
2023-02-22 15:05:26 +00:00
|
|
|
mediaManager mm.Manager
|
2022-02-05 11:47:38 +00:00
|
|
|
statusTimelines timeline.Manager
|
2023-03-01 18:26:53 +00:00
|
|
|
state *state.State
|
2021-06-17 17:02:33 +01:00
|
|
|
filter visibility.Filter
|
2023-03-19 12:11:46 +00:00
|
|
|
emailSender email.Sender
|
2021-05-08 13:25:55 +01:00
|
|
|
|
2021-06-13 17:42:28 +01:00
|
|
|
/*
|
|
|
|
SUB-PROCESSORS
|
|
|
|
*/
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
account account.Processor
|
|
|
|
admin admin.Processor
|
|
|
|
fedi fedi.Processor
|
|
|
|
media media.Processor
|
|
|
|
report report.Processor
|
|
|
|
status status.Processor
|
|
|
|
stream stream.Processor
|
|
|
|
user user.Processor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Account() *account.Processor {
|
|
|
|
return &p.account
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Admin() *admin.Processor {
|
|
|
|
return &p.admin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Fedi() *fedi.Processor {
|
|
|
|
return &p.fedi
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Media() *media.Processor {
|
|
|
|
return &p.media
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Report() *report.Processor {
|
|
|
|
return &p.report
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Status() *status.Processor {
|
|
|
|
return &p.status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Stream() *stream.Processor {
|
|
|
|
return &p.stream
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) User() *user.Processor {
|
|
|
|
return &p.user
|
2021-05-08 13:25:55 +01:00
|
|
|
}
|
|
|
|
|
2021-10-31 14:46:23 +00:00
|
|
|
// NewProcessor returns a new Processor.
|
|
|
|
func NewProcessor(
|
|
|
|
tc typeutils.TypeConverter,
|
|
|
|
federator federation.Federator,
|
|
|
|
oauthServer oauth.Server,
|
2023-02-22 15:05:26 +00:00
|
|
|
mediaManager mm.Manager,
|
2023-03-01 18:26:53 +00:00
|
|
|
state *state.State,
|
2022-04-28 13:23:11 +01:00
|
|
|
emailSender email.Sender,
|
2023-02-22 15:05:26 +00:00
|
|
|
) *Processor {
|
2023-03-01 18:26:53 +00:00
|
|
|
parseMentionFunc := GetParseMentionFunc(state.DB, federator)
|
|
|
|
|
|
|
|
filter := visibility.NewFilter(state.DB)
|
|
|
|
|
|
|
|
processor := &Processor{
|
|
|
|
federator: federator,
|
|
|
|
tc: tc,
|
|
|
|
oauthServer: oauthServer,
|
|
|
|
mediaManager: mediaManager,
|
|
|
|
statusTimelines: timeline.NewManager(
|
|
|
|
StatusGrabFunction(state.DB),
|
|
|
|
StatusFilterFunction(state.DB, filter),
|
|
|
|
StatusPrepareFunction(state.DB, tc),
|
|
|
|
StatusSkipInsertFunction(),
|
|
|
|
),
|
2023-03-19 12:11:46 +00:00
|
|
|
state: state,
|
|
|
|
filter: filter,
|
|
|
|
emailSender: emailSender,
|
2021-06-13 17:42:28 +01:00
|
|
|
}
|
2021-05-08 13:25:55 +01:00
|
|
|
|
2023-03-01 18:26:53 +00:00
|
|
|
// sub processors
|
|
|
|
processor.account = account.New(state, tc, mediaManager, oauthServer, federator, parseMentionFunc)
|
2023-03-14 16:11:04 +00:00
|
|
|
processor.admin = admin.New(state, tc, mediaManager, federator.TransportController(), emailSender)
|
2023-03-01 18:26:53 +00:00
|
|
|
processor.fedi = fedi.New(state, tc, federator)
|
|
|
|
processor.media = media.New(state, tc, mediaManager, federator.TransportController())
|
|
|
|
processor.report = report.New(state, tc)
|
|
|
|
processor.status = status.New(state, tc, parseMentionFunc)
|
|
|
|
processor.stream = stream.New(state, oauthServer)
|
|
|
|
processor.user = user.New(state, emailSender)
|
|
|
|
|
|
|
|
return processor
|
|
|
|
}
|
2022-04-28 13:23:11 +01:00
|
|
|
|
2023-03-20 18:10:08 +00:00
|
|
|
func (p *Processor) EnqueueClientAPI(ctx context.Context, msgs ...messages.FromClientAPI) {
|
|
|
|
log.Trace(ctx, "enqueuing client API")
|
2023-03-01 18:26:53 +00:00
|
|
|
_ = p.state.Workers.ClientAPI.MustEnqueueCtx(ctx, func(ctx context.Context) {
|
2023-03-20 18:10:08 +00:00
|
|
|
for _, msg := range msgs {
|
|
|
|
if err := p.ProcessFromClientAPI(ctx, msg); err != nil {
|
|
|
|
log.WithContext(ctx).WithField("msg", msg).Errorf("error processing client API message: %v", err)
|
|
|
|
}
|
2023-03-01 18:26:53 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-04-28 13:23:11 +01:00
|
|
|
|
2023-03-20 18:10:08 +00:00
|
|
|
func (p *Processor) EnqueueFederator(ctx context.Context, msgs ...messages.FromFederator) {
|
|
|
|
log.Trace(ctx, "enqueuing federator")
|
2023-03-01 18:26:53 +00:00
|
|
|
_ = p.state.Workers.Federator.MustEnqueueCtx(ctx, func(ctx context.Context) {
|
2023-03-20 18:10:08 +00:00
|
|
|
for _, msg := range msgs {
|
|
|
|
if err := p.ProcessFromFederator(ctx, msg); err != nil {
|
|
|
|
log.WithContext(ctx).WithField("msg", msg).Errorf("error processing federator message: %v", err)
|
|
|
|
}
|
2023-03-01 18:26:53 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-11-22 18:38:10 +00:00
|
|
|
|
2023-03-01 18:26:53 +00:00
|
|
|
// Start starts the Processor.
|
|
|
|
func (p *Processor) Start() error {
|
|
|
|
return p.statusTimelines.Start()
|
2021-05-08 13:25:55 +01:00
|
|
|
}
|
|
|
|
|
2023-03-01 18:26:53 +00:00
|
|
|
// Stop stops the processor cleanly.
|
2023-02-22 15:05:26 +00:00
|
|
|
func (p *Processor) Stop() error {
|
2023-03-01 18:26:53 +00:00
|
|
|
return p.statusTimelines.Stop()
|
2021-05-08 13:25:55 +01:00
|
|
|
}
|