summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/update.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-10-04 13:09:42 +0100
committerLibravatar GitHub <noreply@github.com>2023-10-04 13:09:42 +0100
commitc6e00afc7c23df994b70eee89d2d392718e6a321 (patch)
treecee98c1a78e36ba6a0e8183afa0b2796765fe7f6 /internal/federation/federatingdb/update.go
parent[chore] internal/ap: add pollable AS types, code reformatting, general niceti... (diff)
downloadgotosocial-c6e00afc7c23df994b70eee89d2d392718e6a321.tar.xz
[feature] tentatively start adding polls support (#2249)
Diffstat (limited to 'internal/federation/federatingdb/update.go')
-rw-r--r--internal/federation/federatingdb/update.go57
1 files changed, 47 insertions, 10 deletions
diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go
index 8e452eb3c..5d3d4a0ff 100644
--- a/internal/federation/federatingdb/update.go
+++ b/internal/federation/federatingdb/update.go
@@ -56,21 +56,18 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
return nil // Already processed.
}
- switch asType.GetTypeName() {
- case ap.ActorApplication, ap.ActorGroup, ap.ActorOrganization, ap.ActorPerson, ap.ActorService:
- return f.updateAccountable(ctx, receivingAccount, requestingAccount, asType)
+ if accountable, ok := ap.ToAccountable(asType); ok {
+ return f.updateAccountable(ctx, receivingAccount, requestingAccount, accountable)
+ }
+
+ if statusable, ok := ap.ToStatusable(asType); ok {
+ return f.updateStatusable(ctx, receivingAccount, requestingAccount, statusable)
}
return nil
}
-func (f *federatingDB) updateAccountable(ctx context.Context, receivingAcct *gtsmodel.Account, requestingAcct *gtsmodel.Account, asType vocab.Type) error {
- // Ensure delivered asType is a valid Accountable model.
- accountable, ok := asType.(ap.Accountable)
- if !ok {
- return gtserror.Newf("could not convert vocab.Type %T to Accountable", asType)
- }
-
+func (f *federatingDB) updateAccountable(ctx context.Context, receivingAcct *gtsmodel.Account, requestingAcct *gtsmodel.Account, accountable ap.Accountable) error {
// Extract AP URI of the updated Accountable model.
idProp := accountable.GetJSONLDId()
if idProp == nil || !idProp.IsIRI() {
@@ -103,3 +100,43 @@ func (f *federatingDB) updateAccountable(ctx context.Context, receivingAcct *gts
return nil
}
+
+func (f *federatingDB) updateStatusable(ctx context.Context, receivingAcct *gtsmodel.Account, requestingAcct *gtsmodel.Account, statusable ap.Statusable) error {
+ // Extract AP URI of the updated model.
+ idProp := statusable.GetJSONLDId()
+ if idProp == nil || !idProp.IsIRI() {
+ return gtserror.New("invalid id prop")
+ }
+
+ // Get the status URI string for lookups.
+ statusURI := idProp.GetIRI()
+ statusURIStr := statusURI.String()
+
+ // Don't try to update local statuses.
+ if statusURI.Host == config.GetHost() {
+ return nil
+ }
+
+ // Get the status we have on file for this URI string.
+ status, err := f.state.DB.GetStatusByURI(ctx, statusURIStr)
+ if err != nil {
+ 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)
+ }
+
+ // Queue an UPDATE NOTE activity to our fedi API worker,
+ // this will handle necessary database insertions, etc.
+ f.state.Workers.EnqueueFediAPI(ctx, messages.FromFediAPI{
+ APObjectType: ap.ObjectNote,
+ APActivityType: ap.ActivityUpdate,
+ GTSModel: status, // original status
+ APObjectModel: statusable,
+ ReceivingAccount: receivingAcct,
+ })
+
+ return nil
+}