summaryrefslogtreecommitdiff
path: root/internal/message/timelineprocess.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-21 23:04:59 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-21 23:04:59 +0200
commit0df2e18cc0d5440deca32681f33c66d883913901 (patch)
treed52cb72f376695c70c37377fdb03ae47177e420e /internal/message/timelineprocess.go
parentFollows and relationships (#27) (diff)
downloadgotosocial-0df2e18cc0d5440deca32681f33c66d883913901.tar.xz
Home timeline (#28)
* v. basic implementation of home timeline * Go fmt ./...
Diffstat (limited to 'internal/message/timelineprocess.go')
-rw-r--r--internal/message/timelineprocess.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/internal/message/timelineprocess.go b/internal/message/timelineprocess.go
new file mode 100644
index 000000000..c3f2246d5
--- /dev/null
+++ b/internal/message/timelineprocess.go
@@ -0,0 +1,67 @@
+package message
+
+import (
+ "fmt"
+
+ apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "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) {
+ statuses, err := p.db.GetHomeTimelineForAccount(authed.Account.ID, maxID, sinceID, minID, limit, local)
+ if err != nil {
+ return nil, NewErrorInternalError(err)
+ }
+
+ apiStatuses := []apimodel.Status{}
+ for _, s := range statuses {
+ targetAccount := &gtsmodel.Account{}
+ if err := p.db.GetByID(s.AccountID, targetAccount); err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error getting status author: %s", err))
+ }
+
+ relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(s)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error getting relevant statuses: %s", err))
+ }
+
+ visible, err := p.db.StatusVisible(s, targetAccount, authed.Account, relevantAccounts)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error checking status visibility: %s", err))
+ }
+ if !visible {
+ continue
+ }
+
+ var boostedStatus *gtsmodel.Status
+ if s.BoostOfID != "" {
+ bs := &gtsmodel.Status{}
+ if err := p.db.GetByID(s.BoostOfID, bs); err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error getting boosted status: %s", err))
+ }
+ boostedRelevantAccounts, err := p.db.PullRelevantAccountsFromStatus(bs)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error getting relevant accounts from boosted status: %s", err))
+ }
+
+ boostedVisible, err := p.db.StatusVisible(bs, relevantAccounts.BoostedAccount, authed.Account, boostedRelevantAccounts)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error checking boosted status visibility: %s", err))
+ }
+
+ if boostedVisible {
+ boostedStatus = bs
+ }
+ }
+
+ apiStatus, err := p.tc.StatusToMasto(s, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostedStatus)
+ if err != nil {
+ return nil, NewErrorInternalError(fmt.Errorf("error converting status to masto: %s", err))
+ }
+
+ apiStatuses = append(apiStatuses, *apiStatus)
+ }
+
+ return apiStatuses, nil
+}