diff --git a/internal/cliactions/server/server.go b/internal/cliactions/server/server.go index 8759895..3f8b48f 100644 --- a/internal/cliactions/server/server.go +++ b/internal/cliactions/server/server.go @@ -25,7 +25,6 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/api/client/search" "github.com/superseriousbusiness/gotosocial/internal/api/client/status" "github.com/superseriousbusiness/gotosocial/internal/api/client/timeline" - timelineprocessing "github.com/superseriousbusiness/gotosocial/internal/processing/timeline" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/user" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger" "github.com/superseriousbusiness/gotosocial/internal/api/security" @@ -40,6 +39,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/processing" + timelineprocessing "github.com/superseriousbusiness/gotosocial/internal/processing/timeline" "github.com/superseriousbusiness/gotosocial/internal/router" "github.com/superseriousbusiness/gotosocial/internal/transport" "github.com/superseriousbusiness/gotosocial/internal/typeutils" diff --git a/internal/federation/federatingdb/create.go b/internal/federation/federatingdb/create.go index d2a060e..f707d44 100644 --- a/internal/federation/federatingdb/create.go +++ b/internal/federation/federatingdb/create.go @@ -110,10 +110,10 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error { } fromFederatorChan <- gtsmodel.FromFederator{ - APObjectType: gtsmodel.ActivityStreamsNote, - APActivityType: gtsmodel.ActivityStreamsCreate, - GTSModel: status, - ReceivingAccount: targetAcct, + APObjectType: gtsmodel.ActivityStreamsNote, + APActivityType: gtsmodel.ActivityStreamsCreate, + GTSModel: status, + ReceivingAccount: targetAcct, } } } diff --git a/internal/gtsmodel/messages.go b/internal/gtsmodel/messages.go index d573441..910c748 100644 --- a/internal/gtsmodel/messages.go +++ b/internal/gtsmodel/messages.go @@ -25,8 +25,8 @@ type FromClientAPI struct { // FromFederator wraps a message that travels from the federator into the processor type FromFederator struct { - APObjectType string - APActivityType string - GTSModel interface{} - ReceivingAccount *Account + APObjectType string + APActivityType string + GTSModel interface{} + ReceivingAccount *Account } diff --git a/internal/processing/processor.go b/internal/processing/processor.go index e1cd152..e4d860f 100644 --- a/internal/processing/processor.go +++ b/internal/processing/processor.go @@ -137,8 +137,6 @@ type Processor interface { // PublicTimelineGet returns statuses from the public/local timeline, with the given filters/parameters. PublicTimelineGet(authed *oauth.Auth, maxID string, sinceID string, minID string, limit int, local bool) ([]*apimodel.Status, ErrorWithCode) - - /* FEDERATION API-FACING PROCESSING FUNCTIONS These functions are intended to be called when the federating client needs an immediate (ie., synchronous) reply diff --git a/internal/processing/timeline.go b/internal/processing/timeline.go index b968156..3440430 100644 --- a/internal/processing/timeline.go +++ b/internal/processing/timeline.go @@ -179,7 +179,7 @@ func (p *processor) initTimelineFor(account *gtsmodel.Account, wg *sync.WaitGrou } if rearmostStatusID != "" { - moreStatuses, err := p.db.GetStatusesWhereFollowing(account.ID, desiredIndexLength / 2, rearmostStatusID) + moreStatuses, err := p.db.GetStatusesWhereFollowing(account.ID, desiredIndexLength/2, rearmostStatusID) if err != nil { l.Error(fmt.Errorf("initTimelineFor: error getting more statuses: %s", err)) return diff --git a/internal/processing/timeline/timeline.go b/internal/processing/timeline/timeline.go index 9352e79..bd4f16f 100644 --- a/internal/processing/timeline/timeline.go +++ b/internal/processing/timeline/timeline.go @@ -35,40 +35,61 @@ const ( preparedPostsMaxLength = desiredPostIndexLength ) +// Timeline represents a timeline for one account, and contains indexed and prepared posts. type Timeline interface { + /* + RETRIEVAL FUNCTIONS + */ + // GetXFromTop returns x amount of posts from the top of the timeline, from newest to oldest. GetXFromTop(amount int) ([]*apimodel.Status, error) // GetXFromIDOnwards returns x amount of posts from the given id onwards, from newest to oldest. // This will include the status with the given ID. GetXFromIDOnwards(amount int, fromID string) ([]*apimodel.Status, error) - // GetXBeforeID returns x amount of posts up to the given id, from newest to oldest. // This will NOT include the status with the given ID. GetXBeforeID(amount int, sinceID string) ([]*apimodel.Status, error) + /* + INDEXING FUNCTIONS + */ + // IndexOne puts a status into the timeline at the appropriate place according to its 'createdAt' property. IndexOne(statusCreatedAt time.Time, statusID string) error - // IndexOne puts a status into the timeline at the appropriate place according to its 'createdAt' property, - // and then immediately prepares it. - IndexAndPrepareOne(statusCreatedAt time.Time, statusID string) error // Remove removes a status from the timeline. Remove(statusID string) error // OldestIndexedPostID returns the id of the rearmost (ie., the oldest) indexed post, or an error if something goes wrong. // If nothing goes wrong but there's no oldest post, an empty string will be returned so make sure to check for this. OldestIndexedPostID() (string, error) + /* + PREPARATION FUNCTIONS + */ + // PrepareXFromTop instructs the timeline to prepare x amount of posts from the top of the timeline. PrepareXFromTop(amount int) error // PrepareXFromIndex instrucst the timeline to prepare the next amount of entries for serialization, from index onwards. PrepareXFromIndex(amount int, index int) error + // IndexOne puts a status into the timeline at the appropriate place according to its 'createdAt' property, + // and then immediately prepares it. + IndexAndPrepareOne(statusCreatedAt time.Time, statusID string) error + + /* + INFO FUNCTIONS + */ // ActualPostIndexLength returns the actual length of the post index at this point in time. PostIndexLength() int + /* + UTILITY FUNCTIONS + */ + // Reset instructs the timeline to reset to its base state -- cache only the minimum amount of posts. Reset() error } +// timeline fulfils the Timeline interface type timeline struct { postIndex *postIndex preparedPosts *preparedPosts @@ -79,6 +100,7 @@ type timeline struct { sync.Mutex } +// NewTimeline returns a new Timeline for the given account ID func NewTimeline(accountID string, db db.DB, typeConverter typeutils.TypeConverter) Timeline { return &timeline{ postIndex: &postIndex{}, diff --git a/testrig/timelinemanager.go b/testrig/timelinemanager.go index 2dd2514..5dae16c 100644 --- a/testrig/timelinemanager.go +++ b/testrig/timelinemanager.go @@ -5,6 +5,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/processing/timeline" ) +// NewTestTimelineManager retuts a new timeline.Manager, suitable for testing, using the given db. func NewTestTimelineManager(db db.DB) timeline.Manager { return timeline.NewManager(db, NewTestTypeConverter(db), NewTestConfig(), NewTestLog()) }