summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/update.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-04 20:21:20 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-04 20:21:20 +0000
commit41435a6c4ee0a5b52528890edf3fbf5a9dc0a6c8 (patch)
tree987b5d7787b24f6f6e340bbcf7fd1b052fe40dfc /internal/federation/federatingdb/update.go
parent[docs/bugfix] fix link to swagger yaml (#2333) (diff)
downloadgotosocial-41435a6c4ee0a5b52528890edf3fbf5a9dc0a6c8.tar.xz
[feature] support canceling scheduled tasks, some federation API performance improvements (#2329)
Diffstat (limited to 'internal/federation/federatingdb/update.go')
-rw-r--r--internal/federation/federatingdb/update.go45
1 files changed, 33 insertions, 12 deletions
diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go
index 5d3d4a0ff..26ea81f72 100644
--- a/internal/federation/federatingdb/update.go
+++ b/internal/federation/federatingdb/update.go
@@ -19,11 +19,13 @@ package federatingdb
import (
"context"
+ "errors"
"codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
@@ -71,18 +73,21 @@ func (f *federatingDB) updateAccountable(ctx context.Context, receivingAcct *gts
// Extract AP URI of the updated Accountable model.
idProp := accountable.GetJSONLDId()
if idProp == nil || !idProp.IsIRI() {
- return gtserror.New("Accountable id prop was nil or not IRI")
+ return gtserror.New("invalid id prop")
}
- updatedAcctURI := idProp.GetIRI()
- // Don't try to update local accounts, it will break things.
- if updatedAcctURI.Host == config.GetHost() {
+ // Get the account URI string for checks
+ accountURI := idProp.GetIRI()
+ accountURIStr := accountURI.String()
+
+ // Don't try to update local accounts.
+ if accountURI.Host == config.GetHost() {
return nil
}
- // Ensure Accountable and requesting account are one and the same.
- if updatedAcctURIStr := updatedAcctURI.String(); requestingAcct.URI != updatedAcctURIStr {
- return gtserror.Newf("update for %s was requested by %s, this is not valid", updatedAcctURIStr, requestingAcct.URI)
+ // Check that update was by the account themselves.
+ if accountURIStr != requestingAcct.URI {
+ return gtserror.Newf("update for %s was not requested by owner", accountURIStr)
}
// Pass in to the processor the existing version of the requesting
@@ -117,15 +122,31 @@ func (f *federatingDB) updateStatusable(ctx context.Context, receivingAcct *gtsm
return nil
}
+ // Check if this is a forwarded object, i.e. did
+ // the account making the request also create this?
+ forwarded := !isSender(statusable, requestingAcct)
+
// Get the status we have on file for this URI string.
status, err := f.state.DB.GetStatusByURI(ctx, statusURIStr)
- if err != nil {
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
return gtserror.Newf("error fetching status from db: %w", err)
}
- // Check that update was by the status author.
- if status.AccountID != requestingAcct.ID {
- return gtserror.Newf("update for %s was not requested by author", statusURIStr)
+ if status == nil {
+ // We haven't seen this status before, be
+ // lenient and handle as a CREATE event.
+ return f.createStatusable(ctx,
+ receivingAcct,
+ requestingAcct,
+ statusable,
+ forwarded,
+ )
+ }
+
+ if forwarded {
+ // For forwarded updates, set a nil AS
+ // status to force refresh from remote.
+ statusable = nil
}
// Queue an UPDATE NOTE activity to our fedi API worker,
@@ -134,7 +155,7 @@ func (f *federatingDB) updateStatusable(ctx context.Context, receivingAcct *gtsm
APObjectType: ap.ObjectNote,
APActivityType: ap.ActivityUpdate,
GTSModel: status, // original status
- APObjectModel: statusable,
+ APObjectModel: (ap.Statusable)(statusable),
ReceivingAccount: receivingAcct,
})