summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb/accept.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/accept.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/accept.go')
-rw-r--r--internal/federation/federatingdb/accept.go69
1 files changed, 38 insertions, 31 deletions
diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go
index 1c514d035..38b6b9300 100644
--- a/internal/federation/federatingdb/accept.go
+++ b/internal/federation/federatingdb/accept.go
@@ -46,28 +46,29 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
return nil // Already processed.
}
- acceptObject := accept.GetActivityStreamsObject()
- if acceptObject == nil {
- return errors.New("ACCEPT: no object set on vocab.ActivityStreamsAccept")
- }
+ // Iterate all provided objects in the activity.
+ for _, object := range ap.ExtractObjects(accept) {
+
+ // Check and handle any vocab.Type objects.
+ if objType := object.GetType(); objType != nil {
+ switch objType.GetTypeName() { //nolint:gocritic
- for iter := acceptObject.Begin(); iter != acceptObject.End(); iter = iter.Next() {
- // check if the object is an IRI
- if iter.IsIRI() {
- // we have just the URI of whatever is being accepted, so we need to find out what it is
- acceptedObjectIRI := iter.GetIRI()
- if uris.IsFollowPath(acceptedObjectIRI) {
- // ACCEPT FOLLOW
- followReq, err := f.state.DB.GetFollowRequestByURI(ctx, acceptedObjectIRI.String())
+ case ap.ActivityFollow:
+ // Cast the vocab.Type object to known AS type.
+ asFollow := objType.(vocab.ActivityStreamsFollow)
+
+ // convert the follow to something we can understand
+ gtsFollow, err := f.converter.ASFollowToFollow(ctx, asFollow)
if err != nil {
- return fmt.Errorf("ACCEPT: couldn't get follow request with id %s from the database: %s", acceptedObjectIRI.String(), err)
+ return fmt.Errorf("ACCEPT: error converting asfollow to gtsfollow: %s", err)
}
// make sure the addressee of the original follow is the same as whatever inbox this landed in
- if followReq.AccountID != receivingAccount.ID {
+ if gtsFollow.AccountID != receivingAccount.ID {
return errors.New("ACCEPT: follow object account and inbox account were not the same")
}
- follow, err := f.state.DB.AcceptFollowRequest(ctx, followReq.AccountID, followReq.TargetAccountID)
+
+ follow, err := f.state.DB.AcceptFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID)
if err != nil {
return err
}
@@ -78,31 +79,36 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
GTSModel: follow,
ReceivingAccount: receivingAccount,
})
-
- return nil
}
- }
- // check if iter is an AP object / type
- if iter.GetType() == nil {
continue
}
- if iter.GetType().GetTypeName() == ap.ActivityFollow {
- // ACCEPT FOLLOW
- asFollow, ok := iter.GetType().(vocab.ActivityStreamsFollow)
- if !ok {
- return errors.New("ACCEPT: couldn't parse follow into vocab.ActivityStreamsFollow")
+
+ // Check and handle any
+ // IRI type objects.
+ if object.IsIRI() {
+
+ // Extract IRI from object.
+ iri := object.GetIRI()
+ if !uris.IsFollowPath(iri) {
+ continue
}
- // convert the follow to something we can understand
- gtsFollow, err := f.converter.ASFollowToFollow(ctx, asFollow)
+
+ // Serialize IRI.
+ iriStr := iri.String()
+
+ // ACCEPT FOLLOW
+ followReq, err := f.state.DB.GetFollowRequestByURI(ctx, iriStr)
if err != nil {
- return fmt.Errorf("ACCEPT: error converting asfollow to gtsfollow: %s", err)
+ return fmt.Errorf("ACCEPT: couldn't get follow request with id %s from the database: %s", iriStr, err)
}
+
// make sure the addressee of the original follow is the same as whatever inbox this landed in
- if gtsFollow.AccountID != receivingAccount.ID {
+ if followReq.AccountID != receivingAccount.ID {
return errors.New("ACCEPT: follow object account and inbox account were not the same")
}
- follow, err := f.state.DB.AcceptFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID)
+
+ follow, err := f.state.DB.AcceptFollowRequest(ctx, followReq.AccountID, followReq.TargetAccountID)
if err != nil {
return err
}
@@ -114,8 +120,9 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
ReceivingAccount: receivingAccount,
})
- return nil
+ continue
}
+
}
return nil