2021-05-28 20:47:18 +00:00
|
|
|
package typeutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/go-fed/activity/streams"
|
|
|
|
"github.com/go-fed/activity/streams/vocab"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2021-06-13 16:42:28 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
2021-05-28 20:47:18 +00:00
|
|
|
"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
|
2021-06-13 16:42:28 +00:00
|
|
|
|
|
|
|
newID, err := id.NewRandomULID()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
idString := util.GenerateURIForUpdate(originAccount.Username, c.config.Protocol, c.config.Host, newID)
|
2021-05-28 20:47:18 +00:00
|
|
|
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
|
|
|
|
}
|