Move a lot of stuff + tidy stuff (#37)

Lots of renaming and moving stuff, some bug fixes, more lenient parsing of notifications and home timeline.
This commit is contained in:
Tobi Smethurst
2021-05-30 13:12:00 +02:00
committed by GitHub
parent c4d791be75
commit 3d77f81c7f
69 changed files with 342 additions and 719 deletions

View File

@@ -1,32 +0,0 @@
// Code generated by mockery v2.7.4. DO NOT EDIT.
package action
import (
context "context"
config "github.com/superseriousbusiness/gotosocial/internal/config"
logrus "github.com/sirupsen/logrus"
mock "github.com/stretchr/testify/mock"
)
// MockGTSAction is an autogenerated mock type for the GTSAction type
type MockGTSAction struct {
mock.Mock
}
// Execute provides a mock function with given fields: _a0, _a1, _a2
func (_m *MockGTSAction) Execute(_a0 context.Context, _a1 *config.Config, _a2 *logrus.Logger) error {
ret := _m.Called(_a0, _a1, _a2)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, *config.Config, *logrus.Logger) error); ok {
r0 = rf(_a0, _a1, _a2)
} else {
r0 = ret.Error(0)
}
return r0
}

View File

@@ -26,7 +26,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -61,7 +61,7 @@ const (
GetFollowingPath = BasePathWithID + "/following"
// GetRelationshipsPath is for showing an account's relationship with other accounts
GetRelationshipsPath = BasePath + "/relationships"
// FollowPath is for POSTing new follows to, and updating existing follows
// PostFollowPath is for POSTing new follows to, and updating existing follows
PostFollowPath = BasePathWithID + "/follow"
// PostUnfollowPath is for POSTing an unfollow
PostUnfollowPath = BasePathWithID + "/unfollow"
@@ -70,12 +70,12 @@ const (
// Module implements the ClientAPIModule interface for account-related actions
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new account module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -4,13 +4,13 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -22,9 +22,9 @@ type AccountStandardTestSuite struct {
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
storage storage.Storage
storage blob.Storage
federator federation.Federator
processor message.Processor
processor processing.Processor
// standard suite models
testTokens map[string]*oauth.Token

View File

@@ -25,7 +25,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
// AccountFollowersGETHandler serves the followers of the requested account, if they're visible to the requester.
// AccountFollowingGETHandler serves the following of the requested account, if they're visible to the requester.
func (m *Module) AccountFollowingGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {

View File

@@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -38,12 +38,12 @@ const (
// Module implements the ClientAPIModule interface for admin-related actions (reports, emojis, etc)
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new admin module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -34,12 +34,12 @@ const BasePath = "/api/v1/apps"
// Module implements the ClientAPIModule interface for requests relating to registering/removing applications
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new auth module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -27,7 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -46,13 +46,13 @@ const (
// The goal here is to serve requested media files if the gotosocial server is configured to use local storage.
type FileServer struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
storageBase string
}
// New returns a new fileServer module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &FileServer{
config: config,
processor: processor,

View File

@@ -31,14 +31,14 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/fileserver"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -49,10 +49,10 @@ type ServeFileTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage storage.Storage
storage blob.Storage
federator federation.Federator
tc typeutils.TypeConverter
processor message.Processor
processor processing.Processor
mediaHandler media.Handler
oauthServer oauth.Server

View File

@@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -46,12 +46,12 @@ const (
// Module implements the ClientAPIModule interface for every related to interacting with follow requests
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new follow request module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -6,7 +6,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -18,12 +18,12 @@ const (
// Module implements the ClientModule interface
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new instance information module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -27,7 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -43,12 +43,12 @@ const BasePathWithID = BasePath + "/:" + IDKey
// Module implements the ClientAPIModule interface for media
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new auth module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -34,14 +34,14 @@ import (
"github.com/stretchr/testify/suite"
mediamodule "github.com/superseriousbusiness/gotosocial/internal/api/client/media"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -52,12 +52,12 @@ type MediaCreateTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage storage.Storage
storage blob.Storage
federator federation.Federator
tc typeutils.TypeConverter
mediaHandler media.Handler
oauthServer oauth.Server
processor message.Processor
processor processing.Processor
// standard suite models
testTokens map[string]*oauth.Token

View File

@@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -39,19 +39,19 @@ const (
// MaxIDKey is the url query for setting a max notification ID to return
MaxIDKey = "max_id"
// Limit key is for specifying maximum number of notifications to return.
// LimitKey is for specifying maximum number of notifications to return.
LimitKey = "limit"
)
// Module implements the ClientAPIModule interface for every related to posting/deleting/interacting with notifications
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new notification module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -27,6 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
// NotificationsGETHandler serves a list of notifications to the caller, with the desired query parameters
func (m *Module) NotificationsGETHandler(c *gin.Context) {
l := m.log.WithFields(logrus.Fields{
"func": "NotificationsGETHandler",

View File

@@ -24,12 +24,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
const (
// BasePath is the base path for serving v1 of the search API
// BasePathV1 is the base path for serving v1 of the search API
BasePathV1 = "/api/v1/search"
// BasePathV2 is the base path for serving v2 of the search API
@@ -67,12 +67,12 @@ const (
// Module implements the ClientAPIModule interface for everything related to searching
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new search module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -26,7 +26,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -75,12 +75,12 @@ const (
// Module implements the ClientAPIModule interface for every related to posting/deleting/interacting with statuses
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new account module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -22,13 +22,13 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/status"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -41,8 +41,8 @@ type StatusStandardTestSuite struct {
log *logrus.Logger
tc typeutils.TypeConverter
federator federation.Federator
processor message.Processor
storage storage.Storage
processor processing.Processor
storage blob.Storage
// standard suite models
testTokens map[string]*oauth.Token

View File

@@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -39,7 +39,7 @@ const (
SinceIDKey = "since_id"
// MinIDKey is the url query for returning results immediately newer than the given ID
MinIDKey = "min_id"
// Limit key is for specifying maximum number of results to return.
// LimitKey is for specifying maximum number of results to return.
LimitKey = "limit"
// LocalKey is for specifying whether only local statuses should be returned
LocalKey = "local"
@@ -48,12 +48,12 @@ const (
// Module implements the ClientAPIModule interface for everything relating to viewing timelines
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new timeline module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
config: config,
processor: processor,

View File

@@ -25,6 +25,7 @@ import (
"github.com/sirupsen/logrus"
)
// FollowersGETHandler returns a collection of URIs for followers of the target user, formatted so that other AP servers can understand it.
func (m *Module) FollowersGETHandler(c *gin.Context) {
l := m.log.WithFields(logrus.Fields{
"func": "FollowersGETHandler",

View File

@@ -25,6 +25,7 @@ import (
"github.com/sirupsen/logrus"
)
// FollowingGETHandler returns a collection of URIs for accounts that the target user follows, formatted so that other AP servers can understand it.
func (m *Module) FollowingGETHandler(c *gin.Context) {
l := m.log.WithFields(logrus.Fields{
"func": "FollowingGETHandler",

View File

@@ -23,7 +23,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
)
// InboxPOSTHandler deals with incoming POST requests to an actor's inbox.
@@ -42,7 +42,7 @@ func (m *Module) InboxPOSTHandler(c *gin.Context) {
posted, err := m.processor.InboxPost(c.Request.Context(), c.Writer, c.Request)
if err != nil {
if withCode, ok := err.(message.ErrorWithCode); ok {
if withCode, ok := err.(processing.ErrorWithCode); ok {
l.Debug(withCode.Error())
c.JSON(withCode.Code(), withCode.Safe())
return

View File

@@ -7,6 +7,7 @@ import (
"github.com/sirupsen/logrus"
)
// StatusGETHandler serves the target status as an activitystreams NOTE so that other AP servers can parse it.
func (m *Module) StatusGETHandler(c *gin.Context) {
l := m.log.WithFields(logrus.Fields{
"func": "StatusGETHandler",

View File

@@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -60,12 +60,12 @@ var ActivityPubAcceptHeaders = []string{
// Module implements the FederationAPIModule interface
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new auth module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.FederationModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule {
return &Module{
config: config,
processor: processor,

View File

@@ -4,13 +4,13 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -23,8 +23,8 @@ type UserStandardTestSuite struct {
log *logrus.Logger
tc typeutils.TypeConverter
federator federation.Federator
processor message.Processor
storage storage.Storage
processor processing.Processor
storage blob.Storage
// standard suite models
testTokens map[string]*oauth.Token

View File

@@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -36,12 +36,12 @@ const (
// Module implements the FederationModule interface
type Module struct {
config *config.Config
processor message.Processor
processor processing.Processor
log *logrus.Logger
}
// New returns a new webfinger module
func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.FederationModule {
func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule {
return &Module{
config: config,
processor: processor,

View File

@@ -1,4 +1,4 @@
package storage
package blob
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package storage
package blob
import (
"fmt"

View File

@@ -16,8 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Package storage contains an interface and implementations for storing and retrieving files and attachments.
package storage
package blob
// Storage is an interface for storing and retrieving blobs
// such as images, videos, and any other attachments/documents

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package action
package cliactions
import (
"context"

View File

@@ -25,7 +25,7 @@ import (
"time"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/action"
"github.com/superseriousbusiness/gotosocial/internal/cliactions"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/db/pg"
@@ -34,7 +34,7 @@ import (
)
// Create creates a new account in the database using the provided flags.
var Create action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := pg.NewPostgresService(ctx, c, log)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
@@ -73,7 +73,7 @@ var Create action.GTSAction = func(ctx context.Context, c *config.Config, log *l
}
// Confirm sets a user to Approved, sets Email to the current UnconfirmedEmail value, and sets ConfirmedAt to now.
var Confirm action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := pg.NewPostgresService(ctx, c, log)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
@@ -108,7 +108,7 @@ var Confirm action.GTSAction = func(ctx context.Context, c *config.Config, log *
}
// Promote sets a user to admin.
var Promote action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := pg.NewPostgresService(ctx, c, log)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
@@ -140,7 +140,7 @@ var Promote action.GTSAction = func(ctx context.Context, c *config.Config, log *
}
// Demote sets admin on a user to false.
var Demote action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := pg.NewPostgresService(ctx, c, log)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
@@ -172,7 +172,7 @@ var Demote action.GTSAction = func(ctx context.Context, c *config.Config, log *l
}
// Disable sets Disabled to true on a user.
var Disable action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbConn, err := pg.NewPostgresService(ctx, c, log)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
@@ -203,7 +203,8 @@ var Disable action.GTSAction = func(ctx context.Context, c *config.Config, log *
return dbConn.Stop(ctx)
}
var Suspend action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
// Suspend suspends the target account, cleanly removing all of its media, followers, following, likes, statuses, etc.
var Suspend cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
// TODO
return nil
}

View File

@@ -1,22 +1,4 @@
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gotosocial
package server
import (
"context"
@@ -27,7 +9,6 @@ import (
"syscall"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/action"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
"github.com/superseriousbusiness/gotosocial/internal/api/client/admin"
@@ -44,16 +25,18 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger"
"github.com/superseriousbusiness/gotosocial/internal/api/security"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/cliactions"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/pg"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb"
"github.com/superseriousbusiness/gotosocial/internal/gotosocial"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/message"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/transport"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -81,8 +64,8 @@ var models []interface{} = []interface{}{
&oauth.Client{},
}
// Run creates and starts a gotosocial server
var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
// Start creates and starts a gotosocial server
var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
dbService, err := pg.NewPostgresService(ctx, c, log)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
@@ -95,7 +78,7 @@ var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logr
return fmt.Errorf("error creating router: %s", err)
}
storageBackend, err := storage.NewLocal(c, log)
storageBackend, err := blob.NewLocal(c, log)
if err != nil {
return fmt.Errorf("error creating storage backend: %s", err)
}
@@ -108,7 +91,7 @@ var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logr
oauthServer := oauth.New(dbService, log)
transportController := transport.NewController(c, &federation.Clock{}, http.DefaultClient, log)
federator := federation.NewFederator(dbService, federatingDB, transportController, c, log, typeConverter)
processor := message.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storageBackend, dbService, log)
processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storageBackend, dbService, log)
if err := processor.Start(); err != nil {
return fmt.Errorf("error starting processor: %s", err)
}
@@ -171,7 +154,7 @@ var Run action.GTSAction = func(ctx context.Context, c *config.Config, log *logr
return fmt.Errorf("error creating instance instance: %s", err)
}
gts, err := New(dbService, router, federator, c)
gts, err := gotosocial.NewServer(dbService, router, federator, c)
if err != nil {
return fmt.Errorf("error creating gotosocial service: %s", err)
}

View File

@@ -26,6 +26,7 @@ import (
"gopkg.in/yaml.v2"
)
// Flags and usage strings for configuration.
const (
UsernameFlag = "username"
UsernameUsage = "the username to create/delete/etc"

View File

@@ -30,34 +30,10 @@ const (
DBTypePostgres string = "POSTGRES"
)
// ErrNoEntries is to be returned from the DB interface when no entries are found for a given query.
type ErrNoEntries struct{}
func (e ErrNoEntries) Error() string {
return "no entries"
}
// ErrAlreadyExists is to be returned from the DB interface when an entry already exists for a given query or its constraints.
type ErrAlreadyExists struct{}
func (e ErrAlreadyExists) Error() string {
return "already exists"
}
type Where struct {
Key string
Value interface{}
CaseInsensitive bool
}
// DB provides methods for interacting with an underlying database or other storage mechanism (for now, just postgres).
// Note that in all of the functions below, the passed interface should be a pointer or a slice, which will then be populated
// by whatever is returned from the database.
type DB interface {
// Federation returns an interface that's compatible with go-fed, for performing federation storage/retrieval functions.
// See: https://pkg.go.dev/github.com/go-fed/activity@v1.0.0/pub?utm_source=gopls#Database
// Federation() federatingdb.FederatingDB
/*
BASIC DB FUNCTIONALITY
*/
@@ -269,10 +245,6 @@ type DB interface {
// StatusBookmarkedBy checks if a given status has been bookmarked by a given account ID
StatusBookmarkedBy(status *gtsmodel.Status, accountID string) (bool, error)
// FaveStatus faves the given status, using accountID as the faver.
// The returned fave will be nil if the status was already faved.
// FaveStatus(status *gtsmodel.Status, accountID string) (*gtsmodel.StatusFave, error)
// UnfaveStatus unfaves the given status, using accountID as the unfaver (sure, that's a word).
// The returned fave will be nil if the status was already not faved.
UnfaveStatus(status *gtsmodel.Status, accountID string) (*gtsmodel.StatusFave, error)
@@ -285,6 +257,7 @@ type DB interface {
// It will use the given filters and try to return as many statuses up to the limit as possible.
GetHomeTimelineForAccount(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, error)
// GetNotificationsForAccount returns a list of notifications that pertain to the given accountID.
GetNotificationsForAccount(accountID string, limit int, maxID string) ([]*gtsmodel.Notification, error)
/*

View File

@@ -18,20 +18,16 @@
package db
import (
"context"
// ErrNoEntries is to be returned from the DB interface when no entries are found for a given query.
type ErrNoEntries struct{}
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
)
// Initialize will initialize the database given in the config for use with GoToSocial
var Initialize action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
// db, err := New(ctx, c, log)
// if err != nil {
// return err
// }
return nil
// return db.CreateSchema(ctx)
func (e ErrNoEntries) Error() string {
return "no entries"
}
// ErrAlreadyExists is to be returned from the DB interface when an entry already exists for a given query or its constraints.
type ErrAlreadyExists struct{}
func (e ErrAlreadyExists) Error() string {
return "already exists"
}

30
internal/db/params.go Normal file
View File

@@ -0,0 +1,30 @@
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package db
// Where allows the caller of the DB to specify Where parameters.
type Where struct {
// The table to search on.
Key string
// The value that must be set.
Value interface{}
// Whether the value (if a string) should be case sensitive or not.
// Defaults to false.
CaseInsensitive bool
}

View File

@@ -35,11 +35,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
"github.com/superseriousbusiness/gotosocial/internal/util"
"github.com/superseriousbusiness/gotosocial/testrig"
@@ -50,7 +50,7 @@ type ProtocolTestSuite struct {
config *config.Config
db db.DB
log *logrus.Logger
storage storage.Storage
storage blob.Storage
typeConverter typeutils.TypeConverter
accounts map[string]*gtsmodel.Account
activities map[string]testrig.ActivityWithSignature

View File

@@ -27,17 +27,22 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/router"
)
// Gotosocial is the 'main' function of the gotosocial server, and the place where everything hangs together.
// Server is the 'main' function of the gotosocial server, and the place where everything hangs together.
// The logic of stopping and starting the entire server is contained here.
type Gotosocial interface {
type Server interface {
// Start starts up the gotosocial server. If something goes wrong
// while starting the server, then an error will be returned.
Start(context.Context) error
// Stop closes down the gotosocial server, first closing the router
// then the database. If something goes wrong while stopping, an
// error will be returned.
Stop(context.Context) error
}
// New returns a new gotosocial server, initialized with the given configuration.
// NewServer returns a new gotosocial server, initialized with the given configuration.
// An error will be returned the caller if something goes wrong during initialization
// eg., no db or storage connection, port for router already in use, etc.
func New(db db.DB, apiRouter router.Router, federator federation.Federator, config *config.Config) (Gotosocial, error) {
func NewServer(db db.DB, apiRouter router.Router, federator federation.Federator, config *config.Config) (Server, error) {
return &gotosocial{
db: db,
apiRouter: apiRouter,
@@ -61,6 +66,9 @@ func (gts *gotosocial) Start(ctx context.Context) error {
return nil
}
// Stop closes down the gotosocial server, first closing the router
// then the database. If something goes wrong while stopping, an
// error will be returned.
func (gts *gotosocial) Stop(ctx context.Context) error {
if err := gts.apiRouter.Stop(ctx); err != nil {
return err

View File

@@ -61,7 +61,7 @@ const (
NotificationMention NotificationType = "mention"
// NotificationReblog -- someone boosted one of your statuses
NotificationReblog NotificationType = "reblog"
// NotifiationFave -- someone faved/liked one of your statuses
// NotificationFave -- someone faved/liked one of your statuses
NotificationFave NotificationType = "favourite"
// NotificationPoll -- a poll you voted in or created has ended
NotificationPoll NotificationType = "poll"

View File

@@ -28,10 +28,10 @@ import (
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
@@ -93,12 +93,12 @@ type Handler interface {
type mediaHandler struct {
config *config.Config
db db.DB
storage storage.Storage
storage blob.Storage
log *logrus.Logger
}
// New returns a new handler with the given config, db, storage, and logger
func New(config *config.Config, database db.DB, storage storage.Storage, log *logrus.Logger) Handler {
func New(config *config.Config, database db.DB, storage blob.Storage, log *logrus.Logger) Handler {
return &mediaHandler{
config: config,
db: database,

View File

@@ -1,173 +0,0 @@
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package media
import (
"context"
"io/ioutil"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/db/pg"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/storage"
)
type MediaTestSuite struct {
suite.Suite
config *config.Config
log *logrus.Logger
db db.DB
mediaHandler *mediaHandler
mockStorage *storage.MockStorage
}
/*
TEST INFRASTRUCTURE
*/
// SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout
func (suite *MediaTestSuite) SetupSuite() {
// some of our subsequent entities need a log so create this here
log := logrus.New()
log.SetLevel(logrus.TraceLevel)
suite.log = log
// Direct config to local postgres instance
c := config.Empty()
c.Protocol = "http"
c.Host = "localhost"
c.DBConfig = &config.DBConfig{
Type: "postgres",
Address: "localhost",
Port: 5432,
User: "postgres",
Password: "postgres",
Database: "postgres",
ApplicationName: "gotosocial",
}
c.MediaConfig = &config.MediaConfig{
MaxImageSize: 2 << 20,
}
c.StorageConfig = &config.StorageConfig{
Backend: "local",
BasePath: "/tmp",
ServeProtocol: "http",
ServeHost: "localhost",
ServeBasePath: "/fileserver/media",
}
suite.config = c
// use an actual database for this, because it's just easier than mocking one out
database, err := pg.NewPostgresService(context.Background(), c, log)
if err != nil {
suite.FailNow(err.Error())
}
suite.db = database
suite.mockStorage = &storage.MockStorage{}
// We don't need storage to do anything for these tests, so just simulate a success and do nothing
suite.mockStorage.On("StoreFileAt", mock.AnythingOfType("string"), mock.AnythingOfType("[]uint8")).Return(nil)
// and finally here's the thing we're actually testing!
suite.mediaHandler = &mediaHandler{
config: suite.config,
db: suite.db,
storage: suite.mockStorage,
log: log,
}
}
func (suite *MediaTestSuite) TearDownSuite() {
if err := suite.db.Stop(context.Background()); err != nil {
logrus.Panicf("error closing db connection: %s", err)
}
}
// SetupTest creates a db connection and creates necessary tables before each test
func (suite *MediaTestSuite) SetupTest() {
// create all the tables we might need in thie suite
models := []interface{}{
&gtsmodel.Account{},
&gtsmodel.MediaAttachment{},
}
for _, m := range models {
if err := suite.db.CreateTable(m); err != nil {
logrus.Panicf("db connection error: %s", err)
}
}
err := suite.db.CreateInstanceAccount()
if err != nil {
logrus.Panic(err)
}
}
// TearDownTest drops tables to make sure there's no data in the db
func (suite *MediaTestSuite) TearDownTest() {
// remove all the tables we might have used so it's clear for the next test
models := []interface{}{
&gtsmodel.Account{},
&gtsmodel.MediaAttachment{},
}
for _, m := range models {
if err := suite.db.DropTable(m); err != nil {
logrus.Panicf("error dropping table: %s", err)
}
}
}
/*
ACTUAL TESTS
*/
func (suite *MediaTestSuite) TestSetHeaderOrAvatarForAccountID() {
// load test image
f, err := ioutil.ReadFile("./test/test-jpeg.jpg")
assert.Nil(suite.T(), err)
ma, err := suite.mediaHandler.ProcessHeaderOrAvatar(f, "weeeeeee", "header", "")
assert.Nil(suite.T(), err)
suite.log.Debugf("%+v", ma)
// attachment should have....
assert.Equal(suite.T(), "weeeeeee", ma.AccountID)
assert.Equal(suite.T(), "LjCZnlvyRkRn_NvzRjWF?urqV@f9", ma.Blurhash)
//TODO: add more checks here, cba right now!
}
func (suite *MediaTestSuite) TestProcessLocalEmoji() {
f, err := ioutil.ReadFile("./test/rainbow-original.png")
assert.NoError(suite.T(), err)
emoji, err := suite.mediaHandler.ProcessLocalEmoji(f, "rainbow")
assert.NoError(suite.T(), err)
suite.log.Debugf("%+v", emoji)
}
// TODO: add tests for sad path, gif, png....
func TestMediaTestSuite(t *testing.T) {
suite.Run(t, new(MediaTestSuite))
}

View File

@@ -1,24 +0,0 @@
package message
import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
func (p *processor) NotificationsGet(authed *oauth.Auth, limit int, maxID string) ([]*apimodel.Notification, ErrorWithCode) {
notifs, err := p.db.GetNotificationsForAccount(authed.Account.ID, limit, maxID)
if err != nil {
return nil, NewErrorInternalError(err)
}
mastoNotifs := []*apimodel.Notification{}
for _, n := range notifs {
mastoNotif, err := p.tc.NotificationToMasto(n)
if err != nil {
return nil, NewErrorInternalError(err)
}
mastoNotifs = append(mastoNotifs, mastoNotif)
}
return mastoNotifs, nil
}

View File

@@ -1,89 +0,0 @@
// Code generated by mockery v2.7.4. DO NOT EDIT.
package oauth
import (
http "net/http"
mock "github.com/stretchr/testify/mock"
oauth2 "github.com/superseriousbusiness/oauth2/v4"
)
// MockServer is an autogenerated mock type for the Server type
type MockServer struct {
mock.Mock
}
// GenerateUserAccessToken provides a mock function with given fields: ti, clientSecret, userID
func (_m *MockServer) GenerateUserAccessToken(ti oauth2.TokenInfo, clientSecret string, userID string) (oauth2.TokenInfo, error) {
ret := _m.Called(ti, clientSecret, userID)
var r0 oauth2.TokenInfo
if rf, ok := ret.Get(0).(func(oauth2.TokenInfo, string, string) oauth2.TokenInfo); ok {
r0 = rf(ti, clientSecret, userID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(oauth2.TokenInfo)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(oauth2.TokenInfo, string, string) error); ok {
r1 = rf(ti, clientSecret, userID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// HandleAuthorizeRequest provides a mock function with given fields: w, r
func (_m *MockServer) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) error {
ret := _m.Called(w, r)
var r0 error
if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) error); ok {
r0 = rf(w, r)
} else {
r0 = ret.Error(0)
}
return r0
}
// HandleTokenRequest provides a mock function with given fields: w, r
func (_m *MockServer) HandleTokenRequest(w http.ResponseWriter, r *http.Request) error {
ret := _m.Called(w, r)
var r0 error
if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) error); ok {
r0 = rf(w, r)
} else {
r0 = ret.Error(0)
}
return r0
}
// ValidationBearerToken provides a mock function with given fields: r
func (_m *MockServer) ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error) {
ret := _m.Called(r)
var r0 oauth2.TokenInfo
if rf, ok := ret.Get(0).(func(*http.Request) oauth2.TokenInfo); ok {
r0 = rf(r)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(oauth2.TokenInfo)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(*http.Request) error); ok {
r1 = rf(r)
} else {
r1 = ret.Error(1)
}
return r0, r1
}

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"errors"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"bytes"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"github.com/google/uuid"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"errors"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"context"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"context"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"fmt"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"errors"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"fmt"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"bytes"

View File

@@ -0,0 +1,45 @@
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package processing
import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
func (p *processor) NotificationsGet(authed *oauth.Auth, limit int, maxID string) ([]*apimodel.Notification, ErrorWithCode) {
l := p.log.WithField("func", "NotificationsGet")
notifs, err := p.db.GetNotificationsForAccount(authed.Account.ID, limit, maxID)
if err != nil {
return nil, NewErrorInternalError(err)
}
mastoNotifs := []*apimodel.Notification{}
for _, n := range notifs {
mastoNotif, err := p.tc.NotificationToMasto(n)
if err != nil {
l.Debugf("got an error converting a notification to masto, will skip it: %s", err)
continue
}
mastoNotifs = append(mastoNotifs, mastoNotif)
}
return mastoNotifs, nil
}

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"context"
@@ -24,13 +24,13 @@ import (
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/blob"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -184,12 +184,12 @@ type processor struct {
tc typeutils.TypeConverter
oauthServer oauth.Server
mediaHandler media.Handler
storage storage.Storage
storage blob.Storage
db db.DB
}
// NewProcessor returns a new Processor that uses the given federator and logger
func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage storage.Storage, db db.DB, log *logrus.Logger) Processor {
func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage blob.Storage, db db.DB, log *logrus.Logger) Processor {
return &processor{
// toClientAPI: make(chan gtsmodel.ToClientAPI, 100),
fromClientAPI: make(chan gtsmodel.FromClientAPI, 100),

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"errors"

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"errors"

View File

@@ -1,14 +1,35 @@
package message
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package processing
import (
"fmt"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID string, minID string, limit int, local bool) ([]apimodel.Status, ErrorWithCode) {
l := p.log.WithField("func", "HomeTimelineGet")
statuses, err := p.db.GetHomeTimelineForAccount(authed.Account.ID, maxID, sinceID, minID, limit, local)
if err != nil {
return nil, NewErrorInternalError(err)
@@ -18,12 +39,17 @@ func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID st
for _, s := range statuses {
targetAccount := &gtsmodel.Account{}
if err := p.db.GetByID(s.AccountID, targetAccount); err != nil {
if _, ok := err.(db.ErrNoEntries); ok {
l.Debugf("skipping status %s because account %s can't be found in the db", s.ID, s.AccountID)
continue
}
return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting status author: %s", err))
}
relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(s)
if err != nil {
return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting relevant statuses for status with id %s and uri %s: %s", s.ID, s.URI, err))
l.Debugf("skipping status %s because we couldn't pull relevant accounts from the db", s.ID)
continue
}
visible, err := p.db.StatusVisible(s, targetAccount, authed.Account, relevantAccounts)
@@ -38,11 +64,16 @@ func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID st
if s.BoostOfID != "" {
bs := &gtsmodel.Status{}
if err := p.db.GetByID(s.BoostOfID, bs); err != nil {
if _, ok := err.(db.ErrNoEntries); ok {
l.Debugf("skipping status %s because status %s can't be found in the db", s.ID, s.BoostOfID)
continue
}
return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting boosted status: %s", err))
}
boostedRelevantAccounts, err := p.db.PullRelevantAccountsFromStatus(bs)
if err != nil {
return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error getting relevant accounts from boosted status: %s", err))
l.Debugf("skipping status %s because we couldn't pull relevant accounts from the db", s.ID)
continue
}
boostedVisible, err := p.db.StatusVisible(bs, relevantAccounts.BoostedAccount, authed.Account, boostedRelevantAccounts)
@@ -57,7 +88,8 @@ func (p *processor) HomeTimelineGet(authed *oauth.Auth, maxID string, sinceID st
apiStatus, err := p.tc.StatusToMasto(s, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostedStatus)
if err != nil {
return nil, NewErrorInternalError(fmt.Errorf("HomeTimelineGet: error converting status to masto: %s", err))
l.Debugf("skipping status %s because it couldn't be converted to its mastodon representation: %s", s.ID, err)
continue
}
apiStatuses = append(apiStatuses, *apiStatus)

View File

@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package message
package processing
import (
"bytes"

View File

@@ -1,44 +0,0 @@
// Code generated by mockery v2.7.4. DO NOT EDIT.
package router
import (
context "context"
gin "github.com/gin-gonic/gin"
mock "github.com/stretchr/testify/mock"
)
// MockRouter is an autogenerated mock type for the Router type
type MockRouter struct {
mock.Mock
}
// AttachHandler provides a mock function with given fields: method, path, f
func (_m *MockRouter) AttachHandler(method string, path string, f gin.HandlerFunc) {
_m.Called(method, path, f)
}
// AttachMiddleware provides a mock function with given fields: handler
func (_m *MockRouter) AttachMiddleware(handler gin.HandlerFunc) {
_m.Called(handler)
}
// Start provides a mock function with given fields:
func (_m *MockRouter) Start() {
_m.Called()
}
// Stop provides a mock function with given fields: ctx
func (_m *MockRouter) Stop(ctx context.Context) error {
ret := _m.Called(ctx)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context) error); ok {
r0 = rf(ctx)
} else {
r0 = ret.Error(0)
}
return r0
}

View File

@@ -1,84 +0,0 @@
// Code generated by mockery v2.7.4. DO NOT EDIT.
package storage
import mock "github.com/stretchr/testify/mock"
// MockStorage is an autogenerated mock type for the Storage type
type MockStorage struct {
mock.Mock
}
// ListKeys provides a mock function with given fields:
func (_m *MockStorage) ListKeys() ([]string, error) {
ret := _m.Called()
var r0 []string
if rf, ok := ret.Get(0).(func() []string); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]string)
}
}
var r1 error
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// RemoveFileAt provides a mock function with given fields: path
func (_m *MockStorage) RemoveFileAt(path string) error {
ret := _m.Called(path)
var r0 error
if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(path)
} else {
r0 = ret.Error(0)
}
return r0
}
// RetrieveFileFrom provides a mock function with given fields: path
func (_m *MockStorage) RetrieveFileFrom(path string) ([]byte, error) {
ret := _m.Called(path)
var r0 []byte
if rf, ok := ret.Get(0).(func(string) []byte); ok {
r0 = rf(path)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]byte)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(path)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// StoreFileAt provides a mock function with given fields: path, data
func (_m *MockStorage) StoreFileAt(path string, data []byte) error {
ret := _m.Called(path, data)
var r0 error
if rf, ok := ret.Get(0).(func(string, []byte) error); ok {
r0 = rf(path, data)
} else {
r0 = ret.Error(0)
}
return r0
}

View File

@@ -113,7 +113,7 @@ func GenerateURIForFollow(username string, protocol string, host string, thisFol
return fmt.Sprintf("%s://%s/%s/%s/%s/%s", protocol, host, UsersPath, username, FollowPath, thisFollowID)
}
// GenerateURIForFollow returns the AP URI for a new like/fave -- something like:
// GenerateURIForLike returns the AP URI for a new like/fave -- something like:
// https://example.org/users/whatever_user/liked/41c7f33f-1060-48d9-84df-38dcb13cf0d8
func GenerateURIForLike(username string, protocol string, host string, thisFavedID string) string {
return fmt.Sprintf("%s://%s/%s/%s/%s/%s", protocol, host, UsersPath, username, LikedPath, thisFavedID)
@@ -195,7 +195,7 @@ func IsLikedPath(id *url.URL) bool {
return likedPathRegex.MatchString(strings.ToLower(id.Path))
}
// IsLikedPath returns true if the given URL path corresponds to eg /users/example_username/liked/SOME_UUID_OF_A_STATUS
// IsLikePath returns true if the given URL path corresponds to eg /users/example_username/liked/SOME_UUID_OF_A_STATUS
func IsLikePath(id *url.URL) bool {
return likePathRegex.MatchString(strings.ToLower(id.Path))
}