summaryrefslogtreecommitdiff
path: root/internal/processing/fedi/status.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-06-11 11:54:59 +0200
committerLibravatar GitHub <noreply@github.com>2024-06-11 11:54:59 +0200
commit611f9de39b7a29e89616c9ffe76d2aca1194877b (patch)
treec5792f5c4c21070b608e0bb3b743edffbd190074 /internal/processing/fedi/status.go
parent[bugfix] boost and account recursion (#2982) (diff)
downloadgotosocial-611f9de39b7a29e89616c9ffe76d2aca1194877b.tar.xz
[bugfix] Deref stats async, serve stub collections if handshaking (#2990)v0.16.0-rc2
* [bugfix] Deref stats async, allow peek if handshaking * don't return totalItems when handshaking or hiding collections * use GetLimit() * use StubAccountStats
Diffstat (limited to 'internal/processing/fedi/status.go')
-rw-r--r--internal/processing/fedi/status.go43
1 files changed, 33 insertions, 10 deletions
diff --git a/internal/processing/fedi/status.go b/internal/processing/fedi/status.go
index c6d611eee..7c4d4beec 100644
--- a/internal/processing/fedi/status.go
+++ b/internal/processing/fedi/status.go
@@ -30,23 +30,35 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/paging"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// StatusGet handles the getting of a fedi/activitypub representation of a local status.
// It performs appropriate authentication before returning a JSON serializable interface.
func (p *Processor) StatusGet(ctx context.Context, requestedUser string, statusID string) (interface{}, gtserror.WithCode) {
- // Authenticate the incoming request, getting related user accounts.
- requester, receiver, errWithCode := p.authenticate(ctx, requestedUser)
+ // Authenticate incoming request, getting related accounts.
+ auth, errWithCode := p.authenticate(ctx, requestedUser)
if errWithCode != nil {
return nil, errWithCode
}
+ if auth.handshakingURI != nil {
+ // We're currently handshaking, which means
+ // we don't know this account yet. This should
+ // be a very rare race condition.
+ err := gtserror.Newf("network race handshaking %s", auth.handshakingURI)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ receivingAcct := auth.receivingAcct
+ requestingAcct := auth.requestingAcct
+
status, err := p.state.DB.GetStatusByID(ctx, statusID)
if err != nil {
return nil, gtserror.NewErrorNotFound(err)
}
- if status.AccountID != receiver.ID {
+ if status.AccountID != receivingAcct.ID {
const text = "status does not belong to receiving account"
return nil, gtserror.NewErrorNotFound(errors.New(text))
}
@@ -56,7 +68,7 @@ func (p *Processor) StatusGet(ctx context.Context, requestedUser string, statusI
return nil, gtserror.NewErrorNotFound(errors.New(text))
}
- visible, err := p.filter.StatusVisible(ctx, requester, status)
+ visible, err := p.filter.StatusVisible(ctx, requestingAcct, status)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
@@ -90,15 +102,26 @@ func (p *Processor) StatusRepliesGet(
page *paging.Page,
onlyOtherAccounts bool,
) (interface{}, gtserror.WithCode) {
- // Authenticate the incoming request, getting related user accounts.
- requester, receiver, errWithCode := p.authenticate(ctx, requestedUser)
+ // Authenticate incoming request, getting related accounts.
+ auth, errWithCode := p.authenticate(ctx, requestedUser)
if errWithCode != nil {
return nil, errWithCode
}
+ if auth.handshakingURI != nil {
+ // We're currently handshaking, which means
+ // we don't know this account yet. This should
+ // be a very rare race condition.
+ err := gtserror.Newf("network race handshaking %s", auth.handshakingURI)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ receivingAcct := auth.receivingAcct
+ requestingAcct := auth.requestingAcct
+
// Get target status and ensure visible to requester.
status, errWithCode := p.c.GetVisibleTargetStatus(ctx,
- requester,
+ requestingAcct,
statusID,
nil, // default freshness
)
@@ -107,7 +130,7 @@ func (p *Processor) StatusRepliesGet(
}
// Ensure status is by receiving account.
- if status.AccountID != receiver.ID {
+ if status.AccountID != receivingAcct.ID {
const text = "status does not belong to receiving account"
return nil, gtserror.NewErrorNotFound(errors.New(text))
}
@@ -140,7 +163,7 @@ func (p *Processor) StatusRepliesGet(
}
// Reslice replies dropping all those invisible to requester.
- replies, err = p.filter.StatusesVisible(ctx, requester, replies)
+ replies, err = p.filter.StatusesVisible(ctx, requestingAcct, replies)
if err != nil {
err := gtserror.Newf("error filtering status replies: %w", err)
return nil, gtserror.NewErrorInternalError(err)
@@ -151,7 +174,7 @@ func (p *Processor) StatusRepliesGet(
// Start AS collection params.
var params ap.CollectionParams
params.ID = collectionID
- params.Total = len(replies)
+ params.Total = util.Ptr(len(replies))
if page == nil {
// i.e. paging disabled, return collection