mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-12-08 06:32:22 +01:00
098dbe6ff4
* first commit Signed-off-by: kim <grufwub@gmail.com> * replace logging with our own log library Signed-off-by: kim <grufwub@gmail.com> * fix imports Signed-off-by: kim <grufwub@gmail.com> * fix log imports Signed-off-by: kim <grufwub@gmail.com> * add license text Signed-off-by: kim <grufwub@gmail.com> * fix package import cycle between config and log package Signed-off-by: kim <grufwub@gmail.com> * fix empty kv.Fields{} being passed to WithFields() Signed-off-by: kim <grufwub@gmail.com> * fix uses of log.WithFields() with whitespace issues and empty slices Signed-off-by: kim <grufwub@gmail.com> * *linter related grumbling* Signed-off-by: kim <grufwub@gmail.com> * gofmt the codebase! also fix more log.WithFields() formatting issues Signed-off-by: kim <grufwub@gmail.com> * update testrig code to match new changes Signed-off-by: kim <grufwub@gmail.com> * fix error wrapping in non fmt.Errorf function Signed-off-by: kim <grufwub@gmail.com> * add benchmarking of log.Caller() vs non-cached Signed-off-by: kim <grufwub@gmail.com> * fix syslog tests, add standard build tags to test runner to ensure consistency Signed-off-by: kim <grufwub@gmail.com> * make syslog tests more robust Signed-off-by: kim <grufwub@gmail.com> * fix caller depth arithmatic (is that how you spell it?) Signed-off-by: kim <grufwub@gmail.com> * update to use unkeyed fields in kv.Field{} instances Signed-off-by: kim <grufwub@gmail.com> * update go-kv library Signed-off-by: kim <grufwub@gmail.com> * update libraries list Signed-off-by: kim <grufwub@gmail.com> * fuck you linter get nerfed Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
132 lines
3.9 KiB
Go
132 lines
3.9 KiB
Go
package typeutils
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/superseriousbusiness/activity/pub"
|
|
"github.com/superseriousbusiness/activity/streams"
|
|
"github.com/superseriousbusiness/activity/streams/vocab"
|
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
|
"github.com/superseriousbusiness/gotosocial/internal/uris"
|
|
)
|
|
|
|
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
|
|
|
|
newID, err := id.NewRandomULID()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
idString := uris.GenerateURIForUpdate(originAccount.Username, newID)
|
|
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(pub.PublicActivityPubIRI)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("WrapPersonInUpdate: error parsing url %s: %s", pub.PublicActivityPubIRI, 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
|
|
}
|
|
|
|
func (c *converter) WrapNoteInCreate(note vocab.ActivityStreamsNote, objectIRIOnly bool) (vocab.ActivityStreamsCreate, error) {
|
|
create := streams.NewActivityStreamsCreate()
|
|
|
|
// Object property
|
|
objectProp := streams.NewActivityStreamsObjectProperty()
|
|
if objectIRIOnly {
|
|
objectProp.AppendIRI(note.GetJSONLDId().GetIRI())
|
|
} else {
|
|
objectProp.AppendActivityStreamsNote(note)
|
|
}
|
|
create.SetActivityStreamsObject(objectProp)
|
|
|
|
// ID property
|
|
idProp := streams.NewJSONLDIdProperty()
|
|
createID := fmt.Sprintf("%s/activity", note.GetJSONLDId().GetIRI().String())
|
|
createIDIRI, err := url.Parse(createID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
idProp.SetIRI(createIDIRI)
|
|
create.SetJSONLDId(idProp)
|
|
|
|
// Actor Property
|
|
actorProp := streams.NewActivityStreamsActorProperty()
|
|
actorIRI, err := ap.ExtractAttributedTo(note)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("WrapNoteInCreate: couldn't extract AttributedTo: %s", err)
|
|
}
|
|
actorProp.AppendIRI(actorIRI)
|
|
create.SetActivityStreamsActor(actorProp)
|
|
|
|
// Published Property
|
|
publishedProp := streams.NewActivityStreamsPublishedProperty()
|
|
published, err := ap.ExtractPublished(note)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("WrapNoteInCreate: couldn't extract Published: %s", err)
|
|
}
|
|
publishedProp.Set(published)
|
|
create.SetActivityStreamsPublished(publishedProp)
|
|
|
|
// To Property
|
|
toProp := streams.NewActivityStreamsToProperty()
|
|
tos, err := ap.ExtractTos(note)
|
|
if err == nil {
|
|
for _, to := range tos {
|
|
toProp.AppendIRI(to)
|
|
}
|
|
create.SetActivityStreamsTo(toProp)
|
|
}
|
|
|
|
// Cc Property
|
|
ccProp := streams.NewActivityStreamsCcProperty()
|
|
ccs, err := ap.ExtractCCs(note)
|
|
if err == nil {
|
|
for _, cc := range ccs {
|
|
ccProp.AppendIRI(cc)
|
|
}
|
|
create.SetActivityStreamsCc(ccProp)
|
|
}
|
|
|
|
return create, nil
|
|
}
|