Home timeline (#28)

* v. basic implementation of home timeline

* Go fmt ./...
This commit is contained in:
Tobi Smethurst
2021-05-21 23:04:59 +02:00
committed by GitHub
parent d839f27c30
commit 0df2e18cc0
14 changed files with 317 additions and 52 deletions

View File

@ -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))
}
// 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)
}
// 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)
}
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))
}
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))
}
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)
}
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)
}
data, err := streams.Serialize(asStatus)
if err != nil {
return nil, NewErrorInternalError(err)
}
return data, nil
return data, nil
}
func (p *processor) GetWebfingerAccount(requestedUsername string, request *http.Request) (*apimodel.WebfingerAccountResponse, ErrorWithCode) {

View File

@ -25,5 +25,5 @@ func (p *processor) notifyStatus(status *gtsmodel.Status) error {
}
func (p *processor) notifyFollow(follow *gtsmodel.Follow) error {
return nil
return nil
}

View File

@ -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)
}

View File

@ -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

View File

@ -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
}