more timeline stuff

This commit is contained in:
tsmethurst
2021-06-07 20:20:36 +02:00
parent 5d65b6ca0a
commit 625e6d654c
7 changed files with 139 additions and 46 deletions

View File

@ -256,7 +256,7 @@ type DB interface {
WhoBoostedStatus(status *gtsmodel.Status) ([]*gtsmodel.Account, error)
// GetStatusesWhereFollowing returns a slice of statuses from accounts that are followed by the given account id.
GetStatusesWhereFollowing(accountID string, limit int, maxID string, minID string, sinceID string) ([]*gtsmodel.Status, error)
GetStatusesWhereFollowing(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, error)
// GetPublicTimelineForAccount fetches the account's PUBLIC timline -- ie., posts and replies that are public.
// It will use the given filters and try to return as many statuses as possible up to the limit.

View File

@ -1133,7 +1133,7 @@ func (ps *postgresService) WhoBoostedStatus(status *gtsmodel.Status) ([]*gtsmode
return accounts, nil
}
func (ps *postgresService) GetStatusesWhereFollowing(accountID string, limit int, offsetStatusID string, includeOffsetStatus bool, ascending bool) ([]*gtsmodel.Status, error) {
func (ps *postgresService) GetStatusesWhereFollowing(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, error) {
statuses := []*gtsmodel.Status{}
q := ps.conn.Model(&statuses)
@ -1142,23 +1142,35 @@ func (ps *postgresService) GetStatusesWhereFollowing(accountID string, limit int
Join("JOIN follows AS f ON f.target_account_id = status.account_id").
Where("f.account_id = ?", accountID)
if ascending {
if maxID != "" {
s := &gtsmodel.Status{}
if err := ps.conn.Model(s).Where("id = ?", maxID).Select(); err == nil {
q = q.Where("status.created_at < ?", s.CreatedAt)
}
}
if sinceID != "" {
s := &gtsmodel.Status{}
if err := ps.conn.Model(s).Where("id = ?", sinceID).Select(); err == nil {
q = q.Where("status.created_at > ?", s.CreatedAt)
}
}
if minID != "" {
s := &gtsmodel.Status{}
if err := ps.conn.Model(s).Where("id = ?", minID).Select(); err == nil {
q = q.Where("status.created_at > ?", s.CreatedAt)
}
}
if minID != "" {
q = q.Order("status.created_at")
} else {
q = q.Order("status.created_at DESC")
}
s := &gtsmodel.Status{}
if offsetStatusID != "" {
if err := ps.conn.Model(s).Where("id = ?", offsetStatusID).Select(); err != nil {
return nil, err
}
if ascending {
q = q.Where("status.created_at > ?", s.CreatedAt)
} else {
q = q.Where("status.created_at < ?", s.CreatedAt)
}
if local {
q = q.Where("status.local = ?", local)
}
if limit > 0 {
@ -1172,14 +1184,6 @@ func (ps *postgresService) GetStatusesWhereFollowing(accountID string, limit int
}
}
if includeOffsetStatus {
if ascending {
statuses = append([]*gtsmodel.Status{s}, statuses...)
} else {
statuses = append(statuses, s)
}
}
return statuses, nil
}