summaryrefslogtreecommitdiff
path: root/internal/typeutils/wrap.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-06-17 17:49:11 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-17 16:49:11 +0100
commitd8e16a226a570a7d262bdeb067273ce35b03cc7c (patch)
tree94a09ebe5501c01159efb8aa3e74d70da8db2f87 /internal/typeutils/wrap.go
parent[bugfix] Accept non-multipart forms for account updates (#1896) (diff)
downloadgotosocial-d8e16a226a570a7d262bdeb067273ce35b03cc7c.tar.xz
[chore/bugfix] Refactor `ap/extract.go` functions, return URIs more reliably (#1897)
Diffstat (limited to 'internal/typeutils/wrap.go')
-rw-r--r--internal/typeutils/wrap.go49
1 files changed, 32 insertions, 17 deletions
diff --git a/internal/typeutils/wrap.go b/internal/typeutils/wrap.go
index c81bf14f1..71099cbee 100644
--- a/internal/typeutils/wrap.go
+++ b/internal/typeutils/wrap.go
@@ -1,13 +1,30 @@
+// GoToSocial
+// Copyright (C) GoToSocial Authors admin@gotosocial.org
+// SPDX-License-Identifier: AGPL-3.0-or-later
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
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/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/uris"
@@ -19,7 +36,7 @@ func (c *converter) WrapPersonInUpdate(person vocab.ActivityStreamsPerson, origi
// 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)
+ return nil, gtserror.Newf("error parsing url %s: %w", originAccount.URI, err)
}
actorProp := streams.NewActivityStreamsActorProperty()
actorProp.AppendIRI(actorURI)
@@ -35,7 +52,7 @@ func (c *converter) WrapPersonInUpdate(person vocab.ActivityStreamsPerson, origi
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)
+ return nil, gtserror.Newf("error parsing url %s: %w", idString, err)
}
idProp := streams.NewJSONLDIdProperty()
idProp.SetIRI(idURI)
@@ -49,7 +66,7 @@ func (c *converter) WrapPersonInUpdate(person vocab.ActivityStreamsPerson, origi
// 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)
+ return nil, gtserror.Newf("error parsing url %s: %w", pub.PublicActivityPubIRI, err)
}
toProp := streams.NewActivityStreamsToProperty()
toProp.AppendIRI(toURI)
@@ -58,7 +75,7 @@ func (c *converter) WrapPersonInUpdate(person vocab.ActivityStreamsPerson, origi
// bcc followers
followersURI, err := url.Parse(originAccount.FollowersURI)
if err != nil {
- return nil, fmt.Errorf("WrapPersonInUpdate: error parsing url %s: %s", originAccount.FollowersURI, err)
+ return nil, gtserror.Newf("error parsing url %s: %w", originAccount.FollowersURI, err)
}
bccProp := streams.NewActivityStreamsBccProperty()
bccProp.AppendIRI(followersURI)
@@ -81,7 +98,7 @@ func (c *converter) WrapNoteInCreate(note vocab.ActivityStreamsNote, objectIRIOn
// ID property
idProp := streams.NewJSONLDIdProperty()
- createID := fmt.Sprintf("%s/activity", note.GetJSONLDId().GetIRI().String())
+ createID := note.GetJSONLDId().GetIRI().String() + "/activity"
createIDIRI, err := url.Parse(createID)
if err != nil {
return nil, err
@@ -91,9 +108,9 @@ func (c *converter) WrapNoteInCreate(note vocab.ActivityStreamsNote, objectIRIOn
// Actor Property
actorProp := streams.NewActivityStreamsActorProperty()
- actorIRI, err := ap.ExtractAttributedTo(note)
+ actorIRI, err := ap.ExtractAttributedToURI(note)
if err != nil {
- return nil, fmt.Errorf("WrapNoteInCreate: couldn't extract AttributedTo: %s", err)
+ return nil, gtserror.Newf("couldn't extract AttributedTo: %w", err)
}
actorProp.AppendIRI(actorIRI)
create.SetActivityStreamsActor(actorProp)
@@ -102,27 +119,25 @@ func (c *converter) WrapNoteInCreate(note vocab.ActivityStreamsNote, objectIRIOn
publishedProp := streams.NewActivityStreamsPublishedProperty()
published, err := ap.ExtractPublished(note)
if err != nil {
- return nil, fmt.Errorf("WrapNoteInCreate: couldn't extract Published: %s", err)
+ return nil, gtserror.Newf("couldn't extract Published: %w", 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)
+ if toURIs := ap.ExtractToURIs(note); len(toURIs) != 0 {
+ for _, toURI := range toURIs {
+ toProp.AppendIRI(toURI)
}
create.SetActivityStreamsTo(toProp)
}
// Cc Property
ccProp := streams.NewActivityStreamsCcProperty()
- ccs, err := ap.ExtractCCs(note)
- if err == nil {
- for _, cc := range ccs {
- ccProp.AppendIRI(cc)
+ if ccURIs := ap.ExtractCcURIs(note); len(ccURIs) != 0 {
+ for _, ccURI := range ccURIs {
+ ccProp.AppendIRI(ccURI)
}
create.SetActivityStreamsCc(ccProp)
}