summaryrefslogtreecommitdiff
path: root/internal/federation
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation')
-rw-r--r--internal/federation/federatingdb/create.go38
-rw-r--r--internal/federation/federatingdb/create_test.go46
2 files changed, 84 insertions, 0 deletions
diff --git a/internal/federation/federatingdb/create.go b/internal/federation/federatingdb/create.go
index 05321bd6c..fbe3d3ad6 100644
--- a/internal/federation/federatingdb/create.go
+++ b/internal/federation/federatingdb/create.go
@@ -78,6 +78,9 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
case ap.ActivityLike:
// LIKE SOMETHING
return f.activityLike(ctx, asType, receivingAccount, requestingAccount)
+ case ap.ActivityFlag:
+ // FLAG / REPORT SOMETHING
+ return f.activityFlag(ctx, asType, receivingAccount, requestingAccount)
}
return nil
}
@@ -314,3 +317,38 @@ func (f *federatingDB) activityLike(ctx context.Context, asType vocab.Type, rece
return nil
}
+
+/*
+ FLAG HANDLERS
+*/
+
+func (f *federatingDB) activityFlag(ctx context.Context, asType vocab.Type, receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) error {
+ flag, ok := asType.(vocab.ActivityStreamsFlag)
+ if !ok {
+ return errors.New("activityFlag: could not convert type to flag")
+ }
+
+ report, err := f.typeConverter.ASFlagToReport(ctx, flag)
+ if err != nil {
+ return fmt.Errorf("activityFlag: could not convert Flag to report: %w", err)
+ }
+
+ newID, err := id.NewULID()
+ if err != nil {
+ return err
+ }
+ report.ID = newID
+
+ if err := f.db.PutReport(ctx, report); err != nil {
+ return fmt.Errorf("activityFlag: database error inserting report: %w", err)
+ }
+
+ f.fedWorker.Queue(messages.FromFederator{
+ APObjectType: ap.ActivityFlag,
+ APActivityType: ap.ActivityCreate,
+ GTSModel: report,
+ ReceivingAccount: receivingAccount,
+ })
+
+ return nil
+}
diff --git a/internal/federation/federatingdb/create_test.go b/internal/federation/federatingdb/create_test.go
index 6bab42889..c56dcd864 100644
--- a/internal/federation/federatingdb/create_test.go
+++ b/internal/federation/federatingdb/create_test.go
@@ -20,9 +20,11 @@ package federatingdb_test
import (
"context"
+ "encoding/json"
"testing"
"github.com/stretchr/testify/suite"
+ "github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
@@ -83,6 +85,50 @@ func (suite *CreateTestSuite) TestCreateNoteForward() {
suite.Equal("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1", msg.APIri.String())
}
+func (suite *CreateTestSuite) TestCreateFlag1() {
+ reportedAccount := suite.testAccounts["local_account_1"]
+ reportingAccount := suite.testAccounts["remote_account_1"]
+ reportedStatus := suite.testStatuses["local_account_1_status_1"]
+
+ raw := `{
+ "@context": "https://www.w3.org/ns/activitystreams",
+ "actor": "` + reportingAccount.URI + `",
+ "content": "Note: ` + reportedStatus.URL + `\n-----\nban this sick filth ⛔",
+ "id": "http://fossbros-anonymous.io/db22128d-884e-4358-9935-6a7c3940535d",
+ "object": "` + reportedAccount.URI + `",
+ "type": "Flag"
+}`
+
+ m := make(map[string]interface{})
+ if err := json.Unmarshal([]byte(raw), &m); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ t, err := streams.ToType(context.Background(), m)
+ if err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ ctx := createTestContext(reportedAccount, reportingAccount)
+ if err := suite.federatingDB.Create(ctx, t); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // should be a message heading to the processor now, which we can intercept here
+ msg := <-suite.fromFederator
+ suite.Equal(ap.ActivityFlag, msg.APObjectType)
+ suite.Equal(ap.ActivityCreate, msg.APActivityType)
+
+ // shiny new report should be defined on the message
+ suite.NotNil(msg.GTSModel)
+ report := msg.GTSModel.(*gtsmodel.Report)
+
+ // report should be in the database
+ if _, err := suite.db.GetReportByID(context.Background(), report.ID); err != nil {
+ suite.FailNow(err.Error())
+ }
+}
+
func TestCreateTestSuite(t *testing.T) {
suite.Run(t, &CreateTestSuite{})
}