diff options
Diffstat (limited to 'internal/apimodule/status')
-rw-r--r-- | internal/apimodule/status/status.go | 34 | ||||
-rw-r--r-- | internal/apimodule/status/statuscreate.go | 19 | ||||
-rw-r--r-- | internal/apimodule/status/statusdelete.go | 3 | ||||
-rw-r--r-- | internal/apimodule/status/statusfave.go | 3 | ||||
-rw-r--r-- | internal/apimodule/status/statusfavedby.go | 3 | ||||
-rw-r--r-- | internal/apimodule/status/statusget.go | 3 | ||||
-rw-r--r-- | internal/apimodule/status/statusunfave.go | 3 | ||||
-rw-r--r-- | internal/apimodule/status/test/statuscreate_test.go | 16 | ||||
-rw-r--r-- | internal/apimodule/status/test/statusfave_test.go | 10 | ||||
-rw-r--r-- | internal/apimodule/status/test/statusfavedby_test.go | 8 | ||||
-rw-r--r-- | internal/apimodule/status/test/statusget_test.go | 6 | ||||
-rw-r--r-- | internal/apimodule/status/test/statusunfave_test.go | 10 |
12 files changed, 71 insertions, 47 deletions
diff --git a/internal/apimodule/status/status.go b/internal/apimodule/status/status.go index e65293b62..73a1b5847 100644 --- a/internal/apimodule/status/status.go +++ b/internal/apimodule/status/status.go @@ -36,42 +36,60 @@ import ( ) const ( + // IDKey is for status UUIDs IDKey = "id" + // BasePath is the base path for serving the status API BasePath = "/api/v1/statuses" + // BasePathWithID is just the base path with the ID key in it. + // Use this anywhere you need to know the ID of the status being queried. BasePathWithID = BasePath + "/:" + IDKey + // ContextPath is used for fetching context of posts ContextPath = BasePathWithID + "/context" + // FavouritedPath is for seeing who's faved a given status FavouritedPath = BasePathWithID + "/favourited_by" + // FavouritePath is for posting a fave on a status FavouritePath = BasePathWithID + "/favourite" + // UnfavouritePath is for removing a fave from a status UnfavouritePath = BasePathWithID + "/unfavourite" + // RebloggedPath is for seeing who's boosted a given status RebloggedPath = BasePathWithID + "/reblogged_by" + // ReblogPath is for boosting/reblogging a given status ReblogPath = BasePathWithID + "/reblog" + // UnreblogPath is for undoing a boost/reblog of a given status UnreblogPath = BasePathWithID + "/unreblog" + // BookmarkPath is for creating a bookmark on a given status BookmarkPath = BasePathWithID + "/bookmark" + // UnbookmarkPath is for removing a bookmark from a given status UnbookmarkPath = BasePathWithID + "/unbookmark" + // MutePath is for muting a given status so that notifications will no longer be received about it. MutePath = BasePathWithID + "/mute" + // UnmutePath is for undoing an existing mute UnmutePath = BasePathWithID + "/unmute" + // PinPath is for pinning a status to an account profile so that it's the first thing people see PinPath = BasePathWithID + "/pin" + // UnpinPath is for undoing a pin and returning a status to the ever-swirling drain of time and entropy UnpinPath = BasePathWithID + "/unpin" ) -type StatusModule struct { +// 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.MediaHandler + mediaHandler media.Handler mastoConverter mastotypes.Converter distributor distributor.Distributor log *logrus.Logger } // New returns a new account module -func New(config *config.Config, db db.DB, mediaHandler media.MediaHandler, mastoConverter mastotypes.Converter, distributor distributor.Distributor, log *logrus.Logger) apimodule.ClientAPIModule { - return &StatusModule{ +func New(config *config.Config, db db.DB, mediaHandler media.Handler, mastoConverter mastotypes.Converter, distributor distributor.Distributor, log *logrus.Logger) apimodule.ClientAPIModule { + return &Module{ config: config, db: db, mediaHandler: mediaHandler, @@ -82,7 +100,7 @@ func New(config *config.Config, db db.DB, mediaHandler media.MediaHandler, masto } // Route attaches all routes from this module to the given router -func (m *StatusModule) Route(r router.Router) error { +func (m *Module) Route(r router.Router) error { r.AttachHandler(http.MethodPost, BasePath, m.StatusCreatePOSTHandler) r.AttachHandler(http.MethodDelete, BasePathWithID, m.StatusDELETEHandler) @@ -93,7 +111,8 @@ func (m *StatusModule) Route(r router.Router) error { return nil } -func (m *StatusModule) CreateTables(db db.DB) error { +// CreateTables populates necessary tables in the given DB +func (m *Module) CreateTables(db db.DB) error { models := []interface{}{ >smodel.User{}, >smodel.Account{}, @@ -121,7 +140,8 @@ func (m *StatusModule) CreateTables(db db.DB) error { return nil } -func (m *StatusModule) muxHandler(c *gin.Context) { +// muxHandler is a little workaround to overcome the limitations of Gin +func (m *Module) muxHandler(c *gin.Context) { m.log.Debug("entering mux handler") ru := c.Request.RequestURI diff --git a/internal/apimodule/status/statuscreate.go b/internal/apimodule/status/statuscreate.go index ce1cc6da7..97354e767 100644 --- a/internal/apimodule/status/statuscreate.go +++ b/internal/apimodule/status/statuscreate.go @@ -53,7 +53,8 @@ type advancedVisibilityFlagsForm struct { Likeable *bool `form:"likeable"` } -func (m *StatusModule) StatusCreatePOSTHandler(c *gin.Context) { +// StatusCreatePOSTHandler deals with the creation of new statuses +func (m *Module) StatusCreatePOSTHandler(c *gin.Context) { l := m.log.WithField("func", "statusCreatePOSTHandler") authed, err := oauth.MustAuth(c, true, true, true, true) // posting a status is serious business so we want *everything* if err != nil { @@ -318,7 +319,7 @@ func parseVisibility(form *advancedStatusCreateForm, accountDefaultVis gtsmodel. return nil } -func (m *StatusModule) parseReplyToID(form *advancedStatusCreateForm, thisAccountID string, status *gtsmodel.Status) error { +func (m *Module) parseReplyToID(form *advancedStatusCreateForm, thisAccountID string, status *gtsmodel.Status) error { if form.InReplyToID == "" { return nil } @@ -336,9 +337,8 @@ func (m *StatusModule) parseReplyToID(form *advancedStatusCreateForm, thisAccoun if err := m.db.GetByID(form.InReplyToID, repliedStatus); err != nil { if _, ok := err.(db.ErrNoEntries); ok { return fmt.Errorf("status with id %s not replyable because it doesn't exist", form.InReplyToID) - } else { - return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) } + return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) } if !repliedStatus.VisibilityAdvanced.Replyable { @@ -349,9 +349,8 @@ func (m *StatusModule) parseReplyToID(form *advancedStatusCreateForm, thisAccoun if err := m.db.GetByID(repliedStatus.AccountID, repliedAccount); err != nil { if _, ok := err.(db.ErrNoEntries); ok { return fmt.Errorf("status with id %s not replyable because account id %s is not known", form.InReplyToID, repliedStatus.AccountID) - } else { - return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) } + return fmt.Errorf("status with id %s not replyable: %s", form.InReplyToID, err) } // check if a block exists if blocked, err := m.db.Blocked(thisAccountID, repliedAccount.ID); err != nil { @@ -367,7 +366,7 @@ func (m *StatusModule) parseReplyToID(form *advancedStatusCreateForm, thisAccoun return nil } -func (m *StatusModule) parseMediaIDs(form *advancedStatusCreateForm, thisAccountID string, status *gtsmodel.Status) error { +func (m *Module) parseMediaIDs(form *advancedStatusCreateForm, thisAccountID string, status *gtsmodel.Status) error { if form.MediaIDs == nil { return nil } @@ -408,7 +407,7 @@ func parseLanguage(form *advancedStatusCreateForm, accountDefaultLanguage string return nil } -func (m *StatusModule) parseMentions(form *advancedStatusCreateForm, accountID string, status *gtsmodel.Status) error { +func (m *Module) parseMentions(form *advancedStatusCreateForm, accountID string, status *gtsmodel.Status) error { menchies := []string{} gtsMenchies, err := m.db.MentionStringsToMentions(util.DeriveMentions(form.Status), accountID, status.ID) if err != nil { @@ -427,7 +426,7 @@ func (m *StatusModule) parseMentions(form *advancedStatusCreateForm, accountID s return nil } -func (m *StatusModule) parseTags(form *advancedStatusCreateForm, accountID string, status *gtsmodel.Status) error { +func (m *Module) parseTags(form *advancedStatusCreateForm, accountID string, status *gtsmodel.Status) error { tags := []string{} gtsTags, err := m.db.TagStringsToTags(util.DeriveHashtags(form.Status), accountID, status.ID) if err != nil { @@ -446,7 +445,7 @@ func (m *StatusModule) parseTags(form *advancedStatusCreateForm, accountID strin return nil } -func (m *StatusModule) parseEmojis(form *advancedStatusCreateForm, accountID string, status *gtsmodel.Status) error { +func (m *Module) parseEmojis(form *advancedStatusCreateForm, accountID string, status *gtsmodel.Status) error { emojis := []string{} gtsEmojis, err := m.db.EmojiStringsToEmojis(util.DeriveEmojis(form.Status), accountID, status.ID) if err != nil { diff --git a/internal/apimodule/status/statusdelete.go b/internal/apimodule/status/statusdelete.go index f67d035d8..01dfe81df 100644 --- a/internal/apimodule/status/statusdelete.go +++ b/internal/apimodule/status/statusdelete.go @@ -29,7 +29,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) -func (m *StatusModule) StatusDELETEHandler(c *gin.Context) { +// StatusDELETEHandler verifies and handles deletion of a status +func (m *Module) StatusDELETEHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "StatusDELETEHandler", "request_uri": c.Request.RequestURI, diff --git a/internal/apimodule/status/statusfave.go b/internal/apimodule/status/statusfave.go index de475b905..9ce68af09 100644 --- a/internal/apimodule/status/statusfave.go +++ b/internal/apimodule/status/statusfave.go @@ -29,7 +29,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) -func (m *StatusModule) StatusFavePOSTHandler(c *gin.Context) { +// StatusFavePOSTHandler handles fave requests against a given status ID +func (m *Module) StatusFavePOSTHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "StatusFavePOSTHandler", "request_uri": c.Request.RequestURI, diff --git a/internal/apimodule/status/statusfavedby.go b/internal/apimodule/status/statusfavedby.go index 76a50b2ca..58236edc2 100644 --- a/internal/apimodule/status/statusfavedby.go +++ b/internal/apimodule/status/statusfavedby.go @@ -29,7 +29,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) -func (m *StatusModule) StatusFavedByGETHandler(c *gin.Context) { +// StatusFavedByGETHandler is for serving a list of accounts that have faved a given status +func (m *Module) StatusFavedByGETHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "statusGETHandler", "request_uri": c.Request.RequestURI, diff --git a/internal/apimodule/status/statusget.go b/internal/apimodule/status/statusget.go index ed2e89159..76918c782 100644 --- a/internal/apimodule/status/statusget.go +++ b/internal/apimodule/status/statusget.go @@ -28,7 +28,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) -func (m *StatusModule) StatusGETHandler(c *gin.Context) { +// StatusGETHandler is for handling requests to just get one status based on its ID +func (m *Module) StatusGETHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "statusGETHandler", "request_uri": c.Request.RequestURI, diff --git a/internal/apimodule/status/statusunfave.go b/internal/apimodule/status/statusunfave.go index 61ffd8e4c..9c06eaf92 100644 --- a/internal/apimodule/status/statusunfave.go +++ b/internal/apimodule/status/statusunfave.go @@ -29,7 +29,8 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) -func (m *StatusModule) StatusUnfavePOSTHandler(c *gin.Context) { +// StatusUnfavePOSTHandler is for undoing a fave on a status with a given ID +func (m *Module) StatusUnfavePOSTHandler(c *gin.Context) { l := m.log.WithFields(logrus.Fields{ "func": "StatusUnfavePOSTHandler", "request_uri": c.Request.RequestURI, diff --git a/internal/apimodule/status/test/statuscreate_test.go b/internal/apimodule/status/test/statuscreate_test.go index 6c5aa6b7d..d143ac9a7 100644 --- a/internal/apimodule/status/test/statuscreate_test.go +++ b/internal/apimodule/status/test/statuscreate_test.go @@ -52,7 +52,7 @@ type StatusCreateTestSuite struct { log *logrus.Logger storage storage.Storage mastoConverter mastotypes.Converter - mediaHandler media.MediaHandler + mediaHandler media.Handler oauthServer oauth.Server distributor distributor.Distributor @@ -65,7 +65,7 @@ type StatusCreateTestSuite struct { testAttachments map[string]*gtsmodel.MediaAttachment // module being tested - statusModule *status.StatusModule + statusModule *status.Module } /* @@ -85,7 +85,7 @@ func (suite *StatusCreateTestSuite) SetupSuite() { 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.StatusModule) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) } func (suite *StatusCreateTestSuite) TearDownSuite() { @@ -121,7 +121,7 @@ func (suite *StatusCreateTestSuite) TearDownTest() { func (suite *StatusCreateTestSuite) TestPostNewStatus() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) // setup recorder := httptest.NewRecorder() @@ -175,7 +175,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatus() { func (suite *StatusCreateTestSuite) TestPostNewStatusWithEmoji() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) // setup recorder := httptest.NewRecorder() @@ -216,7 +216,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithEmoji() { // Try to reply to a status that doesn't exist func (suite *StatusCreateTestSuite) TestReplyToNonexistentStatus() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) // setup recorder := httptest.NewRecorder() @@ -247,7 +247,7 @@ func (suite *StatusCreateTestSuite) TestReplyToNonexistentStatus() { // Post a reply to the status of a local user that allows replies. func (suite *StatusCreateTestSuite) TestReplyToLocalStatus() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) // setup recorder := httptest.NewRecorder() @@ -287,7 +287,7 @@ func (suite *StatusCreateTestSuite) TestReplyToLocalStatus() { // Take a media file which is currently not associated with a status, and attach it to a new status. func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) // setup recorder := httptest.NewRecorder() diff --git a/internal/apimodule/status/test/statusfave_test.go b/internal/apimodule/status/test/statusfave_test.go index b15e57e77..9ccf58948 100644 --- a/internal/apimodule/status/test/statusfave_test.go +++ b/internal/apimodule/status/test/statusfave_test.go @@ -52,7 +52,7 @@ type StatusFaveTestSuite struct { log *logrus.Logger storage storage.Storage mastoConverter mastotypes.Converter - mediaHandler media.MediaHandler + mediaHandler media.Handler oauthServer oauth.Server distributor distributor.Distributor @@ -66,7 +66,7 @@ type StatusFaveTestSuite struct { testStatuses map[string]*gtsmodel.Status // module being tested - statusModule *status.StatusModule + statusModule *status.Module } /* @@ -86,7 +86,7 @@ func (suite *StatusFaveTestSuite) SetupSuite() { 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.StatusModule) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) } func (suite *StatusFaveTestSuite) TearDownSuite() { @@ -120,7 +120,7 @@ func (suite *StatusFaveTestSuite) TearDownTest() { func (suite *StatusFaveTestSuite) TestPostFave() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) targetStatus := suite.testStatuses["admin_account_status_2"] @@ -168,7 +168,7 @@ func (suite *StatusFaveTestSuite) TestPostFave() { func (suite *StatusFaveTestSuite) TestPostUnfaveable() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) targetStatus := suite.testStatuses["local_account_2_status_3"] // this one is unlikeable and unreplyable diff --git a/internal/apimodule/status/test/statusfavedby_test.go b/internal/apimodule/status/test/statusfavedby_test.go index 83f66562b..169543a81 100644 --- a/internal/apimodule/status/test/statusfavedby_test.go +++ b/internal/apimodule/status/test/statusfavedby_test.go @@ -52,7 +52,7 @@ type StatusFavedByTestSuite struct { log *logrus.Logger storage storage.Storage mastoConverter mastotypes.Converter - mediaHandler media.MediaHandler + mediaHandler media.Handler oauthServer oauth.Server distributor distributor.Distributor @@ -66,7 +66,7 @@ type StatusFavedByTestSuite struct { testStatuses map[string]*gtsmodel.Status // module being tested - statusModule *status.StatusModule + statusModule *status.Module } // SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout @@ -82,7 +82,7 @@ func (suite *StatusFavedByTestSuite) SetupSuite() { 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.StatusModule) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) } func (suite *StatusFavedByTestSuite) TearDownSuite() { @@ -114,7 +114,7 @@ func (suite *StatusFavedByTestSuite) TearDownTest() { func (suite *StatusFavedByTestSuite) TestGetFavedBy() { t := suite.testTokens["local_account_2"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) targetStatus := suite.testStatuses["admin_account_status_1"] // this status is faved by local_account_1 diff --git a/internal/apimodule/status/test/statusget_test.go b/internal/apimodule/status/test/statusget_test.go index 2c2e98acd..ce817d247 100644 --- a/internal/apimodule/status/test/statusget_test.go +++ b/internal/apimodule/status/test/statusget_test.go @@ -43,7 +43,7 @@ type StatusGetTestSuite struct { log *logrus.Logger storage storage.Storage mastoConverter mastotypes.Converter - mediaHandler media.MediaHandler + mediaHandler media.Handler oauthServer oauth.Server distributor distributor.Distributor @@ -56,7 +56,7 @@ type StatusGetTestSuite struct { testAttachments map[string]*gtsmodel.MediaAttachment // module being tested - statusModule *status.StatusModule + statusModule *status.Module } /* @@ -76,7 +76,7 @@ func (suite *StatusGetTestSuite) SetupSuite() { 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.StatusModule) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) } func (suite *StatusGetTestSuite) TearDownSuite() { diff --git a/internal/apimodule/status/test/statusunfave_test.go b/internal/apimodule/status/test/statusunfave_test.go index 81276a1ed..5f5277921 100644 --- a/internal/apimodule/status/test/statusunfave_test.go +++ b/internal/apimodule/status/test/statusunfave_test.go @@ -52,7 +52,7 @@ type StatusUnfaveTestSuite struct { log *logrus.Logger storage storage.Storage mastoConverter mastotypes.Converter - mediaHandler media.MediaHandler + mediaHandler media.Handler oauthServer oauth.Server distributor distributor.Distributor @@ -66,7 +66,7 @@ type StatusUnfaveTestSuite struct { testStatuses map[string]*gtsmodel.Status // module being tested - statusModule *status.StatusModule + statusModule *status.Module } /* @@ -86,7 +86,7 @@ func (suite *StatusUnfaveTestSuite) SetupSuite() { 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.StatusModule) + suite.statusModule = status.New(suite.config, suite.db, suite.mediaHandler, suite.mastoConverter, suite.distributor, suite.log).(*status.Module) } func (suite *StatusUnfaveTestSuite) TearDownSuite() { @@ -120,7 +120,7 @@ func (suite *StatusUnfaveTestSuite) TearDownTest() { func (suite *StatusUnfaveTestSuite) TestPostUnfave() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) // this is the status we wanna unfave: in the testrig it's already faved by this account targetStatus := suite.testStatuses["admin_account_status_1"] @@ -169,7 +169,7 @@ func (suite *StatusUnfaveTestSuite) TestPostUnfave() { func (suite *StatusUnfaveTestSuite) TestPostAlreadyNotFaved() { t := suite.testTokens["local_account_1"] - oauthToken := oauth.PGTokenToOauthToken(t) + oauthToken := oauth.TokenToOauthToken(t) // this is the status we wanna unfave: in the testrig it's not faved by this account targetStatus := suite.testStatuses["admin_account_status_2"] |