summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar tsmethurst <tobi.smethurst@klarrio.com>2021-05-28 22:47:18 +0200
committerLibravatar tsmethurst <tobi.smethurst@klarrio.com>2021-05-28 22:47:18 +0200
commitcb54324430e7c4640a7aa5aac24932b5e91b71c4 (patch)
treea5193ee09656d808f589de20f77a5a455a5a6683 /internal/typeutils
parentAnnounce/boost (#35) (diff)
downloadgotosocial-cb54324430e7c4640a7aa5aac24932b5e91b71c4.tar.xz
federate account updates
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/converter.go7
-rw-r--r--internal/typeutils/wrap.go61
2 files changed, 68 insertions, 0 deletions
diff --git a/internal/typeutils/converter.go b/internal/typeutils/converter.go
index 93ac6bd84..9cd7ad9b4 100644
--- a/internal/typeutils/converter.go
+++ b/internal/typeutils/converter.go
@@ -141,6 +141,13 @@ type TypeConverter interface {
FollowRequestToFollow(f *gtsmodel.FollowRequest) *gtsmodel.Follow
// StatusToBoost wraps the given status into a boosting status.
StatusToBoost(s *gtsmodel.Status, boostingAccount *gtsmodel.Account) (*gtsmodel.Status, error)
+
+ /*
+ WRAPPER CONVENIENCE FUNCTIONS
+ */
+
+ // WrapPersonInUpdate
+ WrapPersonInUpdate(person vocab.ActivityStreamsPerson, originAccount *gtsmodel.Account) (vocab.ActivityStreamsUpdate, error)
}
type converter struct {
diff --git a/internal/typeutils/wrap.go b/internal/typeutils/wrap.go
new file mode 100644
index 000000000..fde6fda79
--- /dev/null
+++ b/internal/typeutils/wrap.go
@@ -0,0 +1,61 @@
+package typeutils
+
+import (
+ "fmt"
+ "net/url"
+
+ "github.com/go-fed/activity/streams"
+ "github.com/go-fed/activity/streams/vocab"
+ "github.com/google/uuid"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
+)
+
+func (c *converter) WrapPersonInUpdate(person vocab.ActivityStreamsPerson, originAccount *gtsmodel.Account) (vocab.ActivityStreamsUpdate, error) {
+
+ update := streams.NewActivityStreamsUpdate()
+
+ // set the actor
+ actorURI, err := url.Parse(originAccount.URI)
+ if err != nil {
+ return nil, fmt.Errorf("WrapPersonInUpdate: error parsing url %s: %s", originAccount.URI, err)
+ }
+ actorProp := streams.NewActivityStreamsActorProperty()
+ actorProp.AppendIRI(actorURI)
+ update.SetActivityStreamsActor(actorProp)
+
+ // set the ID
+ idString := util.GenerateURIForUpdate(originAccount.Username, c.config.Protocol, c.config.Host, uuid.NewString())
+ idURI, err := url.Parse(idString)
+ if err != nil {
+ return nil, fmt.Errorf("WrapPersonInUpdate: error parsing url %s: %s", idString, err)
+ }
+ idProp := streams.NewJSONLDIdProperty()
+ idProp.SetIRI(idURI)
+ update.SetJSONLDId(idProp)
+
+ // set the person as the object here
+ objectProp := streams.NewActivityStreamsObjectProperty()
+ objectProp.AppendActivityStreamsPerson(person)
+ update.SetActivityStreamsObject(objectProp)
+
+ // to should be public
+ toURI, err := url.Parse(asPublicURI)
+ if err != nil {
+ return nil, fmt.Errorf("WrapPersonInUpdate: error parsing url %s: %s", asPublicURI, err)
+ }
+ toProp := streams.NewActivityStreamsToProperty()
+ toProp.AppendIRI(toURI)
+ update.SetActivityStreamsTo(toProp)
+
+ // bcc followers
+ followersURI, err := url.Parse(originAccount.FollowersURI)
+ if err != nil {
+ return nil, fmt.Errorf("WrapPersonInUpdate: error parsing url %s: %s", originAccount.FollowersURI, err)
+ }
+ bccProp := streams.NewActivityStreamsBccProperty()
+ bccProp.AppendIRI(followersURI)
+ update.SetActivityStreamsBcc(bccProp)
+
+ return update, nil
+}