diff --git a/internal/apimodule/account/account.go b/internal/apimodule/account/account.go index a836afcdb..ce2dc4e2c 100644 --- a/internal/apimodule/account/account.go +++ b/internal/apimodule/account/account.go @@ -29,7 +29,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" @@ -51,23 +51,23 @@ const ( // Module implements the ClientAPIModule interface for account-related actions type Module struct { - config *config.Config - db db.DB - oauthServer oauth.Server - mediaHandler media.Handler - mastoConverter mastotypes.Converter - log *logrus.Logger + config *config.Config + db db.DB + oauthServer oauth.Server + mediaHandler media.Handler + tc typeutils.TypeConverter + log *logrus.Logger } // New returns a new account module -func New(config *config.Config, db db.DB, oauthServer oauth.Server, mediaHandler media.Handler, mastoConverter mastotypes.Converter, log *logrus.Logger) apimodule.ClientAPIModule { +func New(config *config.Config, db db.DB, oauthServer oauth.Server, mediaHandler media.Handler, tc typeutils.TypeConverter, log *logrus.Logger) apimodule.ClientAPIModule { return &Module{ - config: config, - db: db, - oauthServer: oauthServer, - mediaHandler: mediaHandler, - mastoConverter: mastoConverter, - log: log, + config: config, + db: db, + oauthServer: oauthServer, + mediaHandler: mediaHandler, + tc: tc, + log: log, } } diff --git a/internal/apimodule/account/accountcreate.go b/internal/apimodule/account/accountcreate.go index fb21925b8..9a092fa69 100644 --- a/internal/apimodule/account/accountcreate.go +++ b/internal/apimodule/account/accountcreate.go @@ -28,7 +28,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/util" "github.com/superseriousbusiness/oauth2/v4" diff --git a/internal/apimodule/account/accountcreate_test.go b/internal/apimodule/account/accountcreate_test.go index da2b22510..6e5c3a8eb 100644 --- a/internal/apimodule/account/accountcreate_test.go +++ b/internal/apimodule/account/accountcreate_test.go @@ -44,7 +44,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/mastotypes" - mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" @@ -65,7 +65,7 @@ type AccountCreateTestSuite struct { mockOauthServer *oauth.MockServer mockStorage *storage.MockStorage mediaHandler media.Handler - mastoConverter mastotypes.Converter + mastoConverter typeutils.TypeConverter db db.DB accountModule *account.Module newUserFormHappyPath url.Values @@ -162,7 +162,7 @@ func (suite *AccountCreateTestSuite) SetupSuite() { // set a media handler because some handlers (eg update credentials) need to upload media (new header/avatar) suite.mediaHandler = media.New(suite.config, suite.db, suite.mockStorage, log) - suite.mastoConverter = mastotypes.New(suite.config, suite.db) + suite.mastoConverter = typeutils.NewConverter(suite.config, suite.db) // and finally here's the thing we're actually testing! suite.accountModule = account.New(suite.config, suite.db, suite.mockOauthServer, suite.mediaHandler, suite.mastoConverter, suite.log).(*account.Module) @@ -265,7 +265,7 @@ func (suite *AccountCreateTestSuite) TestAccountCreatePOSTHandlerSuccessful() { defer result.Body.Close() b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - t := &mastomodel.Token{} + t := &mastotypes.Token{} err = json.Unmarshal(b, t) assert.NoError(suite.T(), err) assert.Equal(suite.T(), "we're authorized now!", t.AccessToken) diff --git a/internal/apimodule/account/accountget.go b/internal/apimodule/account/accountget.go index 5003be139..e39623f84 100644 --- a/internal/apimodule/account/accountget.go +++ b/internal/apimodule/account/accountget.go @@ -47,7 +47,7 @@ func (m *Module) AccountGETHandler(c *gin.Context) { return } - acctInfo, err := m.mastoConverter.AccountToMastoPublic(targetAccount) + acctInfo, err := m.tc.AccountToMastoPublic(targetAccount) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return diff --git a/internal/apimodule/account/accountupdate.go b/internal/apimodule/account/accountupdate.go index 7709697bf..5e3760baa 100644 --- a/internal/apimodule/account/accountupdate.go +++ b/internal/apimodule/account/accountupdate.go @@ -28,7 +28,7 @@ import ( "github.com/gin-gonic/gin" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/util" @@ -176,7 +176,7 @@ func (m *Module) AccountUpdateCredentialsPATCHHandler(c *gin.Context) { return } - acctSensitive, err := m.mastoConverter.AccountToMastoSensitive(updatedAccount) + acctSensitive, err := m.tc.AccountToMastoSensitive(updatedAccount) if err != nil { l.Tracef("could not convert account into mastosensitive account: %s", err) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) diff --git a/internal/apimodule/account/accountupdate_test.go b/internal/apimodule/account/accountupdate_test.go index 78664f19c..4b6bd50f6 100644 --- a/internal/apimodule/account/accountupdate_test.go +++ b/internal/apimodule/account/accountupdate_test.go @@ -41,10 +41,10 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/oauth2/v4" "github.com/superseriousbusiness/oauth2/v4/models" oauthmodels "github.com/superseriousbusiness/oauth2/v4/models" @@ -60,7 +60,7 @@ type AccountUpdateTestSuite struct { mockOauthServer *oauth.MockServer mockStorage *storage.MockStorage mediaHandler media.Handler - mastoConverter mastotypes.Converter + mastoConverter typeutils.TypeConverter db db.DB accountModule *account.Module newUserFormHappyPath url.Values @@ -157,7 +157,7 @@ func (suite *AccountUpdateTestSuite) SetupSuite() { // set a media handler because some handlers (eg update credentials) need to upload media (new header/avatar) suite.mediaHandler = media.New(suite.config, suite.db, suite.mockStorage, log) - suite.mastoConverter = mastotypes.New(suite.config, suite.db) + suite.mastoConverter = typeutils.NewConverter(suite.config, suite.db) // and finally here's the thing we're actually testing! suite.accountModule = account.New(suite.config, suite.db, suite.mockOauthServer, suite.mediaHandler, suite.mastoConverter, suite.log).(*account.Module) diff --git a/internal/apimodule/account/accountverify.go b/internal/apimodule/account/accountverify.go index 9edf1e73a..3c7f9b9ac 100644 --- a/internal/apimodule/account/accountverify.go +++ b/internal/apimodule/account/accountverify.go @@ -38,7 +38,7 @@ func (m *Module) AccountVerifyGETHandler(c *gin.Context) { } l.Tracef("retrieved account %+v, converting to mastosensitive...", authed.Account.ID) - acctSensitive, err := m.mastoConverter.AccountToMastoSensitive(authed.Account) + acctSensitive, err := m.tc.AccountToMastoSensitive(authed.Account) if err != nil { l.Tracef("could not convert account into mastosensitive account: %s", err) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) diff --git a/internal/apimodule/admin/admin.go b/internal/apimodule/admin/admin.go index 200e7bd88..703f38257 100644 --- a/internal/apimodule/admin/admin.go +++ b/internal/apimodule/admin/admin.go @@ -27,9 +27,9 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/router" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) const ( @@ -41,21 +41,21 @@ const ( // Module implements the ClientAPIModule interface for admin-related actions (reports, emojis, etc) type Module struct { - config *config.Config - db db.DB - mediaHandler media.Handler - mastoConverter mastotypes.Converter - log *logrus.Logger + config *config.Config + db db.DB + mediaHandler media.Handler + tc typeutils.TypeConverter + log *logrus.Logger } // New returns a new admin module -func New(config *config.Config, db db.DB, mediaHandler media.Handler, mastoConverter mastotypes.Converter, log *logrus.Logger) apimodule.ClientAPIModule { +func New(config *config.Config, db db.DB, mediaHandler media.Handler, tc typeutils.TypeConverter, log *logrus.Logger) apimodule.ClientAPIModule { return &Module{ - config: config, - db: db, - mediaHandler: mediaHandler, - mastoConverter: mastoConverter, - log: log, + config: config, + db: db, + mediaHandler: mediaHandler, + tc: tc, + log: log, } } diff --git a/internal/apimodule/admin/emojicreate.go b/internal/apimodule/admin/emojicreate.go index 49e5492dd..1da83a4c4 100644 --- a/internal/apimodule/admin/emojicreate.go +++ b/internal/apimodule/admin/emojicreate.go @@ -27,7 +27,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/util" @@ -99,7 +99,7 @@ func (m *Module) emojiCreatePOSTHandler(c *gin.Context) { return } - mastoEmoji, err := m.mastoConverter.EmojiToMasto(emoji) + mastoEmoji, err := m.tc.EmojiToMasto(emoji) if err != nil { l.Debugf("error converting emoji to mastotype: %s", err) c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("could not convert emoji: %s", err)}) diff --git a/internal/apimodule/app/app.go b/internal/apimodule/app/app.go index 518192758..2a1c7752f 100644 --- a/internal/apimodule/app/app.go +++ b/internal/apimodule/app/app.go @@ -26,9 +26,9 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/apimodule" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/router" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) // BasePath is the base path for this api module @@ -36,19 +36,19 @@ const BasePath = "/api/v1/apps" // Module implements the ClientAPIModule interface for requests relating to registering/removing applications type Module struct { - server oauth.Server - db db.DB - mastoConverter mastotypes.Converter - log *logrus.Logger + server oauth.Server + db db.DB + tc typeutils.TypeConverter + log *logrus.Logger } // New returns a new auth module -func New(srv oauth.Server, db db.DB, mastoConverter mastotypes.Converter, log *logrus.Logger) apimodule.ClientAPIModule { +func New(srv oauth.Server, db db.DB, tc typeutils.TypeConverter, log *logrus.Logger) apimodule.ClientAPIModule { return &Module{ - server: srv, - db: db, - mastoConverter: mastoConverter, - log: log, + server: srv, + db: db, + tc: tc, + log: log, } } diff --git a/internal/apimodule/app/appcreate.go b/internal/apimodule/app/appcreate.go index 99b79d470..dd78dddfc 100644 --- a/internal/apimodule/app/appcreate.go +++ b/internal/apimodule/app/appcreate.go @@ -25,7 +25,7 @@ import ( "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/oauth" ) @@ -108,7 +108,7 @@ func (m *Module) AppsPOSTHandler(c *gin.Context) { return } - mastoApp, err := m.mastoConverter.AppToMastoSensitive(app) + mastoApp, err := m.tc.AppToMastoSensitive(app) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return diff --git a/internal/apimodule/auth/authorize.go b/internal/apimodule/auth/authorize.go index 4bc1991ac..394780374 100644 --- a/internal/apimodule/auth/authorize.go +++ b/internal/apimodule/auth/authorize.go @@ -28,7 +28,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" ) // AuthorizeGETHandler should be served as GET at https://example.org/oauth/authorize diff --git a/internal/apimodule/fileserver/servefile_test.go b/internal/apimodule/fileserver/servefile_test.go index 4c0844010..08800071e 100644 --- a/internal/apimodule/fileserver/servefile_test.go +++ b/internal/apimodule/fileserver/servefile_test.go @@ -34,23 +34,23 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) type ServeFileTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config - db db.DB - log *logrus.Logger - storage storage.Storage - mastoConverter mastotypes.Converter - mediaHandler media.Handler - oauthServer oauth.Server + config *config.Config + db db.DB + log *logrus.Logger + storage storage.Storage + tc typeutils.TypeConverter + mediaHandler media.Handler + oauthServer oauth.Server // standard suite models testTokens map[string]*oauth.Token @@ -74,7 +74,7 @@ func (suite *ServeFileTestSuite) SetupSuite() { suite.db = testrig.NewTestDB() suite.log = testrig.NewTestLog() suite.storage = testrig.NewTestStorage() - suite.mastoConverter = testrig.NewTestMastoConverter(suite.db) + suite.tc = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.oauthServer = testrig.NewTestOauthServer(suite.db) diff --git a/internal/apimodule/media/media.go b/internal/apimodule/media/media.go index 8fb9f16ec..89161e8df 100644 --- a/internal/apimodule/media/media.go +++ b/internal/apimodule/media/media.go @@ -27,9 +27,9 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/router" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) // BasePath is the base API path for making media requests @@ -37,21 +37,21 @@ const BasePath = "/api/v1/media" // Module implements the ClientAPIModule interface for media type Module struct { - mediaHandler media.Handler - config *config.Config - db db.DB - mastoConverter mastotypes.Converter - log *logrus.Logger + mediaHandler media.Handler + config *config.Config + db db.DB + tc typeutils.TypeConverter + log *logrus.Logger } // New returns a new auth module -func New(db db.DB, mediaHandler media.Handler, mastoConverter mastotypes.Converter, config *config.Config, log *logrus.Logger) apimodule.ClientAPIModule { +func New(db db.DB, mediaHandler media.Handler, tc typeutils.TypeConverter, config *config.Config, log *logrus.Logger) apimodule.ClientAPIModule { return &Module{ - mediaHandler: mediaHandler, - config: config, - db: db, - mastoConverter: mastoConverter, - log: log, + mediaHandler: mediaHandler, + config: config, + db: db, + tc: tc, + log: log, } } diff --git a/internal/apimodule/media/mediacreate.go b/internal/apimodule/media/mediacreate.go index ee713a471..75d80b966 100644 --- a/internal/apimodule/media/mediacreate.go +++ b/internal/apimodule/media/mediacreate.go @@ -29,7 +29,7 @@ import ( "github.com/gin-gonic/gin" "github.com/superseriousbusiness/gotosocial/internal/config" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/oauth" ) @@ -149,7 +149,7 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) { // prepare the frontend representation now -- if there are any errors here at least we can bail without // having already put something in the database and then having to clean it up again (eugh) - mastoAttachment, err := m.mastoConverter.AttachmentToMasto(attachment) + mastoAttachment, err := m.tc.AttachmentToMasto(attachment) if err != nil { l.Debugf("error parsing media attachment to frontend type: %s", err) c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("error parsing media attachment to frontend type: %s", err)}) diff --git a/internal/apimodule/media/mediacreate_test.go b/internal/apimodule/media/mediacreate_test.go index 0c13ab8ab..64b532dce 100644 --- a/internal/apimodule/media/mediacreate_test.go +++ b/internal/apimodule/media/mediacreate_test.go @@ -37,23 +37,23 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/mastotypes" - mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) type MediaCreateTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config - db db.DB - log *logrus.Logger - storage storage.Storage - mastoConverter mastotypes.Converter - mediaHandler media.Handler - oauthServer oauth.Server + config *config.Config + db db.DB + log *logrus.Logger + storage storage.Storage + tc typeutils.TypeConverter + mediaHandler media.Handler + oauthServer oauth.Server // standard suite models testTokens map[string]*oauth.Token @@ -77,12 +77,12 @@ func (suite *MediaCreateTestSuite) SetupSuite() { suite.db = testrig.NewTestDB() suite.log = testrig.NewTestLog() suite.storage = testrig.NewTestStorage() - suite.mastoConverter = testrig.NewTestMastoConverter(suite.db) + suite.tc = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.oauthServer = testrig.NewTestOauthServer(suite.db) // setup module being tested - suite.mediaModule = mediamodule.New(suite.db, suite.mediaHandler, suite.mastoConverter, suite.config, suite.log).(*mediamodule.Module) + suite.mediaModule = mediamodule.New(suite.db, suite.mediaHandler, suite.tc, suite.config, suite.log).(*mediamodule.Module) } func (suite *MediaCreateTestSuite) TearDownSuite() { @@ -158,26 +158,26 @@ func (suite *MediaCreateTestSuite) TestStatusCreatePOSTImageHandlerSuccessful() assert.NoError(suite.T(), err) fmt.Println(string(b)) - attachmentReply := &mastomodel.Attachment{} + attachmentReply := &mastotypes.Attachment{} err = json.Unmarshal(b, attachmentReply) assert.NoError(suite.T(), err) assert.Equal(suite.T(), "this is a test image -- a cool background from somewhere", attachmentReply.Description) assert.Equal(suite.T(), "image", attachmentReply.Type) - assert.EqualValues(suite.T(), mastomodel.MediaMeta{ - Original: mastomodel.MediaDimensions{ + assert.EqualValues(suite.T(), mastotypes.MediaMeta{ + Original: mastotypes.MediaDimensions{ Width: 1920, Height: 1080, Size: "1920x1080", Aspect: 1.7777778, }, - Small: mastomodel.MediaDimensions{ + Small: mastotypes.MediaDimensions{ Width: 256, Height: 144, Size: "256x144", Aspect: 1.7777778, }, - Focus: mastomodel.MediaFocus{ + Focus: mastotypes.MediaFocus{ X: -0.5, Y: 0.5, }, diff --git a/internal/apimodule/status/status.go b/internal/apimodule/status/status.go index c54ac4bcf..e370420e5 100644 --- a/internal/apimodule/status/status.go +++ b/internal/apimodule/status/status.go @@ -30,9 +30,9 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/distributor" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/router" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) const ( @@ -79,23 +79,23 @@ const ( // Module implements the ClientAPIModule interface for every related to posting/deleting/interacting with statuses type Module struct { - config *config.Config - db db.DB - mediaHandler media.Handler - mastoConverter mastotypes.Converter - distributor distributor.Distributor - log *logrus.Logger + config *config.Config + db db.DB + mediaHandler media.Handler + tc typeutils.TypeConverter + distributor distributor.Distributor + log *logrus.Logger } // New returns a new account module -func New(config *config.Config, db db.DB, mediaHandler media.Handler, mastoConverter mastotypes.Converter, distributor distributor.Distributor, log *logrus.Logger) apimodule.ClientAPIModule { +func New(config *config.Config, db db.DB, mediaHandler media.Handler, tc typeutils.TypeConverter, distributor distributor.Distributor, log *logrus.Logger) apimodule.ClientAPIModule { return &Module{ - config: config, - db: db, - mediaHandler: mediaHandler, - mastoConverter: mastoConverter, - distributor: distributor, - log: log, + config: config, + db: db, + mediaHandler: mediaHandler, + tc: tc, + distributor: distributor, + log: log, } } diff --git a/internal/apimodule/status/statuscreate.go b/internal/apimodule/status/statuscreate.go index 7d9b2fdbb..79b6fb2a0 100644 --- a/internal/apimodule/status/statuscreate.go +++ b/internal/apimodule/status/statuscreate.go @@ -30,7 +30,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/distributor" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/util" ) @@ -82,7 +82,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) { // Give the fields on the request form a first pass to make sure the request is superficially valid. l.Tracef("validating form %+v", form) - if err := validateCreateStatus(form, m.config.StatusesConfig); err != nil { + if err := m.validateCreateStatus(form, m.config.StatusesConfig); err != nil { l.Debugf("error validating form: %s", err) c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return @@ -127,7 +127,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) { } // check if visibility settings are ok - if err := parseVisibility(form, authed.Account.Privacy, newStatus); err != nil { + if err := m.parseVisibility(form, authed.Account.Privacy, newStatus); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } @@ -182,7 +182,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) { } // return the frontend representation of the new status to the submitter - mastoStatus, err := m.mastoConverter.StatusToMasto(newStatus, authed.Account, authed.Account, nil, newStatus.GTSReplyToAccount, nil) + mastoStatus, err := m.tc.StatusToMasto(newStatus, authed.Account, authed.Account, nil, newStatus.GTSReplyToAccount, nil) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return @@ -190,7 +190,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) { c.JSON(http.StatusOK, mastoStatus) } -func validateCreateStatus(form *advancedStatusCreateForm, config *config.StatusesConfig) error { +func (m *Module) validateCreateStatus(form *advancedStatusCreateForm, config *config.StatusesConfig) error { // validate that, structurally, we have a valid status/post if form.Status == "" && form.MediaIDs == nil && form.Poll == nil { return errors.New("no status, media, or poll provided") @@ -244,7 +244,7 @@ func validateCreateStatus(form *advancedStatusCreateForm, config *config.Statuse return nil } -func parseVisibility(form *advancedStatusCreateForm, accountDefaultVis gtsmodel.Visibility, status *gtsmodel.Status) error { +func (m *Module) parseVisibility(form *advancedStatusCreateForm, accountDefaultVis gtsmodel.Visibility, status *gtsmodel.Status) error { // by default all flags are set to true gtsAdvancedVis := >smodel.VisibilityAdvanced{ Federated: true, @@ -261,7 +261,7 @@ func parseVisibility(form *advancedStatusCreateForm, accountDefaultVis gtsmodel. if form.VisibilityAdvanced != nil { gtsBasicVis = *form.VisibilityAdvanced } else if form.Visibility != "" { - gtsBasicVis = util.ParseGTSVisFromMastoVis(form.Visibility) + gtsBasicVis = m.tc.MastoVisToVis(form.Visibility) } else if accountDefaultVis != "" { gtsBasicVis = accountDefaultVis } else { diff --git a/internal/apimodule/status/statuscreate_test.go b/internal/apimodule/status/statuscreate_test.go index 8c2212b26..891e0a9f9 100644 --- a/internal/apimodule/status/statuscreate_test.go +++ b/internal/apimodule/status/statuscreate_test.go @@ -37,24 +37,24 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/distributor" "github.com/superseriousbusiness/gotosocial/internal/mastotypes" - mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) type StatusCreateTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config - db db.DB - log *logrus.Logger - storage storage.Storage - mastoConverter mastotypes.Converter - mediaHandler media.Handler - oauthServer oauth.Server - distributor distributor.Distributor + config *config.Config + db db.DB + log *logrus.Logger + storage storage.Storage + tc typeutils.TypeConverter + mediaHandler media.Handler + oauthServer oauth.Server + distributor distributor.Distributor // standard suite models testTokens map[string]*oauth.Token @@ -79,13 +79,13 @@ func (suite *StatusCreateTestSuite) SetupSuite() { suite.db = testrig.NewTestDB() suite.log = testrig.NewTestLog() suite.storage = testrig.NewTestStorage() - suite.mastoConverter = testrig.NewTestMastoConverter(suite.db) + suite.tc = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.oauthServer = testrig.NewTestOauthServer(suite.db) suite.distributor = testrig.NewTestDistributor() // setup module being tested - suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.tc, suite.distributor, suite.log).(*status.Module) } func (suite *StatusCreateTestSuite) TearDownSuite() { @@ -152,16 +152,16 @@ func (suite *StatusCreateTestSuite) TestPostNewStatus() { b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - statusReply := &mastomodel.Status{} + statusReply := &mastotypes.Status{} err = json.Unmarshal(b, statusReply) assert.NoError(suite.T(), err) assert.Equal(suite.T(), "hello hello", statusReply.SpoilerText) assert.Equal(suite.T(), "this is a brand new status! #helloworld", statusReply.Content) assert.True(suite.T(), statusReply.Sensitive) - assert.Equal(suite.T(), mastomodel.VisibilityPrivate, statusReply.Visibility) + assert.Equal(suite.T(), mastotypes.VisibilityPrivate, statusReply.Visibility) assert.Len(suite.T(), statusReply.Tags, 1) - assert.Equal(suite.T(), mastomodel.Tag{ + assert.Equal(suite.T(), mastotypes.Tag{ Name: "helloworld", URL: "http://localhost:8080/tags/helloworld", }, statusReply.Tags[0]) @@ -197,7 +197,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithEmoji() { b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - statusReply := &mastomodel.Status{} + statusReply := &mastotypes.Status{} err = json.Unmarshal(b, statusReply) assert.NoError(suite.T(), err) @@ -271,14 +271,14 @@ func (suite *StatusCreateTestSuite) TestReplyToLocalStatus() { b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - statusReply := &mastomodel.Status{} + statusReply := &mastotypes.Status{} err = json.Unmarshal(b, statusReply) assert.NoError(suite.T(), err) assert.Equal(suite.T(), "", statusReply.SpoilerText) assert.Equal(suite.T(), fmt.Sprintf("hello @%s this reply should work!", testrig.NewTestAccounts()["local_account_2"].Username), statusReply.Content) assert.False(suite.T(), statusReply.Sensitive) - assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility) + assert.Equal(suite.T(), mastotypes.VisibilityPublic, statusReply.Visibility) assert.Equal(suite.T(), testrig.NewTestStatuses()["local_account_2_status_1"].ID, statusReply.InReplyToID) assert.Equal(suite.T(), testrig.NewTestAccounts()["local_account_2"].ID, statusReply.InReplyToAccountID) assert.Len(suite.T(), statusReply.Mentions, 1) @@ -313,14 +313,14 @@ func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() { fmt.Println(string(b)) - statusReply := &mastomodel.Status{} + statusReply := &mastotypes.Status{} err = json.Unmarshal(b, statusReply) assert.NoError(suite.T(), err) assert.Equal(suite.T(), "", statusReply.SpoilerText) assert.Equal(suite.T(), "here's an image attachment", statusReply.Content) assert.False(suite.T(), statusReply.Sensitive) - assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility) + assert.Equal(suite.T(), mastotypes.VisibilityPublic, statusReply.Visibility) // there should be one media attachment assert.Len(suite.T(), statusReply.MediaAttachments, 1) @@ -331,7 +331,7 @@ func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() { assert.NoError(suite.T(), err) // convert it to a masto attachment - gtsAttachmentAsMasto, err := suite.mastoConverter.AttachmentToMasto(gtsAttachment) + gtsAttachmentAsMasto, err := suite.tc.AttachmentToMasto(gtsAttachment) assert.NoError(suite.T(), err) // compare it with what we have now diff --git a/internal/apimodule/status/statusdelete.go b/internal/apimodule/status/statusdelete.go index 01dfe81df..cb49a2b63 100644 --- a/internal/apimodule/status/statusdelete.go +++ b/internal/apimodule/status/statusdelete.go @@ -84,7 +84,7 @@ func (m *Module) StatusDELETEHandler(c *gin.Context) { } } - mastoStatus, err := m.mastoConverter.StatusToMasto(targetStatus, authed.Account, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := m.tc.StatusToMasto(targetStatus, authed.Account, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) if err != nil { l.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("status %s not found", targetStatusID)}) diff --git a/internal/apimodule/status/statusfave.go b/internal/apimodule/status/statusfave.go index 9ce68af09..8f17315b8 100644 --- a/internal/apimodule/status/statusfave.go +++ b/internal/apimodule/status/statusfave.go @@ -115,7 +115,7 @@ func (m *Module) StatusFavePOSTHandler(c *gin.Context) { } } - mastoStatus, err := m.mastoConverter.StatusToMasto(targetStatus, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := m.tc.StatusToMasto(targetStatus, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) if err != nil { l.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("status %s not found", targetStatusID)}) diff --git a/internal/apimodule/status/statusfave_test.go b/internal/apimodule/status/statusfave_test.go index 1c8a508ad..76285d6dd 100644 --- a/internal/apimodule/status/statusfave_test.go +++ b/internal/apimodule/status/statusfave_test.go @@ -37,24 +37,24 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/distributor" "github.com/superseriousbusiness/gotosocial/internal/mastotypes" - mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) type StatusFaveTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config - db db.DB - log *logrus.Logger - storage storage.Storage - mastoConverter mastotypes.Converter - mediaHandler media.Handler - oauthServer oauth.Server - distributor distributor.Distributor + config *config.Config + db db.DB + log *logrus.Logger + storage storage.Storage + tc typeutils.TypeConverter + mediaHandler media.Handler + oauthServer oauth.Server + distributor distributor.Distributor // standard suite models testTokens map[string]*oauth.Token @@ -80,13 +80,13 @@ func (suite *StatusFaveTestSuite) SetupSuite() { suite.db = testrig.NewTestDB() suite.log = testrig.NewTestLog() suite.storage = testrig.NewTestStorage() - suite.mastoConverter = testrig.NewTestMastoConverter(suite.db) + suite.tc = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.oauthServer = testrig.NewTestOauthServer(suite.db) suite.distributor = testrig.NewTestDistributor() // setup module being tested - suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.tc, suite.distributor, suite.log).(*status.Module) } func (suite *StatusFaveTestSuite) TearDownSuite() { @@ -152,14 +152,14 @@ func (suite *StatusFaveTestSuite) TestPostFave() { b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - statusReply := &mastomodel.Status{} + statusReply := &mastotypes.Status{} err = json.Unmarshal(b, statusReply) assert.NoError(suite.T(), err) assert.Equal(suite.T(), targetStatus.ContentWarning, statusReply.SpoilerText) assert.Equal(suite.T(), targetStatus.Content, statusReply.Content) assert.True(suite.T(), statusReply.Sensitive) - assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility) + assert.Equal(suite.T(), mastotypes.VisibilityPublic, statusReply.Visibility) assert.True(suite.T(), statusReply.Favourited) assert.Equal(suite.T(), 1, statusReply.FavouritesCount) } diff --git a/internal/apimodule/status/statusfavedby.go b/internal/apimodule/status/statusfavedby.go index 58236edc2..52c28069d 100644 --- a/internal/apimodule/status/statusfavedby.go +++ b/internal/apimodule/status/statusfavedby.go @@ -25,7 +25,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/oauth" ) @@ -117,7 +117,7 @@ func (m *Module) StatusFavedByGETHandler(c *gin.Context) { // now we can return the masto representation of those accounts mastoAccounts := []*mastotypes.Account{} for _, acc := range filteredAccounts { - mastoAccount, err := m.mastoConverter.AccountToMastoPublic(acc) + mastoAccount, err := m.tc.AccountToMastoPublic(acc) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return diff --git a/internal/apimodule/status/statusfavedby_test.go b/internal/apimodule/status/statusfavedby_test.go index 4156023f0..dae76a8fc 100644 --- a/internal/apimodule/status/statusfavedby_test.go +++ b/internal/apimodule/status/statusfavedby_test.go @@ -37,10 +37,10 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/distributor" "github.com/superseriousbusiness/gotosocial/internal/mastotypes" - mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) @@ -51,7 +51,7 @@ type StatusFavedByTestSuite struct { db db.DB log *logrus.Logger storage storage.Storage - mastoConverter mastotypes.Converter + mastoConverter typeutils.TypeConverter mediaHandler media.Handler oauthServer oauth.Server distributor distributor.Distributor @@ -76,7 +76,7 @@ func (suite *StatusFavedByTestSuite) SetupSuite() { suite.db = testrig.NewTestDB() suite.log = testrig.NewTestLog() suite.storage = testrig.NewTestStorage() - suite.mastoConverter = testrig.NewTestMastoConverter(suite.db) + suite.mastoConverter = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.oauthServer = testrig.NewTestOauthServer(suite.db) suite.distributor = testrig.NewTestDistributor() @@ -146,7 +146,7 @@ func (suite *StatusFavedByTestSuite) TestGetFavedBy() { b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - accts := []mastomodel.Account{} + accts := []mastotypes.Account{} err = json.Unmarshal(b, &accts) assert.NoError(suite.T(), err) diff --git a/internal/apimodule/status/statusget.go b/internal/apimodule/status/statusget.go index 76918c782..edaf2d53c 100644 --- a/internal/apimodule/status/statusget.go +++ b/internal/apimodule/status/statusget.go @@ -101,7 +101,7 @@ func (m *Module) StatusGETHandler(c *gin.Context) { } } - mastoStatus, err := m.mastoConverter.StatusToMasto(targetStatus, targetAccount, requestingAccount, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := m.tc.StatusToMasto(targetStatus, targetAccount, requestingAccount, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) if err != nil { l.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("status %s not found", targetStatusID)}) diff --git a/internal/apimodule/status/statusget_test.go b/internal/apimodule/status/statusget_test.go index bef51ee29..fb0d9dd7d 100644 --- a/internal/apimodule/status/statusget_test.go +++ b/internal/apimodule/status/statusget_test.go @@ -28,24 +28,24 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/distributor" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) type StatusGetTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config - db db.DB - log *logrus.Logger - storage storage.Storage - mastoConverter mastotypes.Converter - mediaHandler media.Handler - oauthServer oauth.Server - distributor distributor.Distributor + config *config.Config + db db.DB + log *logrus.Logger + storage storage.Storage + tc typeutils.TypeConverter + mediaHandler media.Handler + oauthServer oauth.Server + distributor distributor.Distributor // standard suite models testTokens map[string]*oauth.Token @@ -70,13 +70,13 @@ func (suite *StatusGetTestSuite) SetupSuite() { suite.db = testrig.NewTestDB() suite.log = testrig.NewTestLog() suite.storage = testrig.NewTestStorage() - suite.mastoConverter = testrig.NewTestMastoConverter(suite.db) + suite.tc = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.oauthServer = testrig.NewTestOauthServer(suite.db) suite.distributor = testrig.NewTestDistributor() // setup module being tested - suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.tc, suite.distributor, suite.log).(*status.Module) } func (suite *StatusGetTestSuite) TearDownSuite() { @@ -143,16 +143,16 @@ func (suite *StatusGetTestSuite) TestPostNewStatus() { // b, err := ioutil.ReadAll(result.Body) // assert.NoError(suite.T(), err) - // statusReply := &mastomodel.Status{} + // statusReply := &mastotypes.Status{} // err = json.Unmarshal(b, statusReply) // assert.NoError(suite.T(), err) // assert.Equal(suite.T(), "hello hello", statusReply.SpoilerText) // assert.Equal(suite.T(), "this is a brand new status! #helloworld", statusReply.Content) // assert.True(suite.T(), statusReply.Sensitive) - // assert.Equal(suite.T(), mastomodel.VisibilityPrivate, statusReply.Visibility) + // assert.Equal(suite.T(), mastotypes.VisibilityPrivate, statusReply.Visibility) // assert.Len(suite.T(), statusReply.Tags, 1) - // assert.Equal(suite.T(), mastomodel.Tag{ + // assert.Equal(suite.T(), mastotypes.Tag{ // Name: "helloworld", // URL: "http://localhost:8080/tags/helloworld", // }, statusReply.Tags[0]) diff --git a/internal/apimodule/status/statusunfave.go b/internal/apimodule/status/statusunfave.go index 9c06eaf92..b857611fe 100644 --- a/internal/apimodule/status/statusunfave.go +++ b/internal/apimodule/status/statusunfave.go @@ -115,7 +115,7 @@ func (m *Module) StatusUnfavePOSTHandler(c *gin.Context) { } } - mastoStatus, err := m.mastoConverter.StatusToMasto(targetStatus, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) + mastoStatus, err := m.tc.StatusToMasto(targetStatus, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) if err != nil { l.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("status %s not found", targetStatusID)}) diff --git a/internal/apimodule/status/statusunfave_test.go b/internal/apimodule/status/statusunfave_test.go index 3838ad9c5..51d2b39ac 100644 --- a/internal/apimodule/status/statusunfave_test.go +++ b/internal/apimodule/status/statusunfave_test.go @@ -37,24 +37,24 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/distributor" "github.com/superseriousbusiness/gotosocial/internal/mastotypes" - mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/testrig" ) type StatusUnfaveTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config - db db.DB - log *logrus.Logger - storage storage.Storage - mastoConverter mastotypes.Converter - mediaHandler media.Handler - oauthServer oauth.Server - distributor distributor.Distributor + config *config.Config + db db.DB + log *logrus.Logger + storage storage.Storage + tc typeutils.TypeConverter + mediaHandler media.Handler + oauthServer oauth.Server + distributor distributor.Distributor // standard suite models testTokens map[string]*oauth.Token @@ -80,13 +80,13 @@ func (suite *StatusUnfaveTestSuite) SetupSuite() { suite.db = testrig.NewTestDB() suite.log = testrig.NewTestLog() suite.storage = testrig.NewTestStorage() - suite.mastoConverter = testrig.NewTestMastoConverter(suite.db) + suite.tc = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.oauthServer = testrig.NewTestOauthServer(suite.db) suite.distributor = testrig.NewTestDistributor() // setup module being tested - suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.tc, suite.distributor, suite.log).(*status.Module) } func (suite *StatusUnfaveTestSuite) TearDownSuite() { @@ -153,14 +153,14 @@ func (suite *StatusUnfaveTestSuite) TestPostUnfave() { b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - statusReply := &mastomodel.Status{} + statusReply := &mastotypes.Status{} err = json.Unmarshal(b, statusReply) assert.NoError(suite.T(), err) assert.Equal(suite.T(), targetStatus.ContentWarning, statusReply.SpoilerText) assert.Equal(suite.T(), targetStatus.Content, statusReply.Content) assert.False(suite.T(), statusReply.Sensitive) - assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility) + assert.Equal(suite.T(), mastotypes.VisibilityPublic, statusReply.Visibility) assert.False(suite.T(), statusReply.Favourited) assert.Equal(suite.T(), 0, statusReply.FavouritesCount) } @@ -202,14 +202,14 @@ func (suite *StatusUnfaveTestSuite) TestPostAlreadyNotFaved() { b, err := ioutil.ReadAll(result.Body) assert.NoError(suite.T(), err) - statusReply := &mastomodel.Status{} + statusReply := &mastotypes.Status{} err = json.Unmarshal(b, statusReply) assert.NoError(suite.T(), err) assert.Equal(suite.T(), targetStatus.ContentWarning, statusReply.SpoilerText) assert.Equal(suite.T(), targetStatus.Content, statusReply.Content) assert.True(suite.T(), statusReply.Sensitive) - assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility) + assert.Equal(suite.T(), mastotypes.VisibilityPublic, statusReply.Visibility) assert.False(suite.T(), statusReply.Favourited) assert.Equal(suite.T(), 0, statusReply.FavouritesCount) } diff --git a/internal/federation/protocol.go b/internal/federation/protocol.go index 158afe184..0274264ce 100644 --- a/internal/federation/protocol.go +++ b/internal/federation/protocol.go @@ -150,15 +150,7 @@ func (f *Federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr } l.Tracef("parsed username %s from %s", username, r.URL.String()) - newContext, authed, err := validateInboundFederationRequest(ctx, r, f.db, username, f.transportController) - - if err != nil { - l.Debug(err) - } - - return newContext, authed, err - - + return validateInboundFederationRequest(ctx, r, f.db, username, f.transportController) } // Blocked should determine whether to permit a set of actors given by diff --git a/internal/gotosocial/actions.go b/internal/gotosocial/actions.go index 195cbb68d..5f7ad788f 100644 --- a/internal/gotosocial/actions.go +++ b/internal/gotosocial/actions.go @@ -41,11 +41,11 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/distributor" "github.com/superseriousbusiness/gotosocial/internal/federation" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/router" "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) // Run creates and starts a gotosocial server @@ -74,16 +74,16 @@ var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logr } // build converters and util - mastoConverter := mastotypes.New(c, dbService) + ic := typeutils.NewConverter(c, dbService) // build client api modules authModule := auth.New(oauthServer, dbService, log) - accountModule := account.New(c, dbService, oauthServer, mediaHandler, mastoConverter, log) - appsModule := app.New(oauthServer, dbService, mastoConverter, log) - mm := mediaModule.New(dbService, mediaHandler, mastoConverter, c, log) + accountModule := account.New(c, dbService, oauthServer, mediaHandler, ic, log) + appsModule := app.New(oauthServer, dbService, ic, log) + mm := mediaModule.New(dbService, mediaHandler, ic, c, log) fileServerModule := fileserver.New(c, dbService, storageBackend, log) - adminModule := admin.New(c, dbService, mediaHandler, mastoConverter, log) - statusModule := status.New(c, dbService, mediaHandler, mastoConverter, distributor, log) + adminModule := admin.New(c, dbService, mediaHandler, ic, log) + statusModule := status.New(c, dbService, mediaHandler, ic, distributor, log) securityModule := security.New(c, log) apiModules := []apimodule.ClientAPIModule{ diff --git a/internal/mastotypes/mastomodel/README.md b/internal/mastotypes/README.md similarity index 100% rename from internal/mastotypes/mastomodel/README.md rename to internal/mastotypes/README.md diff --git a/internal/mastotypes/mastomodel/account.go b/internal/mastotypes/account.go similarity index 100% rename from internal/mastotypes/mastomodel/account.go rename to internal/mastotypes/account.go diff --git a/internal/mastotypes/mastomodel/activity.go b/internal/mastotypes/activity.go similarity index 100% rename from internal/mastotypes/mastomodel/activity.go rename to internal/mastotypes/activity.go diff --git a/internal/mastotypes/mastomodel/admin.go b/internal/mastotypes/admin.go similarity index 100% rename from internal/mastotypes/mastomodel/admin.go rename to internal/mastotypes/admin.go diff --git a/internal/mastotypes/mastomodel/announcement.go b/internal/mastotypes/announcement.go similarity index 100% rename from internal/mastotypes/mastomodel/announcement.go rename to internal/mastotypes/announcement.go diff --git a/internal/mastotypes/mastomodel/announcementreaction.go b/internal/mastotypes/announcementreaction.go similarity index 100% rename from internal/mastotypes/mastomodel/announcementreaction.go rename to internal/mastotypes/announcementreaction.go diff --git a/internal/mastotypes/mastomodel/application.go b/internal/mastotypes/application.go similarity index 100% rename from internal/mastotypes/mastomodel/application.go rename to internal/mastotypes/application.go diff --git a/internal/mastotypes/mastomodel/attachment.go b/internal/mastotypes/attachment.go similarity index 100% rename from internal/mastotypes/mastomodel/attachment.go rename to internal/mastotypes/attachment.go diff --git a/internal/mastotypes/mastomodel/card.go b/internal/mastotypes/card.go similarity index 100% rename from internal/mastotypes/mastomodel/card.go rename to internal/mastotypes/card.go diff --git a/internal/mastotypes/mastomodel/context.go b/internal/mastotypes/context.go similarity index 100% rename from internal/mastotypes/mastomodel/context.go rename to internal/mastotypes/context.go diff --git a/internal/mastotypes/mastomodel/conversation.go b/internal/mastotypes/conversation.go similarity index 100% rename from internal/mastotypes/mastomodel/conversation.go rename to internal/mastotypes/conversation.go diff --git a/internal/mastotypes/mastomodel/emoji.go b/internal/mastotypes/emoji.go similarity index 100% rename from internal/mastotypes/mastomodel/emoji.go rename to internal/mastotypes/emoji.go diff --git a/internal/mastotypes/mastomodel/error.go b/internal/mastotypes/error.go similarity index 100% rename from internal/mastotypes/mastomodel/error.go rename to internal/mastotypes/error.go diff --git a/internal/mastotypes/mastomodel/featuredtag.go b/internal/mastotypes/featuredtag.go similarity index 100% rename from internal/mastotypes/mastomodel/featuredtag.go rename to internal/mastotypes/featuredtag.go diff --git a/internal/mastotypes/mastomodel/field.go b/internal/mastotypes/field.go similarity index 100% rename from internal/mastotypes/mastomodel/field.go rename to internal/mastotypes/field.go diff --git a/internal/mastotypes/mastomodel/filter.go b/internal/mastotypes/filter.go similarity index 100% rename from internal/mastotypes/mastomodel/filter.go rename to internal/mastotypes/filter.go diff --git a/internal/mastotypes/mastomodel/history.go b/internal/mastotypes/history.go similarity index 100% rename from internal/mastotypes/mastomodel/history.go rename to internal/mastotypes/history.go diff --git a/internal/mastotypes/mastomodel/identityproof.go b/internal/mastotypes/identityproof.go similarity index 100% rename from internal/mastotypes/mastomodel/identityproof.go rename to internal/mastotypes/identityproof.go diff --git a/internal/mastotypes/mastomodel/instance.go b/internal/mastotypes/instance.go similarity index 100% rename from internal/mastotypes/mastomodel/instance.go rename to internal/mastotypes/instance.go diff --git a/internal/mastotypes/mastomodel/list.go b/internal/mastotypes/list.go similarity index 100% rename from internal/mastotypes/mastomodel/list.go rename to internal/mastotypes/list.go diff --git a/internal/mastotypes/mastomodel/marker.go b/internal/mastotypes/marker.go similarity index 100% rename from internal/mastotypes/mastomodel/marker.go rename to internal/mastotypes/marker.go diff --git a/internal/mastotypes/mastomodel/mention.go b/internal/mastotypes/mention.go similarity index 100% rename from internal/mastotypes/mastomodel/mention.go rename to internal/mastotypes/mention.go diff --git a/internal/mastotypes/mock_Converter.go b/internal/mastotypes/mock_Converter.go deleted file mode 100644 index 732d933ae..000000000 --- a/internal/mastotypes/mock_Converter.go +++ /dev/null @@ -1,148 +0,0 @@ -// Code generated by mockery v2.7.4. DO NOT EDIT. - -package mastotypes - -import ( - mock "github.com/stretchr/testify/mock" - gtsmodel "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" -) - -// MockConverter is an autogenerated mock type for the Converter type -type MockConverter struct { - mock.Mock -} - -// AccountToMastoPublic provides a mock function with given fields: account -func (_m *MockConverter) AccountToMastoPublic(account *gtsmodel.Account) (*mastotypes.Account, error) { - ret := _m.Called(account) - - var r0 *mastotypes.Account - if rf, ok := ret.Get(0).(func(*gtsmodel.Account) *mastotypes.Account); ok { - r0 = rf(account) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*mastotypes.Account) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(*gtsmodel.Account) error); ok { - r1 = rf(account) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// AccountToMastoSensitive provides a mock function with given fields: account -func (_m *MockConverter) AccountToMastoSensitive(account *gtsmodel.Account) (*mastotypes.Account, error) { - ret := _m.Called(account) - - var r0 *mastotypes.Account - if rf, ok := ret.Get(0).(func(*gtsmodel.Account) *mastotypes.Account); ok { - r0 = rf(account) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*mastotypes.Account) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(*gtsmodel.Account) error); ok { - r1 = rf(account) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// AppToMastoPublic provides a mock function with given fields: application -func (_m *MockConverter) AppToMastoPublic(application *gtsmodel.Application) (*mastotypes.Application, error) { - ret := _m.Called(application) - - var r0 *mastotypes.Application - if rf, ok := ret.Get(0).(func(*gtsmodel.Application) *mastotypes.Application); ok { - r0 = rf(application) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*mastotypes.Application) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(*gtsmodel.Application) error); ok { - r1 = rf(application) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// AppToMastoSensitive provides a mock function with given fields: application -func (_m *MockConverter) AppToMastoSensitive(application *gtsmodel.Application) (*mastotypes.Application, error) { - ret := _m.Called(application) - - var r0 *mastotypes.Application - if rf, ok := ret.Get(0).(func(*gtsmodel.Application) *mastotypes.Application); ok { - r0 = rf(application) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*mastotypes.Application) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(*gtsmodel.Application) error); ok { - r1 = rf(application) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// AttachmentToMasto provides a mock function with given fields: attachment -func (_m *MockConverter) AttachmentToMasto(attachment *gtsmodel.MediaAttachment) (mastotypes.Attachment, error) { - ret := _m.Called(attachment) - - var r0 mastotypes.Attachment - if rf, ok := ret.Get(0).(func(*gtsmodel.MediaAttachment) mastotypes.Attachment); ok { - r0 = rf(attachment) - } else { - r0 = ret.Get(0).(mastotypes.Attachment) - } - - var r1 error - if rf, ok := ret.Get(1).(func(*gtsmodel.MediaAttachment) error); ok { - r1 = rf(attachment) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MentionToMasto provides a mock function with given fields: m -func (_m *MockConverter) MentionToMasto(m *gtsmodel.Mention) (mastotypes.Mention, error) { - ret := _m.Called(m) - - var r0 mastotypes.Mention - if rf, ok := ret.Get(0).(func(*gtsmodel.Mention) mastotypes.Mention); ok { - r0 = rf(m) - } else { - r0 = ret.Get(0).(mastotypes.Mention) - } - - var r1 error - if rf, ok := ret.Get(1).(func(*gtsmodel.Mention) error); ok { - r1 = rf(m) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} diff --git a/internal/mastotypes/mastomodel/notification.go b/internal/mastotypes/notification.go similarity index 100% rename from internal/mastotypes/mastomodel/notification.go rename to internal/mastotypes/notification.go diff --git a/internal/mastotypes/mastomodel/oauth.go b/internal/mastotypes/oauth.go similarity index 100% rename from internal/mastotypes/mastomodel/oauth.go rename to internal/mastotypes/oauth.go diff --git a/internal/mastotypes/mastomodel/poll.go b/internal/mastotypes/poll.go similarity index 100% rename from internal/mastotypes/mastomodel/poll.go rename to internal/mastotypes/poll.go diff --git a/internal/mastotypes/mastomodel/preferences.go b/internal/mastotypes/preferences.go similarity index 100% rename from internal/mastotypes/mastomodel/preferences.go rename to internal/mastotypes/preferences.go diff --git a/internal/mastotypes/mastomodel/pushsubscription.go b/internal/mastotypes/pushsubscription.go similarity index 100% rename from internal/mastotypes/mastomodel/pushsubscription.go rename to internal/mastotypes/pushsubscription.go diff --git a/internal/mastotypes/mastomodel/relationship.go b/internal/mastotypes/relationship.go similarity index 100% rename from internal/mastotypes/mastomodel/relationship.go rename to internal/mastotypes/relationship.go diff --git a/internal/mastotypes/mastomodel/results.go b/internal/mastotypes/results.go similarity index 100% rename from internal/mastotypes/mastomodel/results.go rename to internal/mastotypes/results.go diff --git a/internal/mastotypes/mastomodel/scheduledstatus.go b/internal/mastotypes/scheduledstatus.go similarity index 100% rename from internal/mastotypes/mastomodel/scheduledstatus.go rename to internal/mastotypes/scheduledstatus.go diff --git a/internal/mastotypes/mastomodel/source.go b/internal/mastotypes/source.go similarity index 100% rename from internal/mastotypes/mastomodel/source.go rename to internal/mastotypes/source.go diff --git a/internal/mastotypes/mastomodel/status.go b/internal/mastotypes/status.go similarity index 100% rename from internal/mastotypes/mastomodel/status.go rename to internal/mastotypes/status.go diff --git a/internal/mastotypes/mastomodel/tag.go b/internal/mastotypes/tag.go similarity index 100% rename from internal/mastotypes/mastomodel/tag.go rename to internal/mastotypes/tag.go diff --git a/internal/mastotypes/mastomodel/token.go b/internal/mastotypes/token.go similarity index 100% rename from internal/mastotypes/mastomodel/token.go rename to internal/mastotypes/token.go diff --git a/internal/transport/controller.go b/internal/transport/controller.go index a4654dfe8..525141025 100644 --- a/internal/transport/controller.go +++ b/internal/transport/controller.go @@ -41,7 +41,7 @@ type controller struct { } // NewController returns an implementation of the Controller interface for creating new transports -func NewController(config *config.Config,clock pub.Clock, client pub.HttpClient, log *logrus.Logger) Controller { +func NewController(config *config.Config, clock pub.Clock, client pub.HttpClient, log *logrus.Logger) Controller { return &controller{ config: config, clock: clock, @@ -50,6 +50,7 @@ func NewController(config *config.Config,clock pub.Clock, client pub.HttpClient, } } +// NewTransport returns a new http signature transport with the given public key id (a URL), and the given private key. func (c *controller) NewTransport(pubKeyID string, privkey crypto.PrivateKey) (pub.Transport, error) { prefs := []httpsig.Algorithm{httpsig.RSA_SHA256, httpsig.RSA_SHA512} digestAlgo := httpsig.DigestSha256 diff --git a/internal/mastotypes/converter.go b/internal/typeutils/converter.go similarity index 95% rename from internal/mastotypes/converter.go rename to internal/typeutils/converter.go index e689b62da..5116e9abc 100644 --- a/internal/mastotypes/converter.go +++ b/internal/typeutils/converter.go @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package mastotypes +package typeutils import ( "fmt" @@ -25,13 +25,15 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" - "github.com/superseriousbusiness/gotosocial/internal/util" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" ) -// Converter is an interface for the common action of converting between mastotypes (frontend, serializable) models and internal gts models used in the database. +// TypeConverter is an interface for the common action of converting between mastotypes (frontend, serializable) models, +// internal gts models used in the database, and models used in federation. +// // It requires access to the database because many of the conversions require pulling out database entries and counting them etc. -type Converter interface { +// That said, it *absolutely should not* manipulate database entries in any way, only examine them. +type TypeConverter interface { // AccountToMastoSensitive takes a db model account as a param, and returns a populated mastotype account, or an error // if something goes wrong. The returned account should be ready to serialize on an API level, and may have sensitive fields, // so serve it only to an authorized user who should have permission to see it. @@ -66,6 +68,12 @@ type Converter interface { // StatusToMasto converts a gts model status into its mastodon (frontend) representation for serialization on the API. StatusToMasto(s *gtsmodel.Status, targetAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account, boostOfAccount *gtsmodel.Account, replyToAccount *gtsmodel.Account, reblogOfStatus *gtsmodel.Status) (*mastotypes.Status, error) + + // VisToMasto converts a gts visibility into its mastodon equivalent + VisToMasto(m gtsmodel.Visibility) mastotypes.Visibility + + // MastoVisToVis converts a mastodon visibility into its gts equivalent. + MastoVisToVis(m mastotypes.Visibility) gtsmodel.Visibility } type converter struct { @@ -73,8 +81,8 @@ type converter struct { db db.DB } -// New returns a new Converter -func New(config *config.Config, db db.DB) Converter { +// NewConverter returns a new Converter +func NewConverter(config *config.Config, db db.DB) TypeConverter { return &converter{ config: config, db: db, @@ -103,7 +111,7 @@ func (c *converter) AccountToMastoSensitive(a *gtsmodel.Account) (*mastotypes.Ac } mastoAccount.Source = &mastotypes.Source{ - Privacy: util.ParseMastoVisFromGTSVis(a.Privacy), + Privacy: c.VisToMasto(a.Privacy), Sensitive: a.Sensitive, Language: a.Language, Note: a.Note, @@ -517,7 +525,7 @@ func (c *converter) StatusToMasto( InReplyToAccountID: s.InReplyToAccountID, Sensitive: s.Sensitive, SpoilerText: s.ContentWarning, - Visibility: util.ParseMastoVisFromGTSVis(s.Visibility), + Visibility: c.VisToMasto(s.Visibility), Language: s.Language, URI: s.URI, URL: s.URL, diff --git a/internal/util/visibility.go b/internal/typeutils/visibility.go similarity index 78% rename from internal/util/visibility.go rename to internal/typeutils/visibility.go index c847ef980..71be92f5e 100644 --- a/internal/util/visibility.go +++ b/internal/typeutils/visibility.go @@ -16,15 +16,15 @@ along with this program. If not, see . */ -package util +package typeutils import ( "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" - mastotypes "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" + "github.com/superseriousbusiness/gotosocial/internal/mastotypes" ) -// ParseGTSVisFromMastoVis converts a mastodon visibility into its gts equivalent. -func ParseGTSVisFromMastoVis(m mastotypes.Visibility) gtsmodel.Visibility { +// MastoVisToVis converts a mastodon visibility into its gts equivalent. +func (c *converter) MastoVisToVis(m mastotypes.Visibility) gtsmodel.Visibility { switch m { case mastotypes.VisibilityPublic: return gtsmodel.VisibilityPublic @@ -38,8 +38,8 @@ func ParseGTSVisFromMastoVis(m mastotypes.Visibility) gtsmodel.Visibility { return "" } -// ParseMastoVisFromGTSVis converts a gts visibility into its mastodon equivalent -func ParseMastoVisFromGTSVis(m gtsmodel.Visibility) mastotypes.Visibility { +// VisToMasto converts a gts visibility into its mastodon equivalent +func (c *converter) VisToMasto(m gtsmodel.Visibility) mastotypes.Visibility { switch m { case gtsmodel.VisibilityPublic: return mastotypes.VisibilityPublic diff --git a/internal/util/uri.go b/internal/util/uri.go index 217352435..a4b5848df 100644 --- a/internal/util/uri.go +++ b/internal/util/uri.go @@ -56,7 +56,7 @@ const ( // APActivityKey can be used to set and retrieve the actual go-fed pub.Activity within a context. APActivityKey APContextKey = "activity" // APUsernameKey can be used to set and retrieve the username of the user being interacted with. - APUsernameKey APContextKey = "username" + APUsernameKey APContextKey = "username" // APRequestingHostKey can be used to set and retrieve the host of an incoming federation request. APRequestingHostKey APContextKey = "requestingHost" // APRequestingAccountKey can be used to set and retrieve the account of an incoming federation request. diff --git a/testrig/actions.go b/testrig/actions.go index 4387f4269..c2615451c 100644 --- a/testrig/actions.go +++ b/testrig/actions.go @@ -53,7 +53,7 @@ var Run action.GTSAction = func(ctx context.Context, _ *config.Config, log *logr if err := distributor.Start(); err != nil { return fmt.Errorf("error starting distributor: %s", err) } - mastoConverter := NewTestMastoConverter(dbService) + mastoConverter := NewTestTypeConverter(dbService) c := NewTestConfig() diff --git a/testrig/samplenote.json b/testrig/samplenote.json new file mode 100644 index 000000000..45b5f7e43 --- /dev/null +++ b/testrig/samplenote.json @@ -0,0 +1,76 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + { + "ostatus": "http://ostatus.org#", + "atomUri": "ostatus:atomUri", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "sensitive": "as:sensitive", + "toot": "http://joinmastodon.org/ns#", + "votersCount": "toot:votersCount", + "blurhash": "toot:blurhash", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + } + } + ], + "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106124968746291389/activity", + "type": "Create", + "actor": "https://ondergrond.org/users/dumpsterqueer", + "published": "2021-04-25T08:15:12Z", + "to": [ + "https://ondergrond.org/users/dumpsterqueer/followers" + ], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "object": { + "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106124968746291389", + "type": "Note", + "summary": "selfie", + "inReplyTo": null, + "published": "2021-04-25T08:15:12Z", + "url": "https://ondergrond.org/@dumpsterqueer/106124968746291389", + "attributedTo": "https://ondergrond.org/users/dumpsterqueer", + "to": [ + "https://ondergrond.org/users/dumpsterqueer/followers" + ], + "cc": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "sensitive": true, + "atomUri": "https://ondergrond.org/users/dumpsterqueer/statuses/106124968746291389", + "inReplyToAtomUri": null, + "conversation": "tag:ondergrond.org,2021-04-25:objectId=1058287:objectType=Conversation", + "content": "\u003cp\u003egood morning i\u0026apos;m up and at \u0026apos;em\u003c/p\u003e", + "contentMap": { + "en": "\u003cp\u003egood morning i\u0026apos;m up and at \u0026apos;em\u003c/p\u003e" + }, + "attachment": [ + { + "type": "Document", + "mediaType": "image/jpeg", + "url": "https://ondergrond.org/system/media_attachments/files/106/124/965/963/257/833/original/84bade009d44f0e7.jpg", + "name": "me sitting in front of my computer, looking a bit tired but overall rather cute. I've got a green and grey plaid shirt on which is very wrinked.", + "blurhash": "UXF6Ur_N-=t7~p-pt7RjayayRkRkRjWVafof", + "focalPoint": [ + 0.0, + 0.52 + ] + } + ], + "tag": [], + "replies": { + "id": "https://ondergrond.org/users/dumpsterqueer/statuses/106124968746291389/replies", + "type": "Collection", + "first": { + "type": "CollectionPage", + "next": "https://ondergrond.org/users/dumpsterqueer/statuses/106124968746291389/replies?only_other_accounts=true\u0026page=true", + "partOf": "https://ondergrond.org/users/dumpsterqueer/statuses/106124968746291389/replies", + "items": [] + } + } + } +} diff --git a/testrig/mastoconverter.go b/testrig/typeconverter.go similarity index 75% rename from testrig/mastoconverter.go rename to testrig/typeconverter.go index 10bdbdc95..9d49e6c99 100644 --- a/testrig/mastoconverter.go +++ b/testrig/typeconverter.go @@ -20,10 +20,10 @@ package testrig import ( "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/mastotypes" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) -// NewTestMastoConverter returned a mastotypes converter with the given db and the default test config -func NewTestMastoConverter(db db.DB) mastotypes.Converter { - return mastotypes.New(NewTestConfig(), db) +// NewTestTypeConverter returned a type converter with the given db and the default test config +func NewTestTypeConverter(db db.DB) typeutils.TypeConverter { + return typeutils.NewConverter(NewTestConfig(), db) }