summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-11-22 12:48:46 +0100
committerLibravatar GitHub <noreply@github.com>2021-11-22 12:48:46 +0100
commitb46e5fb65d10be79f553505dc25e575de97f142f (patch)
treeb1c3c04c34a9400d3813f7d6889f91f6aa765dc9 /internal/typeutils
parentFix image description unnecessarily html-escaping innocent characters (#321) (diff)
downloadgotosocial-b46e5fb65d10be79f553505dc25e575de97f142f.tar.xz
Fix incorrect target being used in CC prop for mentioning statuses (#322)
* hardcode time on admin_account_status_3 * add test for as status with mention * fix incorrect target URI being used for mentions
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/internaltoas.go16
-rw-r--r--internal/typeutils/internaltoas_test.go19
2 files changed, 27 insertions, 8 deletions
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index 7afb65f21..ae8e3b1f2 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -464,9 +464,9 @@ func (c *converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (vocab.A
case gtsmodel.VisibilityDirect:
// if DIRECT, then only mentioned users should be added to TO, and nothing to CC
for _, m := range s.Mentions {
- iri, err := url.Parse(m.OriginAccount.URI)
+ iri, err := url.Parse(m.TargetAccount.URI)
if err != nil {
- return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
+ return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.TargetAccount.URI, err)
}
toProp.AppendIRI(iri)
}
@@ -476,9 +476,9 @@ func (c *converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (vocab.A
// if FOLLOWERS ONLY then we want to add followers to TO, and mentions to CC
toProp.AppendIRI(authorFollowersURI)
for _, m := range s.Mentions {
- iri, err := url.Parse(m.OriginAccount.URI)
+ iri, err := url.Parse(m.TargetAccount.URI)
if err != nil {
- return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
+ return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.TargetAccount.URI, err)
}
ccProp.AppendIRI(iri)
}
@@ -487,9 +487,9 @@ func (c *converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (vocab.A
toProp.AppendIRI(authorFollowersURI)
ccProp.AppendIRI(publicURI)
for _, m := range s.Mentions {
- iri, err := url.Parse(m.OriginAccount.URI)
+ iri, err := url.Parse(m.TargetAccount.URI)
if err != nil {
- return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
+ return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.TargetAccount.URI, err)
}
ccProp.AppendIRI(iri)
}
@@ -498,9 +498,9 @@ func (c *converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (vocab.A
toProp.AppendIRI(publicURI)
ccProp.AppendIRI(authorFollowersURI)
for _, m := range s.Mentions {
- iri, err := url.Parse(m.OriginAccount.URI)
+ iri, err := url.Parse(m.TargetAccount.URI)
if err != nil {
- return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.OriginAccount.URI, err)
+ return nil, fmt.Errorf("StatusToAS: error parsing uri %s: %s", m.TargetAccount.URI, err)
}
ccProp.AppendIRI(iri)
}
diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go
index da7dc883a..50f02c24a 100644
--- a/internal/typeutils/internaltoas_test.go
+++ b/internal/typeutils/internaltoas_test.go
@@ -91,6 +91,25 @@ func (suite *InternalToASTestSuite) TestStatusToAS() {
suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","attachment":[],"attributedTo":"http://localhost:8080/users/the_mighty_zork","cc":"http://localhost:8080/users/the_mighty_zork/followers","content":"hello everyone!","id":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY","published":"2021-10-20T12:40:37+02:00","replies":{"first":{"id":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies?page=true","next":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies?only_other_accounts=false\u0026page=true","partOf":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies","type":"CollectionPage"},"id":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/replies","type":"Collection"},"sensitive":true,"summary":"introduction post","tag":[],"to":"https://www.w3.org/ns/activitystreams#Public","type":"Note","url":"http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY"}`, string(bytes))
}
+func (suite *InternalToASTestSuite) TestStatusToASWithMentions() {
+ testStatusID := suite.testStatuses["admin_account_status_3"].ID
+ ctx := context.Background()
+
+ testStatus, err := suite.db.GetStatusByID(ctx, testStatusID)
+ suite.NoError(err)
+
+ asStatus, err := suite.typeconverter.StatusToAS(ctx, testStatus)
+ suite.NoError(err)
+
+ ser, err := streams.Serialize(asStatus)
+ assert.NoError(suite.T(), err)
+
+ bytes, err := json.Marshal(ser)
+ suite.NoError(err)
+
+ suite.Equal(`{"@context":"https://www.w3.org/ns/activitystreams","attachment":[],"attributedTo":"http://localhost:8080/users/admin","cc":["http://localhost:8080/users/admin/followers","http://localhost:8080/users/the_mighty_zork"],"content":"hi @the_mighty_zork welcome to the instance!","id":"http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0","inReplyTo":"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY","published":"2021-11-20T13:32:16Z","replies":{"first":{"id":"http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies?page=true","next":"http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies?only_other_accounts=false\u0026page=true","partOf":"http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies","type":"CollectionPage"},"id":"http://localhost:8080/users/admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0/replies","type":"Collection"},"sensitive":false,"summary":"","tag":{"href":"http://localhost:8080/users/the_mighty_zork","name":"@the_mighty_zork@localhost:8080","type":"Mention"},"to":"https://www.w3.org/ns/activitystreams#Public","type":"Note","url":"http://localhost:8080/@admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0"}`, string(bytes))
+}
+
func (suite *InternalToASTestSuite) TestStatusToASNotSensitive() {
testStatus := suite.testStatuses["admin_account_status_1"]