mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-22 07:07:29 -06:00
get remote follows/accepts working
This commit is contained in:
parent
c7b4f847d8
commit
d69786ef17
16 changed files with 459 additions and 104 deletions
|
|
@ -99,7 +99,7 @@ type TypeConverter interface {
|
|||
ASFollowToFollowRequest(followable Followable) (*gtsmodel.FollowRequest, error)
|
||||
// ASFollowToFollowRequest converts a remote activitystreams `follow` representation into gts model follow.
|
||||
ASFollowToFollow(followable Followable) (*gtsmodel.Follow, error)
|
||||
|
||||
|
||||
/*
|
||||
INTERNAL (gts) MODEL TO ACTIVITYSTREAMS MODEL
|
||||
*/
|
||||
|
|
@ -109,6 +109,9 @@ type TypeConverter interface {
|
|||
|
||||
// StatusToAS converts a gts model status into an activity streams note, suitable for federation
|
||||
StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, error)
|
||||
|
||||
// FollowToASFollow converts a gts model Follow into an activity streams Follow, suitable for federation
|
||||
FollowToAS(f *gtsmodel.Follow, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (vocab.ActivityStreamsFollow, error)
|
||||
}
|
||||
|
||||
type converter struct {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package typeutils
|
|||
import (
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/go-fed/activity/streams"
|
||||
|
|
@ -258,3 +259,49 @@ func (c *converter) AccountToAS(a *gtsmodel.Account) (vocab.ActivityStreamsPerso
|
|||
func (c *converter) StatusToAS(s *gtsmodel.Status) (vocab.ActivityStreamsNote, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *converter) FollowToAS(f *gtsmodel.Follow, originAccount *gtsmodel.Account, targetAccount *gtsmodel.Account) (vocab.ActivityStreamsFollow, error) {
|
||||
// parse out the various URIs we need for this
|
||||
// origin account (who's doing the follow)
|
||||
originAccountURI, err := url.Parse(originAccount.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("followtoasfollow: error parsing origin account uri: %s", err)
|
||||
}
|
||||
originActor := streams.NewActivityStreamsActorProperty()
|
||||
originActor.AppendIRI(originAccountURI)
|
||||
|
||||
// target account (who's being followed)
|
||||
targetAccountURI, err := url.Parse(targetAccount.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("followtoasfollow: error parsing target account uri: %s", err)
|
||||
}
|
||||
|
||||
// uri of the folow activity itself
|
||||
followURI, err := url.Parse(f.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("followtoasfollow: error parsing follow uri: %s", err)
|
||||
}
|
||||
|
||||
// start preparing the follow activity
|
||||
follow := streams.NewActivityStreamsFollow()
|
||||
|
||||
// set the actor
|
||||
follow.SetActivityStreamsActor(originActor)
|
||||
|
||||
// set the id
|
||||
followIDProp := streams.NewJSONLDIdProperty()
|
||||
followIDProp.SetIRI(followURI)
|
||||
follow.SetJSONLDId(followIDProp)
|
||||
|
||||
// set the object
|
||||
followObjectProp := streams.NewActivityStreamsObjectProperty()
|
||||
followObjectProp.AppendIRI(targetAccountURI)
|
||||
follow.SetActivityStreamsObject(followObjectProp)
|
||||
|
||||
// set the To property
|
||||
followToProp := streams.NewActivityStreamsToProperty()
|
||||
followToProp.AppendIRI(targetAccountURI)
|
||||
follow.SetActivityStreamsTo(followToProp)
|
||||
|
||||
return follow, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue