summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/account.go5
-rw-r--r--internal/processing/account/createblock.go20
-rw-r--r--internal/processing/account/createfollow.go8
-rw-r--r--internal/processing/account/delete.go19
-rw-r--r--internal/processing/account/removeblock.go8
-rw-r--r--internal/processing/account/removefollow.go14
-rw-r--r--internal/processing/account/update.go18
-rw-r--r--internal/processing/admin/admin.go5
-rw-r--r--internal/processing/admin/createdomainblock.go8
-rw-r--r--internal/processing/app.go4
-rw-r--r--internal/processing/followrequest.go9
-rw-r--r--internal/processing/fromclientapi.go42
-rw-r--r--internal/processing/fromfederator.go32
-rw-r--r--internal/processing/instance.go12
-rw-r--r--internal/processing/processor.go12
-rw-r--r--internal/processing/status/boost.go14
-rw-r--r--internal/processing/status/create.go10
-rw-r--r--internal/processing/status/delete.go8
-rw-r--r--internal/processing/status/fave.go14
-rw-r--r--internal/processing/status/status.go5
-rw-r--r--internal/processing/status/status_test.go8
-rw-r--r--internal/processing/status/unboost.go8
-rw-r--r--internal/processing/status/unfave.go8
-rw-r--r--internal/processing/status/util.go9
-rw-r--r--internal/processing/status/util_test.go3
-rw-r--r--internal/processing/streaming.go3
-rw-r--r--internal/processing/streaming/openstream.go19
-rw-r--r--internal/processing/streaming/streamdelete.go16
-rw-r--r--internal/processing/streaming/streaming.go3
-rw-r--r--internal/processing/streaming/streamnotification.go17
-rw-r--r--internal/processing/streaming/streamstatus.go17
31 files changed, 205 insertions, 173 deletions
diff --git a/internal/processing/account/account.go b/internal/processing/account/account.go
index 81701fd7c..71b876d3b 100644
--- a/internal/processing/account/account.go
+++ b/internal/processing/account/account.go
@@ -30,6 +30,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/visibility"
@@ -79,7 +80,7 @@ type processor struct {
tc typeutils.TypeConverter
config *config.Config
mediaHandler media.Handler
- fromClientAPI chan gtsmodel.FromClientAPI
+ fromClientAPI chan messages.FromClientAPI
oauthServer oauth.Server
filter visibility.Filter
db db.DB
@@ -88,7 +89,7 @@ type processor struct {
}
// New returns a new account processor.
-func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, oauthServer oauth.Server, fromClientAPI chan gtsmodel.FromClientAPI, federator federation.Federator, config *config.Config, log *logrus.Logger) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, oauthServer oauth.Server, fromClientAPI chan messages.FromClientAPI, federator federation.Federator, config *config.Config, log *logrus.Logger) Processor {
return &processor{
tc: tc,
config: config,
diff --git a/internal/processing/account/createblock.go b/internal/processing/account/createblock.go
index 06f82b37d..347f19bee 100644
--- a/internal/processing/account/createblock.go
+++ b/internal/processing/account/createblock.go
@@ -22,11 +22,13 @@ 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/util"
)
@@ -111,9 +113,9 @@ func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel
// follow request status changed so send the UNDO activity to the channel for async processing
if frChanged {
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsFollow,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
GTSModel: &gtsmodel.Follow{
AccountID: requestingAccount.ID,
TargetAccountID: targetAccountID,
@@ -126,9 +128,9 @@ func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel
// follow status changed so send the UNDO activity to the channel for async processing
if fChanged {
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsFollow,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
GTSModel: &gtsmodel.Follow{
AccountID: requestingAccount.ID,
TargetAccountID: targetAccountID,
@@ -140,9 +142,9 @@ func (p *processor) BlockCreate(ctx context.Context, requestingAccount *gtsmodel
}
// handle the rest of the block process asynchronously
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsBlock,
- APActivityType: gtsmodel.ActivityStreamsCreate,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityBlock,
+ APActivityType: ap.ActivityCreate,
GTSModel: block,
OriginAccount: requestingAccount,
TargetAccount: targetAccount,
diff --git a/internal/processing/account/createfollow.go b/internal/processing/account/createfollow.go
index a7767afea..d3ca386ed 100644
--- a/internal/processing/account/createfollow.go
+++ b/internal/processing/account/createfollow.go
@@ -22,11 +22,13 @@ 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/util"
)
@@ -99,9 +101,9 @@ func (p *processor) FollowCreate(ctx context.Context, requestingAccount *gtsmode
}
// otherwise we leave the follow request as it is and we handle the rest of the process asynchronously
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsFollow,
- APActivityType: gtsmodel.ActivityStreamsCreate,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityCreate,
GTSModel: fr,
OriginAccount: requestingAccount,
TargetAccount: targetAcct,
diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go
index d97af4d2e..5de706045 100644
--- a/internal/processing/account/delete.go
+++ b/internal/processing/account/delete.go
@@ -23,9 +23,10 @@ import (
"time"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
)
// Delete handles the complete deletion of an account.
@@ -64,12 +65,12 @@ func (p *processor) Delete(ctx context.Context, account *gtsmodel.Account, origi
u := &gtsmodel.User{}
if err := p.db.GetWhere(ctx, []db.Where{{Key: "account_id", Value: account.ID}}, u); err == nil {
// we got one! select all tokens with the user's ID
- tokens := []*oauth.Token{}
+ tokens := []*gtsmodel.Token{}
if err := p.db.GetWhere(ctx, []db.Where{{Key: "user_id", Value: u.ID}}, &tokens); err == nil {
// we have some tokens to delete
for _, t := range tokens {
// delete client(s) associated with this token
- if err := p.db.DeleteByID(ctx, t.ClientID, &oauth.Client{}); err != nil {
+ if err := p.db.DeleteByID(ctx, t.ClientID, &gtsmodel.Client{}); err != nil {
l.Errorf("error deleting oauth client: %s", err)
}
// delete application(s) associated with this token
@@ -150,9 +151,9 @@ selectStatusesLoop:
// pass the status delete through the client api channel for processing
s.Account = account
l.Debug("putting status in the client api channel")
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsNote,
- APActivityType: gtsmodel.ActivityStreamsDelete,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ObjectNote,
+ APActivityType: ap.ActivityDelete,
GTSModel: s,
OriginAccount: account,
TargetAccount: account,
@@ -186,9 +187,9 @@ selectStatusesLoop:
}
l.Debug("putting boost undo in the client api channel")
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsAnnounce,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityAnnounce,
+ APActivityType: ap.ActivityUndo,
GTSModel: s,
OriginAccount: b.Account,
TargetAccount: account,
diff --git a/internal/processing/account/removeblock.go b/internal/processing/account/removeblock.go
index 7e3d78076..06bafb3a4 100644
--- a/internal/processing/account/removeblock.go
+++ b/internal/processing/account/removeblock.go
@@ -22,10 +22,12 @@ 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) BlockRemove(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.Relationship, gtserror.WithCode) {
@@ -52,9 +54,9 @@ func (p *processor) BlockRemove(ctx context.Context, requestingAccount *gtsmodel
// block status changed so send the UNDO activity to the channel for async processing
if blockChanged {
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsBlock,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityBlock,
+ APActivityType: ap.ActivityUndo,
GTSModel: block,
OriginAccount: requestingAccount,
TargetAccount: targetAccount,
diff --git a/internal/processing/account/removefollow.go b/internal/processing/account/removefollow.go
index 6186c550f..9791f2e54 100644
--- a/internal/processing/account/removefollow.go
+++ b/internal/processing/account/removefollow.go
@@ -22,10 +22,12 @@ 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) {
@@ -78,9 +80,9 @@ func (p *processor) FollowRemove(ctx context.Context, requestingAccount *gtsmode
// follow request status changed so send the UNDO activity to the channel for async processing
if frChanged {
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsFollow,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
GTSModel: &gtsmodel.Follow{
AccountID: requestingAccount.ID,
TargetAccountID: targetAccountID,
@@ -93,9 +95,9 @@ func (p *processor) FollowRemove(ctx context.Context, requestingAccount *gtsmode
// follow status changed so send the UNDO activity to the channel for async processing
if fChanged {
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsFollow,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
GTSModel: &gtsmodel.Follow{
AccountID: requestingAccount.ID,
TargetAccountID: targetAccountID,
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 99ccbf5a0..c0fee8e25 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -26,11 +26,13 @@ import (
"io"
"mime/multipart"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/text"
- "github.com/superseriousbusiness/gotosocial/internal/util"
+ "github.com/superseriousbusiness/gotosocial/internal/validate"
)
func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, error) {
@@ -49,7 +51,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
}
if form.DisplayName != nil {
- if err := util.ValidateDisplayName(*form.DisplayName); err != nil {
+ if err := validate.DisplayName(*form.DisplayName); err != nil {
return nil, err
}
displayName := text.RemoveHTML(*form.DisplayName) // no html allowed in display name
@@ -59,7 +61,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
}
if form.Note != nil {
- if err := util.ValidateNote(*form.Note); err != nil {
+ if err := validate.Note(*form.Note); err != nil {
return nil, err
}
note := text.SanitizeHTML(*form.Note) // html OK in note but sanitize it
@@ -92,7 +94,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
if form.Source != nil {
if form.Source.Language != nil {
- if err := util.ValidateLanguage(*form.Source.Language); err != nil {
+ if err := validate.Language(*form.Source.Language); err != nil {
return nil, err
}
if err := p.db.UpdateOneByID(ctx, account.ID, "language", *form.Source.Language, &gtsmodel.Account{}); err != nil {
@@ -107,7 +109,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
}
if form.Source.Privacy != nil {
- if err := util.ValidatePrivacy(*form.Source.Privacy); err != nil {
+ if err := validate.Privacy(*form.Source.Privacy); err != nil {
return nil, err
}
if err := p.db.UpdateOneByID(ctx, account.ID, "privacy", *form.Source.Privacy, &gtsmodel.Account{}); err != nil {
@@ -122,9 +124,9 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
return nil, fmt.Errorf("could not fetch updated account %s: %s", account.ID, err)
}
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsProfile,
- APActivityType: gtsmodel.ActivityStreamsUpdate,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ObjectProfile,
+ APActivityType: ap.ActivityUpdate,
GTSModel: updatedAccount,
OriginAccount: updatedAccount,
}
diff --git a/internal/processing/admin/admin.go b/internal/processing/admin/admin.go
index de288811b..92f69f06b 100644
--- a/internal/processing/admin/admin.go
+++ b/internal/processing/admin/admin.go
@@ -29,6 +29,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -46,13 +47,13 @@ type processor struct {
tc typeutils.TypeConverter
config *config.Config
mediaHandler media.Handler
- fromClientAPI chan gtsmodel.FromClientAPI
+ fromClientAPI chan messages.FromClientAPI
db db.DB
log *logrus.Logger
}
// New returns a new admin processor.
-func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, fromClientAPI chan gtsmodel.FromClientAPI, config *config.Config, log *logrus.Logger) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, fromClientAPI chan messages.FromClientAPI, config *config.Config, log *logrus.Logger) Processor {
return &processor{
tc: tc,
config: config,
diff --git a/internal/processing/admin/createdomainblock.go b/internal/processing/admin/createdomainblock.go
index a34c03a44..9c4ff780f 100644
--- a/internal/processing/admin/createdomainblock.go
+++ b/internal/processing/admin/createdomainblock.go
@@ -24,11 +24,13 @@ import (
"time"
"github.com/sirupsen/logrus"
+ "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/text"
)
@@ -140,9 +142,9 @@ selectAccountsLoop:
l.Debugf("putting delete for account %s in the clientAPI channel", a.Username)
// pass the account delete through the client api channel for processing
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsPerson,
- APActivityType: gtsmodel.ActivityStreamsDelete,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActorPerson,
+ APActivityType: ap.ActivityDelete,
GTSModel: block,
OriginAccount: account,
TargetAccount: a,
diff --git a/internal/processing/app.go b/internal/processing/app.go
index 4f805572b..d6ded6efa 100644
--- a/internal/processing/app.go
+++ b/internal/processing/app.go
@@ -43,7 +43,6 @@ func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *api
return nil, err
}
clientSecret := uuid.NewString()
- vapidKey := uuid.NewString()
appID, err := id.NewRandomULID()
if err != nil {
@@ -59,7 +58,6 @@ func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *api
ClientID: clientID,
ClientSecret: clientSecret,
Scopes: scopes,
- VapidKey: vapidKey,
}
// chuck it in the db
@@ -68,7 +66,7 @@ func (p *processor) AppCreate(ctx context.Context, authed *oauth.Auth, form *api
}
// now we need to model an oauth client from the application that the oauth library can use
- oc := &oauth.Client{
+ oc := &gtsmodel.Client{
ID: clientID,
Secret: clientSecret,
Domain: form.RedirectURIs,
diff --git a/internal/processing/followrequest.go b/internal/processing/followrequest.go
index 3dd6432e2..b313e42f8 100644
--- a/internal/processing/followrequest.go
+++ b/internal/processing/followrequest.go
@@ -21,10 +21,11 @@ package processing
import (
"context"
+ "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"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
@@ -77,9 +78,9 @@ func (p *processor) FollowRequestAccept(ctx context.Context, auth *oauth.Auth, a
follow.TargetAccount = followTargetAccount
}
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsFollow,
- APActivityType: gtsmodel.ActivityStreamsAccept,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityAccept,
GTSModel: follow,
OriginAccount: follow.Account,
TargetAccount: follow.TargetAccount,
diff --git a/internal/processing/fromclientapi.go b/internal/processing/fromclientapi.go
index a6ea0068b..97c6cc8b2 100644
--- a/internal/processing/fromclientapi.go
+++ b/internal/processing/fromclientapi.go
@@ -25,16 +25,18 @@ import (
"net/url"
"github.com/go-fed/activity/streams"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
)
-func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel.FromClientAPI) error {
+func (p *processor) processFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
switch clientMsg.APActivityType {
- case gtsmodel.ActivityStreamsCreate:
+ case ap.ActivityCreate:
// CREATE
switch clientMsg.APObjectType {
- case gtsmodel.ActivityStreamsNote:
+ case ap.ObjectNote:
// CREATE NOTE
status, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
@@ -49,10 +51,10 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
return err
}
- if status.VisibilityAdvanced != nil && status.VisibilityAdvanced.Federated {
+ if status.VisibilityAdvanced.Federated {
return p.federateStatus(ctx, status)
}
- case gtsmodel.ActivityStreamsFollow:
+ case ap.ActivityFollow:
// CREATE FOLLOW REQUEST
followRequest, ok := clientMsg.GTSModel.(*gtsmodel.FollowRequest)
if !ok {
@@ -64,7 +66,7 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
}
return p.federateFollow(ctx, followRequest, clientMsg.OriginAccount, clientMsg.TargetAccount)
- case gtsmodel.ActivityStreamsLike:
+ case ap.ActivityLike:
// CREATE LIKE/FAVE
fave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
if !ok {
@@ -76,7 +78,7 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
}
return p.federateFave(ctx, fave, clientMsg.OriginAccount, clientMsg.TargetAccount)
- case gtsmodel.ActivityStreamsAnnounce:
+ case ap.ActivityAnnounce:
// CREATE BOOST/ANNOUNCE
boostWrapperStatus, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
@@ -92,7 +94,7 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
}
return p.federateAnnounce(ctx, boostWrapperStatus, clientMsg.OriginAccount, clientMsg.TargetAccount)
- case gtsmodel.ActivityStreamsBlock:
+ case ap.ActivityBlock:
// CREATE BLOCK
block, ok := clientMsg.GTSModel.(*gtsmodel.Block)
if !ok {
@@ -112,10 +114,10 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
return p.federateBlock(ctx, block)
}
- case gtsmodel.ActivityStreamsUpdate:
+ case ap.ActivityUpdate:
// UPDATE
switch clientMsg.APObjectType {
- case gtsmodel.ActivityStreamsProfile, gtsmodel.ActivityStreamsPerson:
+ case ap.ObjectProfile, ap.ActorPerson:
// UPDATE ACCOUNT/PROFILE
account, ok := clientMsg.GTSModel.(*gtsmodel.Account)
if !ok {
@@ -124,10 +126,10 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
return p.federateAccountUpdate(ctx, account, clientMsg.OriginAccount)
}
- case gtsmodel.ActivityStreamsAccept:
+ case ap.ActivityAccept:
// ACCEPT
switch clientMsg.APObjectType {
- case gtsmodel.ActivityStreamsFollow:
+ case ap.ActivityFollow:
// ACCEPT FOLLOW
follow, ok := clientMsg.GTSModel.(*gtsmodel.Follow)
if !ok {
@@ -140,31 +142,31 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
return p.federateAcceptFollowRequest(ctx, follow, clientMsg.OriginAccount, clientMsg.TargetAccount)
}
- case gtsmodel.ActivityStreamsUndo:
+ case ap.ActivityUndo:
// UNDO
switch clientMsg.APObjectType {
- case gtsmodel.ActivityStreamsFollow:
+ case ap.ActivityFollow:
// UNDO FOLLOW
follow, ok := clientMsg.GTSModel.(*gtsmodel.Follow)
if !ok {
return errors.New("undo was not parseable as *gtsmodel.Follow")
}
return p.federateUnfollow(ctx, follow, clientMsg.OriginAccount, clientMsg.TargetAccount)
- case gtsmodel.ActivityStreamsBlock:
+ case ap.ActivityBlock:
// UNDO BLOCK
block, ok := clientMsg.GTSModel.(*gtsmodel.Block)
if !ok {
return errors.New("undo was not parseable as *gtsmodel.Block")
}
return p.federateUnblock(ctx, block)
- case gtsmodel.ActivityStreamsLike:
+ case ap.ActivityLike:
// UNDO LIKE/FAVE
fave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
if !ok {
return errors.New("undo was not parseable as *gtsmodel.StatusFave")
}
return p.federateUnfave(ctx, fave, clientMsg.OriginAccount, clientMsg.TargetAccount)
- case gtsmodel.ActivityStreamsAnnounce:
+ case ap.ActivityAnnounce:
// UNDO ANNOUNCE/BOOST
boost, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
@@ -177,10 +179,10 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
return p.federateUnannounce(ctx, boost, clientMsg.OriginAccount, clientMsg.TargetAccount)
}
- case gtsmodel.ActivityStreamsDelete:
+ case ap.ActivityDelete:
// DELETE
switch clientMsg.APObjectType {
- case gtsmodel.ActivityStreamsNote:
+ case ap.ObjectNote:
// DELETE STATUS/NOTE
statusToDelete, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
@@ -216,7 +218,7 @@ func (p *processor) processFromClientAPI(ctx context.Context, clientMsg gtsmodel
}
return p.federateStatusDelete(ctx, statusToDelete)
- case gtsmodel.ActivityStreamsProfile, gtsmodel.ActivityStreamsPerson:
+ case ap.ObjectProfile, ap.ActorPerson:
// DELETE ACCOUNT/PROFILE
// the origin of the delete could be either a domain block, or an action by another (or this) account
diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go
index cb0999cf9..d2e949cef 100644
--- a/internal/processing/fromfederator.go
+++ b/internal/processing/fromfederator.go
@@ -25,12 +25,14 @@ import (
"net/url"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
)
-func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmodel.FromFederator) error {
+func (p *processor) processFromFederator(ctx context.Context, federatorMsg messages.FromFederator) error {
l := p.log.WithFields(logrus.Fields{
"func": "processFromFederator",
"federatorMsg": fmt.Sprintf("%+v", federatorMsg),
@@ -39,10 +41,10 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
l.Trace("entering function PROCESS FROM FEDERATOR")
switch federatorMsg.APActivityType {
- case gtsmodel.ActivityStreamsCreate:
+ case ap.ActivityCreate:
// CREATE
switch federatorMsg.APObjectType {
- case gtsmodel.ActivityStreamsNote:
+ case ap.ObjectNote:
// CREATE A STATUS
incomingStatus, ok := federatorMsg.GTSModel.(*gtsmodel.Status)
if !ok {
@@ -61,10 +63,10 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
if err := p.notifyStatus(ctx, status); err != nil {
return err
}
- case gtsmodel.ActivityStreamsProfile:
+ case ap.ObjectProfile:
// CREATE AN ACCOUNT
// nothing to do here
- case gtsmodel.ActivityStreamsLike:
+ case ap.ActivityLike:
// CREATE A FAVE
incomingFave, ok := federatorMsg.GTSModel.(*gtsmodel.StatusFave)
if !ok {
@@ -74,7 +76,7 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
if err := p.notifyFave(ctx, incomingFave, federatorMsg.ReceivingAccount); err != nil {
return err
}
- case gtsmodel.ActivityStreamsFollow:
+ case ap.ActivityFollow:
// CREATE A FOLLOW REQUEST
incomingFollowRequest, ok := federatorMsg.GTSModel.(*gtsmodel.FollowRequest)
if !ok {
@@ -84,7 +86,7 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
if err := p.notifyFollowRequest(ctx, incomingFollowRequest, federatorMsg.ReceivingAccount); err != nil {
return err
}
- case gtsmodel.ActivityStreamsAnnounce:
+ case ap.ActivityAnnounce:
// CREATE AN ANNOUNCE
incomingAnnounce, ok := federatorMsg.GTSModel.(*gtsmodel.Status)
if !ok {
@@ -114,7 +116,7 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
if err := p.notifyAnnounce(ctx, incomingAnnounce); err != nil {
return err
}
- case gtsmodel.ActivityStreamsBlock:
+ case ap.ActivityBlock:
// CREATE A BLOCK
block, ok := federatorMsg.GTSModel.(*gtsmodel.Block)
if !ok {
@@ -131,10 +133,10 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
// TODO: same with notifications
// TODO: same with bookmarks
}
- case gtsmodel.ActivityStreamsUpdate:
+ case ap.ActivityUpdate:
// UPDATE
switch federatorMsg.APObjectType {
- case gtsmodel.ActivityStreamsProfile:
+ case ap.ObjectProfile:
// UPDATE AN ACCOUNT
incomingAccount, ok := federatorMsg.GTSModel.(*gtsmodel.Account)
if !ok {
@@ -150,10 +152,10 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
return fmt.Errorf("error dereferencing account from federator: %s", err)
}
}
- case gtsmodel.ActivityStreamsDelete:
+ case ap.ActivityDelete:
// DELETE
switch federatorMsg.APObjectType {
- case gtsmodel.ActivityStreamsNote:
+ case ap.ObjectNote:
// DELETE A STATUS
// TODO: handle side effects of status deletion here:
// 1. delete all media associated with status
@@ -185,14 +187,14 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg gtsmo
// remove this status from any and all timelines
return p.deleteStatusFromTimelines(ctx, statusToDelete)
- case gtsmodel.ActivityStreamsProfile:
+ case ap.ObjectProfile:
// DELETE A PROFILE/ACCOUNT
// TODO: handle side effects of account deletion here: delete all objects, statuses, media etc associated with account
}
- case gtsmodel.ActivityStreamsAccept:
+ case ap.ActivityAccept:
// ACCEPT
switch federatorMsg.APObjectType {
- case gtsmodel.ActivityStreamsFollow:
+ case ap.ActivityFollow:
// ACCEPT A FOLLOW
follow, ok := federatorMsg.GTSModel.(*gtsmodel.Follow)
if !ok {
diff --git a/internal/processing/instance.go b/internal/processing/instance.go
index ced798c2e..e74d3077a 100644
--- a/internal/processing/instance.go
+++ b/internal/processing/instance.go
@@ -27,7 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/text"
- "github.com/superseriousbusiness/gotosocial/internal/util"
+ "github.com/superseriousbusiness/gotosocial/internal/validate"
)
func (p *processor) InstanceGet(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode) {
@@ -59,7 +59,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
// validate & update site title if it's set on the form
if form.Title != nil {
- if err := util.ValidateSiteTitle(*form.Title); err != nil {
+ if err := validate.SiteTitle(*form.Title); err != nil {
return nil, gtserror.NewErrorBadRequest(err, fmt.Sprintf("site title invalid: %s", err))
}
i.Title = text.RemoveHTML(*form.Title) // don't allow html in site title
@@ -101,7 +101,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
// validate & update site contact email if it's set on the form
if form.ContactEmail != nil {
- if err := util.ValidateEmail(*form.ContactEmail); err != nil {
+ if err := validate.Email(*form.ContactEmail); err != nil {
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
i.ContactEmail = *form.ContactEmail
@@ -109,7 +109,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
// validate & update site short description if it's set on the form
if form.ShortDescription != nil {
- if err := util.ValidateSiteShortDescription(*form.ShortDescription); err != nil {
+ if err := validate.SiteShortDescription(*form.ShortDescription); err != nil {
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
i.ShortDescription = text.SanitizeHTML(*form.ShortDescription) // html is OK in site description, but we should sanitize it
@@ -117,7 +117,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
// validate & update site description if it's set on the form
if form.Description != nil {
- if err := util.ValidateSiteDescription(*form.Description); err != nil {
+ if err := validate.SiteDescription(*form.Description); err != nil {
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
i.Description = text.SanitizeHTML(*form.Description) // html is OK in site description, but we should sanitize it
@@ -125,7 +125,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
// validate & update site terms if it's set on the form
if form.Terms != nil {
- if err := util.ValidateSiteTerms(*form.Terms); err != nil {
+ if err := validate.SiteTerms(*form.Terms); err != nil {
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
i.Terms = text.SanitizeHTML(*form.Terms) // html is OK in site terms, but we should sanitize it
diff --git a/internal/processing/processor.go b/internal/processing/processor.go
index 8df464ce0..38076123f 100644
--- a/internal/processing/processor.go
+++ b/internal/processing/processor.go
@@ -32,12 +32,14 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
"github.com/superseriousbusiness/gotosocial/internal/processing/admin"
mediaProcessor "github.com/superseriousbusiness/gotosocial/internal/processing/media"
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
"github.com/superseriousbusiness/gotosocial/internal/processing/streaming"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
"github.com/superseriousbusiness/gotosocial/internal/timeline"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/visibility"
@@ -165,7 +167,7 @@ type Processor interface {
// AuthorizeStreamingRequest returns a gotosocial account in exchange for an access token, or an error if the given token is not valid.
AuthorizeStreamingRequest(ctx context.Context, accessToken string) (*gtsmodel.Account, error)
// OpenStreamForAccount opens a new stream for the given account, with the given stream type.
- OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*gtsmodel.Stream, gtserror.WithCode)
+ OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode)
/*
FEDERATION API-FACING PROCESSING FUNCTIONS
@@ -219,8 +221,8 @@ type Processor interface {
// processor just implements the Processor interface
type processor struct {
- fromClientAPI chan gtsmodel.FromClientAPI
- fromFederator chan gtsmodel.FromFederator
+ fromClientAPI chan messages.FromClientAPI
+ fromFederator chan messages.FromFederator
federator federation.Federator
stop chan interface{}
log *logrus.Logger
@@ -247,8 +249,8 @@ type processor struct {
// NewProcessor returns a new Processor that uses the given federator and logger
func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage blob.Storage, timelineManager timeline.Manager, db db.DB, log *logrus.Logger) Processor {
- fromClientAPI := make(chan gtsmodel.FromClientAPI, 1000)
- fromFederator := make(chan gtsmodel.FromFederator, 1000)
+ fromClientAPI := make(chan messages.FromClientAPI, 1000)
+ fromFederator := make(chan messages.FromFederator, 1000)
statusProcessor := status.New(db, tc, config, fromClientAPI, log)
streamingProcessor := streaming.New(db, tc, oauthServer, config, log)
diff --git a/internal/processing/status/boost.go b/internal/processing/status/boost.go
index 948d57a48..d6c4ada41 100644
--- a/internal/processing/status/boost.go
+++ b/internal/processing/status/boost.go
@@ -23,9 +23,11 @@ import (
"errors"
"fmt"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
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/messages"
)
func (p *processor) Boost(ctx context.Context, requestingAccount *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
@@ -44,10 +46,8 @@ func (p *processor) Boost(ctx context.Context, requestingAccount *gtsmodel.Accou
if !visible {
return nil, gtserror.NewErrorNotFound(errors.New("status is not visible"))
}
- if targetStatus.VisibilityAdvanced != nil {
- if !targetStatus.VisibilityAdvanced.Boostable {
- return nil, gtserror.NewErrorForbidden(errors.New("status is not boostable"))
- }
+ if !targetStatus.VisibilityAdvanced.Boostable {
+ return nil, gtserror.NewErrorForbidden(errors.New("status is not boostable"))
}
// it's visible! it's boostable! so let's boost the FUCK out of it
@@ -65,9 +65,9 @@ func (p *processor) Boost(ctx context.Context, requestingAccount *gtsmodel.Accou
}
// send it back to the processor for async processing
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsAnnounce,
- APActivityType: gtsmodel.ActivityStreamsCreate,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityAnnounce,
+ APActivityType: ap.ActivityCreate,
GTSModel: boostWrapperStatus,
OriginAccount: requestingAccount,
TargetAccount: targetStatus.Account,
diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go
index 2e0b30ad8..a87dbc7fe 100644
--- a/internal/processing/status/create.go
+++ b/internal/processing/status/create.go
@@ -23,10 +23,12 @@ import (
"fmt"
"time"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
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/id"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/text"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -50,7 +52,7 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, appli
AccountID: account.ID,
AccountURI: account.URI,
ContentWarning: text.RemoveHTML(form.SpoilerText),
- ActivityStreamsType: gtsmodel.ActivityStreamsNote,
+ ActivityStreamsType: ap.ObjectNote,
Sensitive: form.Sensitive,
Language: form.Language,
CreatedWithApplicationID: application.ID,
@@ -95,9 +97,9 @@ func (p *processor) Create(ctx context.Context, account *gtsmodel.Account, appli
}
// send it back to the processor for async processing
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsNote,
- APActivityType: gtsmodel.ActivityStreamsCreate,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ObjectNote,
+ APActivityType: ap.ActivityCreate,
GTSModel: newStatus,
OriginAccount: account,
}
diff --git a/internal/processing/status/delete.go b/internal/processing/status/delete.go
index daa7a934f..dfb2c3626 100644
--- a/internal/processing/status/delete.go
+++ b/internal/processing/status/delete.go
@@ -23,9 +23,11 @@ import (
"errors"
"fmt"
+ "github.com/superseriousbusiness/gotosocial/internal/ap"
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/messages"
)
func (p *processor) Delete(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
@@ -51,9 +53,9 @@ func (p *processor) Delete(ctx context.Context, requestingAccount *gtsmodel.Acco
}
// send it back to the processor for async processing
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsNote,
- APActivityType: gtsmodel.ActivityStreamsDelete,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ObjectNote,
+ APActivityType: ap.ActivityDelete,
GTSModel: targetStatus,
OriginAccount: requestingAccount,
TargetAccount: requestingAccount,
diff --git a/internal/processing/status/fave.go b/internal/processing/status/fave.go
index 2badf83b3..195bfa56a 100644
--- a/internal/processing/status/fave.go
+++ b/internal/processing/status/fave.go
@@ -23,11 +23,13 @@ import (
"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/util"
)
@@ -47,10 +49,8 @@ func (p *processor) Fave(ctx context.Context, requestingAccount *gtsmodel.Accoun
if !visible {
return nil, gtserror.NewErrorNotFound(errors.New("status is not visible"))
}
- if targetStatus.VisibilityAdvanced != nil {
- if !targetStatus.VisibilityAdvanced.Likeable {
- return nil, gtserror.NewErrorForbidden(errors.New("status is not faveable"))
- }
+ if !targetStatus.VisibilityAdvanced.Likeable {
+ return nil, gtserror.NewErrorForbidden(errors.New("status is not faveable"))
}
// first check if the status is already faved, if so we don't need to do anything
@@ -84,9 +84,9 @@ func (p *processor) Fave(ctx context.Context, requestingAccount *gtsmodel.Accoun
}
// send it back to the processor for async processing
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsLike,
- APActivityType: gtsmodel.ActivityStreamsCreate,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityLike,
+ APActivityType: ap.ActivityCreate,
GTSModel: gtsFave,
OriginAccount: requestingAccount,
TargetAccount: targetStatus.Account,
diff --git a/internal/processing/status/status.go b/internal/processing/status/status.go
index 37790d062..10faa5696 100644
--- a/internal/processing/status/status.go
+++ b/internal/processing/status/status.go
@@ -27,6 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/text"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/visibility"
@@ -75,12 +76,12 @@ type processor struct {
db db.DB
filter visibility.Filter
formatter text.Formatter
- fromClientAPI chan gtsmodel.FromClientAPI
+ fromClientAPI chan messages.FromClientAPI
log *logrus.Logger
}
// New returns a new status processor.
-func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, fromClientAPI chan gtsmodel.FromClientAPI, log *logrus.Logger) Processor {
+func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, fromClientAPI chan messages.FromClientAPI, log *logrus.Logger) Processor {
return &processor{
tc: tc,
config: config,
diff --git a/internal/processing/status/status_test.go b/internal/processing/status/status_test.go
index ba95a96a8..707a4843b 100644
--- a/internal/processing/status/status_test.go
+++ b/internal/processing/status/status_test.go
@@ -24,7 +24,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -36,11 +36,11 @@ type StatusStandardTestSuite struct {
db db.DB
log *logrus.Logger
typeConverter typeutils.TypeConverter
- fromClientAPIChan chan gtsmodel.FromClientAPI
+ fromClientAPIChan chan messages.FromClientAPI
// standard suite models
- testTokens map[string]*oauth.Token
- testClients map[string]*oauth.Client
+ testTokens map[string]*gtsmodel.Token
+ testClients map[string]*gtsmodel.Client
testApplications map[string]*gtsmodel.Application
testUsers map[string]*gtsmodel.User
testAccounts map[string]*gtsmodel.Account
diff --git a/internal/processing/status/unboost.go b/internal/processing/status/unboost.go
index c3c667a71..13c24d638 100644
--- a/internal/processing/status/unboost.go
+++ b/internal/processing/status/unboost.go
@@ -23,10 +23,12 @@ import (
"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) Unboost(ctx context.Context, requestingAccount *gtsmodel.Account, application *gtsmodel.Application, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
@@ -89,9 +91,9 @@ func (p *processor) Unboost(ctx context.Context, requestingAccount *gtsmodel.Acc
gtsBoost.BoostOf.Account = targetStatus.Account
// send it back to the processor for async processing
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsAnnounce,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityAnnounce,
+ APActivityType: ap.ActivityUndo,
GTSModel: gtsBoost,
OriginAccount: requestingAccount,
TargetAccount: targetStatus.Account,
diff --git a/internal/processing/status/unfave.go b/internal/processing/status/unfave.go
index 3d079e2ff..27ce9b156 100644
--- a/internal/processing/status/unfave.go
+++ b/internal/processing/status/unfave.go
@@ -23,10 +23,12 @@ import (
"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) Unfave(ctx context.Context, requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
@@ -71,9 +73,9 @@ func (p *processor) Unfave(ctx context.Context, requestingAccount *gtsmodel.Acco
}
// send it back to the processor for async processing
- p.fromClientAPI <- gtsmodel.FromClientAPI{
- APObjectType: gtsmodel.ActivityStreamsLike,
- APActivityType: gtsmodel.ActivityStreamsUndo,
+ p.fromClientAPI <- messages.FromClientAPI{
+ APObjectType: ap.ActivityLike,
+ APActivityType: ap.ActivityUndo,
GTSModel: gtsFave,
OriginAccount: requestingAccount,
TargetAccount: targetStatus.Account,
diff --git a/internal/processing/status/util.go b/internal/processing/status/util.go
index 26ee5d4f7..8861a532b 100644
--- a/internal/processing/status/util.go
+++ b/internal/processing/status/util.go
@@ -33,7 +33,7 @@ import (
func (p *processor) ProcessVisibility(ctx context.Context, form *apimodel.AdvancedStatusCreateForm, accountDefaultVis gtsmodel.Visibility, status *gtsmodel.Status) error {
// by default all flags are set to true
- gtsAdvancedVis := &gtsmodel.VisibilityAdvanced{
+ gtsAdvancedVis := gtsmodel.VisibilityAdvanced{
Federated: true,
Boostable: true,
Replyable: true,
@@ -123,11 +123,8 @@ func (p *processor) ProcessReplyToID(ctx context.Context, form *apimodel.Advance
}
return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err)
}
-
- if repliedStatus.VisibilityAdvanced != nil {
- if !repliedStatus.VisibilityAdvanced.Replyable {
- return fmt.Errorf("status with id %s is marked as not replyable", form.InReplyToID)
- }
+ if !repliedStatus.VisibilityAdvanced.Replyable {
+ return fmt.Errorf("status with id %s is marked as not replyable", form.InReplyToID)
}
// check replied account is known to us
diff --git a/internal/processing/status/util_test.go b/internal/processing/status/util_test.go
index 1ec2076b1..f80cf9342 100644
--- a/internal/processing/status/util_test.go
+++ b/internal/processing/status/util_test.go
@@ -27,6 +27,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -68,7 +69,7 @@ func (suite *UtilTestSuite) SetupTest() {
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
suite.typeConverter = testrig.NewTestTypeConverter(suite.db)
- suite.fromClientAPIChan = make(chan gtsmodel.FromClientAPI, 100)
+ suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100)
suite.status = status.New(suite.db, suite.typeConverter, suite.config, suite.fromClientAPIChan, suite.log)
testrig.StandardDBSetup(suite.db, nil)
diff --git a/internal/processing/streaming.go b/internal/processing/streaming.go
index e1c134d00..fd5113b0d 100644
--- a/internal/processing/streaming.go
+++ b/internal/processing/streaming.go
@@ -23,12 +23,13 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
)
func (p *processor) AuthorizeStreamingRequest(ctx context.Context, accessToken string) (*gtsmodel.Account, error) {
return p.streamingProcessor.AuthorizeStreamingRequest(ctx, accessToken)
}
-func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*gtsmodel.Stream, gtserror.WithCode) {
+func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode) {
return p.streamingProcessor.OpenStreamForAccount(ctx, account, streamType)
}
diff --git a/internal/processing/streaming/openstream.go b/internal/processing/streaming/openstream.go
index dfad5398e..d4e4eef9f 100644
--- a/internal/processing/streaming/openstream.go
+++ b/internal/processing/streaming/openstream.go
@@ -9,9 +9,10 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
)
-func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*gtsmodel.Stream, gtserror.WithCode) {
+func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode) {
l := p.log.WithFields(logrus.Fields{
"func": "OpenStreamForAccount",
"account": account.ID,
@@ -25,10 +26,10 @@ func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error generating stream id: %s", err))
}
- thisStream := &gtsmodel.Stream{
+ thisStream := &stream.Stream{
ID: streamID,
Type: streamType,
- Messages: make(chan *gtsmodel.Message, 100),
+ Messages: make(chan *stream.Message, 100),
Hangup: make(chan interface{}, 1),
Connected: true,
}
@@ -37,8 +38,8 @@ func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.
v, ok := p.streamMap.Load(account.ID)
if !ok || v == nil {
// there is no entry in the streamMap for this account yet, so make one and store it
- streamsForAccount := &gtsmodel.StreamsForAccount{
- Streams: []*gtsmodel.Stream{
+ streamsForAccount := &stream.StreamsForAccount{
+ Streams: []*stream.Stream{
thisStream,
},
}
@@ -46,7 +47,7 @@ func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.
} else {
// there is an entry in the streamMap for this account
// parse the interface as a streamsForAccount
- streamsForAccount, ok := v.(*gtsmodel.StreamsForAccount)
+ streamsForAccount, ok := v.(*stream.StreamsForAccount)
if !ok {
return nil, gtserror.NewErrorInternalError(errors.New("stream map error"))
}
@@ -63,7 +64,7 @@ func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.
// waitToCloseStream waits until the hangup channel is closed for the given stream.
// It then iterates through the map of streams stored by the processor, removes the stream from it,
// and then closes the messages channel of the stream to indicate that the channel should no longer be read from.
-func (p *processor) waitToCloseStream(account *gtsmodel.Account, thisStream *gtsmodel.Stream) {
+func (p *processor) waitToCloseStream(account *gtsmodel.Account, thisStream *stream.Stream) {
<-thisStream.Hangup // wait for a hangup message
// lock the stream to prevent more messages being put in it while we work
@@ -78,7 +79,7 @@ func (p *processor) waitToCloseStream(account *gtsmodel.Account, thisStream *gts
if !ok || v == nil {
return
}
- streamsForAccount, ok := v.(*gtsmodel.StreamsForAccount)
+ streamsForAccount, ok := v.(*stream.StreamsForAccount)
if !ok {
return
}
@@ -88,7 +89,7 @@ func (p *processor) waitToCloseStream(account *gtsmodel.Account, thisStream *gts
defer streamsForAccount.Unlock()
// put everything into modified streams *except* the stream we're removing
- modifiedStreams := []*gtsmodel.Stream{}
+ modifiedStreams := []*stream.Stream{}
for _, s := range streamsForAccount.Streams {
if s.ID != thisStream.ID {
modifiedStreams = append(modifiedStreams, s)
diff --git a/internal/processing/streaming/streamdelete.go b/internal/processing/streaming/streamdelete.go
index 2282c29ae..cd541bc57 100644
--- a/internal/processing/streaming/streamdelete.go
+++ b/internal/processing/streaming/streamdelete.go
@@ -4,7 +4,7 @@ import (
"fmt"
"strings"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
)
func (p *processor) StreamDelete(statusID string) error {
@@ -20,7 +20,7 @@ func (p *processor) StreamDelete(statusID string) error {
}
// the value of the map should be a buncha streams
- streamsForAccount, ok := v.(*gtsmodel.StreamsForAccount)
+ streamsForAccount, ok := v.(*stream.StreamsForAccount)
if !ok {
errs = append(errs, fmt.Sprintf("stream map error for account stream %s", accountID))
}
@@ -28,13 +28,13 @@ func (p *processor) StreamDelete(statusID string) error {
// lock the streams while we work on them
streamsForAccount.Lock()
defer streamsForAccount.Unlock()
- for _, stream := range streamsForAccount.Streams {
+ for _, s := range streamsForAccount.Streams {
// lock each individual stream as we work on it
- stream.Lock()
- defer stream.Unlock()
- if stream.Connected {
- stream.Messages <- &gtsmodel.Message{
- Stream: []string{stream.Type},
+ s.Lock()
+ defer s.Unlock()
+ if s.Connected {
+ s.Messages <- &stream.Message{
+ Stream: []string{s.Type},
Event: "delete",
Payload: statusID,
}
diff --git a/internal/processing/streaming/streaming.go b/internal/processing/streaming/streaming.go
index f349a655a..610d4a9d2 100644
--- a/internal/processing/streaming/streaming.go
+++ b/internal/processing/streaming/streaming.go
@@ -11,6 +11,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/visibility"
)
@@ -20,7 +21,7 @@ type Processor interface {
// AuthorizeStreamingRequest returns an oauth2 token info in response to an access token query from the streaming API
AuthorizeStreamingRequest(ctx context.Context, accessToken string) (*gtsmodel.Account, error)
// OpenStreamForAccount returns a new Stream for the given account, which will contain a channel for passing messages back to the caller.
- OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*gtsmodel.Stream, gtserror.WithCode)
+ OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode)
// StreamStatusToAccount streams the given status to any open, appropriate streams belonging to the given account.
StreamStatusToAccount(s *apimodel.Status, account *gtsmodel.Account) error
// StreamNotificationToAccount streams the given notification to any open, appropriate streams belonging to the given account.
diff --git a/internal/processing/streaming/streamnotification.go b/internal/processing/streaming/streamnotification.go
index 24c8342ee..d8460874f 100644
--- a/internal/processing/streaming/streamnotification.go
+++ b/internal/processing/streaming/streamnotification.go
@@ -8,6 +8,7 @@ import (
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
)
func (p *processor) StreamNotificationToAccount(n *apimodel.Notification, account *gtsmodel.Account) error {
@@ -21,7 +22,7 @@ func (p *processor) StreamNotificationToAccount(n *apimodel.Notification, accoun
return nil
}
- streamsForAccount, ok := v.(*gtsmodel.StreamsForAccount)
+ streamsForAccount, ok := v.(*stream.StreamsForAccount)
if !ok {
return errors.New("stream map error")
}
@@ -33,13 +34,13 @@ func (p *processor) StreamNotificationToAccount(n *apimodel.Notification, accoun
streamsForAccount.Lock()
defer streamsForAccount.Unlock()
- for _, stream := range streamsForAccount.Streams {
- stream.Lock()
- defer stream.Unlock()
- if stream.Connected {
- l.Debugf("streaming notification to stream id %s", stream.ID)
- stream.Messages <- &gtsmodel.Message{
- Stream: []string{stream.Type},
+ for _, s := range streamsForAccount.Streams {
+ s.Lock()
+ defer s.Unlock()
+ if s.Connected {
+ l.Debugf("streaming notification to stream id %s", s.ID)
+ s.Messages <- &stream.Message{
+ Stream: []string{s.Type},
Event: "notification",
Payload: string(notificationBytes),
}
diff --git a/internal/processing/streaming/streamstatus.go b/internal/processing/streaming/streamstatus.go
index 8d026252d..f4d6b2629 100644
--- a/internal/processing/streaming/streamstatus.go
+++ b/internal/processing/streaming/streamstatus.go
@@ -8,6 +8,7 @@ import (
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
)
func (p *processor) StreamStatusToAccount(s *apimodel.Status, account *gtsmodel.Account) error {
@@ -21,7 +22,7 @@ func (p *processor) StreamStatusToAccount(s *apimodel.Status, account *gtsmodel.
return nil
}
- streamsForAccount, ok := v.(*gtsmodel.StreamsForAccount)
+ streamsForAccount, ok := v.(*stream.StreamsForAccount)
if !ok {
return errors.New("stream map error")
}
@@ -33,13 +34,13 @@ func (p *processor) StreamStatusToAccount(s *apimodel.Status, account *gtsmodel.
streamsForAccount.Lock()
defer streamsForAccount.Unlock()
- for _, stream := range streamsForAccount.Streams {
- stream.Lock()
- defer stream.Unlock()
- if stream.Connected {
- l.Debugf("streaming status to stream id %s", stream.ID)
- stream.Messages <- &gtsmodel.Message{
- Stream: []string{stream.Type},
+ for _, s := range streamsForAccount.Streams {
+ s.Lock()
+ defer s.Unlock()
+ if s.Connected {
+ l.Debugf("streaming status to stream id %s", s.ID)
+ s.Messages <- &stream.Message{
+ Stream: []string{s.Type},
Event: "update",
Payload: string(statusBytes),
}