summaryrefslogtreecommitdiff
path: root/internal/message
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
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')
-rw-r--r--internal/message/fediprocess.go80
-rw-r--r--internal/message/fromcommonprocess.go2
-rw-r--r--internal/message/frprocess.go4
-rw-r--r--internal/message/processor.go3
-rw-r--r--internal/message/timelineprocess.go67
5 files changed, 113 insertions, 43 deletions
diff --git a/internal/message/fediprocess.go b/internal/message/fediprocess.go
index eb6e8b6d6..491997bf2 100644
--- a/internal/message/fediprocess.go
+++ b/internal/message/fediprocess.go
@@ -164,46 +164,46 @@ func (p *processor) GetFediFollowers(requestedUsername string, request *http.Req
}
func (p *processor) GetFediStatus(requestedUsername string, requestedStatusID string, request *http.Request) (interface{}, ErrorWithCode) {
- // get the account the request is referring to
- requestedAccount := &gtsmodel.Account{}
- if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
- return nil, NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
- }
-
- // authenticate the request
- requestingAccount, err := p.authenticateAndDereferenceFediRequest(requestedUsername, request)
- if err != nil {
- return nil, NewErrorNotAuthorized(err)
- }
-
- blocked, err := p.db.Blocked(requestedAccount.ID, requestingAccount.ID)
- if err != nil {
- return nil, NewErrorInternalError(err)
- }
-
- if blocked {
- return nil, NewErrorNotAuthorized(fmt.Errorf("block exists between accounts %s and %s", requestedAccount.ID, requestingAccount.ID))
- }
-
- s := &gtsmodel.Status{}
- if err := p.db.GetWhere([]db.Where{
- {Key: "id", Value: requestedStatusID},
- {Key: "account_id", Value: requestedAccount.ID},
- }, s); err != nil {
- return nil, NewErrorNotFound(fmt.Errorf("database error getting status with id %s and account id %s: %s", requestedStatusID, requestedAccount.ID, err))
- }
-
- asStatus, err := p.tc.StatusToAS(s)
- if err != nil {
- return nil, NewErrorInternalError(err)
- }
-
- data, err := streams.Serialize(asStatus)
- if err != nil {
- return nil, NewErrorInternalError(err)
- }
-
- return data, nil
+ // get the account the request is referring to
+ requestedAccount := &gtsmodel.Account{}
+ if err := p.db.GetLocalAccountByUsername(requestedUsername, requestedAccount); err != nil {
+ return nil, NewErrorNotFound(fmt.Errorf("database error getting account with username %s: %s", requestedUsername, err))
+ }
+
+ // authenticate the request
+ requestingAccount, err := p.authenticateAndDereferenceFediRequest(requestedUsername, request)
+ if err != nil {
+ return nil, NewErrorNotAuthorized(err)
+ }
+
+ blocked, err := p.db.Blocked(requestedAccount.ID, requestingAccount.ID)
+ if err != nil {
+ return nil, NewErrorInternalError(err)
+ }
+
+ if blocked {
+ return nil, NewErrorNotAuthorized(fmt.Errorf("block exists between accounts %s and %s", requestedAccount.ID, requestingAccount.ID))
+ }
+
+ s := &gtsmodel.Status{}
+ if err := p.db.GetWhere([]db.Where{
+ {Key: "id", Value: requestedStatusID},
+ {Key: "account_id", Value: requestedAccount.ID},
+ }, s); err != nil {
+ return nil, NewErrorNotFound(fmt.Errorf("database error getting status with id %s and account id %s: %s", requestedStatusID, requestedAccount.ID, err))
+ }
+
+ asStatus, err := p.tc.StatusToAS(s)
+ if err != nil {
+ return nil, NewErrorInternalError(err)
+ }
+
+ data, err := streams.Serialize(asStatus)
+ if err != nil {
+ return nil, NewErrorInternalError(err)
+ }
+
+ return data, nil
}
func (p *processor) GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, ErrorWithCode) {
diff --git a/internal/message/fromcommonprocess.go b/internal/message/fromcommonprocess.go
index d557b7962..486da39af 100644
--- a/internal/message/fromcommonprocess.go
+++ b/internal/message/fromcommonprocess.go
@@ -25,5 +25,5 @@ func (p *processor) notifyStatus(status *gtsmodel.Status) error {
}
func (p *processor) notifyFollow(follow *gtsmodel.Follow) error {
- return nil
+ return nil
}
diff --git a/internal/message/frprocess.go b/internal/message/frprocess.go
index fd64b4c50..e229dcfbb 100644
--- a/internal/message/frprocess.go
+++ b/internal/message/frprocess.go
@@ -56,7 +56,7 @@ func (p *processor) FollowRequestAccept(auth *oauth.Auth, accountID string) (*ap
p.fromClientAPI <- gtsmodel.FromClientAPI{
APActivityType: gtsmodel.ActivityStreamsAccept,
- GTSModel: follow,
+ GTSModel: follow,
}
gtsR, err := p.db.GetRelationship(auth.Account.ID, accountID)
@@ -65,7 +65,7 @@ func (p *processor) FollowRequestAccept(auth *oauth.Auth, accountID string) (*ap
}
r, err := p.tc.RelationshipToMasto(gtsR)
- if err != nil {
+ if err != nil {
return nil, NewErrorInternalError(err)
}
diff --git a/internal/message/processor.go b/internal/message/processor.go
index e9888d647..54b2ada04 100644
--- a/internal/message/processor.go
+++ b/internal/message/processor.go
@@ -121,6 +121,9 @@ type Processor interface {
// StatusUnfave processes the unfaving of a given status, returning the updated status if the fave goes through.
StatusUnfave(authed *oauth.Auth, targetStatusID string) (*apimodel.Status, error)
+ // HomeTimelineGet returns statuses from the home timeline, with the given filters/parameters.
+ HomeTimelineGet(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/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
+}