mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-23 02:32:12 +00:00
Fix mentions not notifying (#230)
* set default privacy for new accounts * teshts * found it * tiny change * aaaa
This commit is contained in:
parent
e0f36278a0
commit
2e5dcc2929
100
internal/ap/extract_test.go
Normal file
100
internal/ap/extract_test.go
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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 ap_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-fed/activity/streams"
|
||||||
|
"github.com/go-fed/activity/streams/vocab"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||||
|
)
|
||||||
|
|
||||||
|
func document1() vocab.ActivityStreamsDocument {
|
||||||
|
d := streams.NewActivityStreamsDocument()
|
||||||
|
|
||||||
|
dMediaType := streams.NewActivityStreamsMediaTypeProperty()
|
||||||
|
dMediaType.Set("image/jpeg")
|
||||||
|
d.SetActivityStreamsMediaType(dMediaType)
|
||||||
|
|
||||||
|
dURL := streams.NewActivityStreamsUrlProperty()
|
||||||
|
dURL.AppendIRI(testrig.URLMustParse("https://s3-us-west-2.amazonaws.com/plushcity/media_attachments/files/106/867/380/219/163/828/original/88e8758c5f011439.jpg"))
|
||||||
|
d.SetActivityStreamsUrl(dURL)
|
||||||
|
|
||||||
|
dName := streams.NewActivityStreamsNameProperty()
|
||||||
|
dName.AppendXMLSchemaString("It's a cute plushie.")
|
||||||
|
d.SetActivityStreamsName(dName)
|
||||||
|
|
||||||
|
dBlurhash := streams.NewTootBlurhashProperty()
|
||||||
|
dBlurhash.Set("UxQ0EkRP_4tRxtRjWBt7%hozM_ayV@oLf6WB")
|
||||||
|
d.SetTootBlurhash(dBlurhash)
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func attachment1() vocab.ActivityStreamsAttachmentProperty {
|
||||||
|
a := streams.NewActivityStreamsAttachmentProperty()
|
||||||
|
a.AppendActivityStreamsDocument(document1())
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func noteWithMentions1() vocab.ActivityStreamsNote {
|
||||||
|
note := streams.NewActivityStreamsNote()
|
||||||
|
|
||||||
|
tags := streams.NewActivityStreamsTagProperty()
|
||||||
|
|
||||||
|
mention1 := streams.NewActivityStreamsMention()
|
||||||
|
|
||||||
|
mention1Href := streams.NewActivityStreamsHrefProperty()
|
||||||
|
mention1Href.Set(testrig.URLMustParse("https://gts.superseriousbusiness.org/users/dumpsterqueer"))
|
||||||
|
mention1.SetActivityStreamsHref(mention1Href)
|
||||||
|
|
||||||
|
mention1Name := streams.NewActivityStreamsNameProperty()
|
||||||
|
mention1Name.AppendXMLSchemaString("@dumpsterqueer@superseriousbusiness.org")
|
||||||
|
mention1.SetActivityStreamsName(mention1Name)
|
||||||
|
|
||||||
|
mention2 := streams.NewActivityStreamsMention()
|
||||||
|
|
||||||
|
mention2Href := streams.NewActivityStreamsHrefProperty()
|
||||||
|
mention2Href.Set(testrig.URLMustParse("https://gts.superseriousbusiness.org/users/f0x"))
|
||||||
|
mention2.SetActivityStreamsHref(mention2Href)
|
||||||
|
|
||||||
|
mention2Name := streams.NewActivityStreamsNameProperty()
|
||||||
|
mention2Name.AppendXMLSchemaString("@f0x@superseriousbusiness.org")
|
||||||
|
mention2.SetActivityStreamsName(mention2Name)
|
||||||
|
|
||||||
|
tags.AppendActivityStreamsMention(mention1)
|
||||||
|
tags.AppendActivityStreamsMention(mention2)
|
||||||
|
|
||||||
|
note.SetActivityStreamsTag(tags)
|
||||||
|
|
||||||
|
return note
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExtractTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
document1 vocab.ActivityStreamsDocument
|
||||||
|
attachment1 vocab.ActivityStreamsAttachmentProperty
|
||||||
|
noteWithMentions1 vocab.ActivityStreamsNote
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ExtractTestSuite) SetupTest() {
|
||||||
|
suite.document1 = document1()
|
||||||
|
suite.attachment1 = attachment1()
|
||||||
|
suite.noteWithMentions1 = noteWithMentions1()
|
||||||
|
}
|
|
@ -22,47 +22,17 @@
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-fed/activity/streams"
|
"github.com/go-fed/activity/streams"
|
||||||
"github.com/go-fed/activity/streams/vocab"
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func document1() vocab.ActivityStreamsDocument {
|
type ExtractAttachmentsTestSuite struct {
|
||||||
document1 := streams.NewActivityStreamsDocument()
|
ExtractTestSuite
|
||||||
|
|
||||||
document1MediaType := streams.NewActivityStreamsMediaTypeProperty()
|
|
||||||
document1MediaType.Set("image/jpeg")
|
|
||||||
document1.SetActivityStreamsMediaType(document1MediaType)
|
|
||||||
|
|
||||||
document1URL := streams.NewActivityStreamsUrlProperty()
|
|
||||||
document1URL.AppendIRI(testrig.URLMustParse("https://s3-us-west-2.amazonaws.com/plushcity/media_attachments/files/106/867/380/219/163/828/original/88e8758c5f011439.jpg"))
|
|
||||||
document1.SetActivityStreamsUrl(document1URL)
|
|
||||||
|
|
||||||
document1Name := streams.NewActivityStreamsNameProperty()
|
|
||||||
document1Name.AppendXMLSchemaString("It's a cute plushie.")
|
|
||||||
document1.SetActivityStreamsName(document1Name)
|
|
||||||
|
|
||||||
document1Blurhash := streams.NewTootBlurhashProperty()
|
|
||||||
document1Blurhash.Set("UxQ0EkRP_4tRxtRjWBt7%hozM_ayV@oLf6WB")
|
|
||||||
document1.SetTootBlurhash(document1Blurhash)
|
|
||||||
|
|
||||||
return document1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func attachment1() vocab.ActivityStreamsAttachmentProperty {
|
func (suite *ExtractAttachmentsTestSuite) TestExtractAttachments() {
|
||||||
attachment1 := streams.NewActivityStreamsAttachmentProperty()
|
|
||||||
attachment1.AppendActivityStreamsDocument(document1())
|
|
||||||
return attachment1
|
|
||||||
}
|
|
||||||
|
|
||||||
type ExtractTestSuite struct {
|
|
||||||
suite.Suite
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *ExtractTestSuite) TestExtractAttachments() {
|
|
||||||
note := streams.NewActivityStreamsNote()
|
note := streams.NewActivityStreamsNote()
|
||||||
note.SetActivityStreamsAttachment(attachment1())
|
note.SetActivityStreamsAttachment(suite.attachment1)
|
||||||
|
|
||||||
attachments, err := ap.ExtractAttachments(note)
|
attachments, err := ap.ExtractAttachments(note)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
@ -75,7 +45,7 @@ func (suite *ExtractTestSuite) TestExtractAttachments() {
|
||||||
suite.Empty(attachment1.Blurhash) // atm we discard blurhashes and generate them ourselves during processing
|
suite.Empty(attachment1.Blurhash) // atm we discard blurhashes and generate them ourselves during processing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ExtractTestSuite) TestExtractNoAttachments() {
|
func (suite *ExtractAttachmentsTestSuite) TestExtractNoAttachments() {
|
||||||
note := streams.NewActivityStreamsNote()
|
note := streams.NewActivityStreamsNote()
|
||||||
|
|
||||||
attachments, err := ap.ExtractAttachments(note)
|
attachments, err := ap.ExtractAttachments(note)
|
||||||
|
@ -83,8 +53,8 @@ func (suite *ExtractTestSuite) TestExtractNoAttachments() {
|
||||||
suite.Empty(attachments)
|
suite.Empty(attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ExtractTestSuite) TestExtractAttachmentsMissingContentType() {
|
func (suite *ExtractAttachmentsTestSuite) TestExtractAttachmentsMissingContentType() {
|
||||||
d1 := document1()
|
d1 := suite.document1
|
||||||
d1.SetActivityStreamsMediaType(streams.NewActivityStreamsMediaTypeProperty())
|
d1.SetActivityStreamsMediaType(streams.NewActivityStreamsMediaTypeProperty())
|
||||||
|
|
||||||
a1 := streams.NewActivityStreamsAttachmentProperty()
|
a1 := streams.NewActivityStreamsAttachmentProperty()
|
||||||
|
@ -98,9 +68,8 @@ func (suite *ExtractTestSuite) TestExtractAttachmentsMissingContentType() {
|
||||||
suite.Empty(attachments)
|
suite.Empty(attachments)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ExtractTestSuite) TestExtractAttachmentMissingContentType() {
|
func (suite *ExtractAttachmentsTestSuite) TestExtractAttachmentMissingContentType() {
|
||||||
|
d1 := suite.document1
|
||||||
d1 := document1()
|
|
||||||
d1.SetActivityStreamsMediaType(streams.NewActivityStreamsMediaTypeProperty())
|
d1.SetActivityStreamsMediaType(streams.NewActivityStreamsMediaTypeProperty())
|
||||||
|
|
||||||
attachment, err := ap.ExtractAttachment(d1)
|
attachment, err := ap.ExtractAttachment(d1)
|
||||||
|
@ -108,8 +77,8 @@ func (suite *ExtractTestSuite) TestExtractAttachmentMissingContentType() {
|
||||||
suite.Nil(attachment)
|
suite.Nil(attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ExtractTestSuite) TestExtractAttachmentMissingURL() {
|
func (suite *ExtractAttachmentsTestSuite) TestExtractAttachmentMissingURL() {
|
||||||
d1 := document1()
|
d1 := suite.document1
|
||||||
d1.SetActivityStreamsUrl(streams.NewActivityStreamsUrlProperty())
|
d1.SetActivityStreamsUrl(streams.NewActivityStreamsUrlProperty())
|
||||||
|
|
||||||
attachment, err := ap.ExtractAttachment(d1)
|
attachment, err := ap.ExtractAttachment(d1)
|
||||||
|
@ -117,6 +86,6 @@ func (suite *ExtractTestSuite) TestExtractAttachmentMissingURL() {
|
||||||
suite.Nil(attachment)
|
suite.Nil(attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractTestSuite(t *testing.T) {
|
func TestExtractAttachmentsTestSuite(t *testing.T) {
|
||||||
suite.Run(t, &ExtractTestSuite{})
|
suite.Run(t, &ExtractAttachmentsTestSuite{})
|
||||||
}
|
}
|
||||||
|
|
50
internal/ap/extractmentions_test.go
Normal file
50
internal/ap/extractmentions_test.go
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
GoToSocial
|
||||||
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
|
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 ap_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ExtractMentionsTestSuite struct {
|
||||||
|
ExtractTestSuite
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ExtractMentionsTestSuite) TestExtractMentions() {
|
||||||
|
note := suite.noteWithMentions1
|
||||||
|
|
||||||
|
mentions, err := ap.ExtractMentions(note)
|
||||||
|
suite.NoError(err)
|
||||||
|
suite.Len(mentions, 2)
|
||||||
|
|
||||||
|
m1 := mentions[0]
|
||||||
|
suite.Equal("@dumpsterqueer@superseriousbusiness.org", m1.NameString)
|
||||||
|
suite.Equal("https://gts.superseriousbusiness.org/users/dumpsterqueer", m1.TargetAccountURI)
|
||||||
|
|
||||||
|
m2 := mentions[1]
|
||||||
|
suite.Equal("@f0x@superseriousbusiness.org", m2.NameString)
|
||||||
|
suite.Equal("https://gts.superseriousbusiness.org/users/f0x", m2.TargetAccountURI)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtractMentionsTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, &ExtractMentionsTestSuite{})
|
||||||
|
}
|
|
@ -34,12 +34,12 @@ func (f *federator) EnrichRemoteAccount(ctx context.Context, username string, ac
|
||||||
return f.dereferencer.EnrichRemoteAccount(ctx, username, account)
|
return f.dereferencer.EnrichRemoteAccount(ctx, username, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *federator) GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent, includeChilds bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
|
func (f *federator) GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
|
||||||
return f.dereferencer.GetRemoteStatus(ctx, username, remoteStatusID, refresh, includeParent, includeChilds)
|
return f.dereferencer.GetRemoteStatus(ctx, username, remoteStatusID, refresh, includeParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *federator) EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent, includeChilds bool) (*gtsmodel.Status, error) {
|
func (f *federator) EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent bool) (*gtsmodel.Status, error) {
|
||||||
return f.dereferencer.EnrichRemoteStatus(ctx, username, status, includeParent, includeChilds)
|
return f.dereferencer.EnrichRemoteStatus(ctx, username, status, includeParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *federator) DereferenceRemoteThread(ctx context.Context, username string, statusIRI *url.URL) error {
|
func (f *federator) DereferenceRemoteThread(ctx context.Context, username string, statusIRI *url.URL) error {
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (d *deref) DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Stat
|
||||||
return fmt.Errorf("DereferenceAnnounce: error dereferencing thread of boosted status: %s", err)
|
return fmt.Errorf("DereferenceAnnounce: error dereferencing thread of boosted status: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
boostedStatus, _, _, err := d.GetRemoteStatus(ctx, requestingUsername, boostedStatusURI, false, false, false)
|
boostedStatus, _, _, err := d.GetRemoteStatus(ctx, requestingUsername, boostedStatusURI, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("DereferenceAnnounce: error dereferencing remote status with id %s: %s", announce.BoostOf.URI, err)
|
return fmt.Errorf("DereferenceAnnounce: error dereferencing remote status with id %s: %s", announce.BoostOf.URI, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ type Dereferencer interface {
|
||||||
GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
|
GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
|
||||||
EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
|
EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
|
||||||
|
|
||||||
GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent, includeChilds bool) (*gtsmodel.Status, ap.Statusable, bool, error)
|
GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent bool) (*gtsmodel.Status, ap.Statusable, bool, error)
|
||||||
EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent, includeChilds bool) (*gtsmodel.Status, error)
|
EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent bool) (*gtsmodel.Status, error)
|
||||||
|
|
||||||
GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
|
GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@
|
||||||
//
|
//
|
||||||
// EnrichRemoteStatus is mostly useful for calling after a status has been initially created by
|
// EnrichRemoteStatus is mostly useful for calling after a status has been initially created by
|
||||||
// the federatingDB's Create function, but additional dereferencing is needed on it.
|
// the federatingDB's Create function, but additional dereferencing is needed on it.
|
||||||
func (d *deref) EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent, includeChilds bool) (*gtsmodel.Status, error) {
|
func (d *deref) EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent bool) (*gtsmodel.Status, error) {
|
||||||
if err := d.populateStatusFields(ctx, status, username, includeParent, includeChilds); err != nil {
|
if err := d.populateStatusFields(ctx, status, username, includeParent); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func (d *deref) EnrichRemoteStatus(ctx context.Context, username string, status
|
||||||
// If a dereference was performed, then the function also returns the ap.Statusable representation for further processing.
|
// If a dereference was performed, then the function also returns the ap.Statusable representation for further processing.
|
||||||
//
|
//
|
||||||
// SIDE EFFECTS: remote status will be stored in the database, and the remote status owner will also be stored.
|
// SIDE EFFECTS: remote status will be stored in the database, and the remote status owner will also be stored.
|
||||||
func (d *deref) GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent, includeChilds bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
|
func (d *deref) GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent bool) (*gtsmodel.Status, ap.Statusable, bool, error) {
|
||||||
new := true
|
new := true
|
||||||
|
|
||||||
// check if we already have the status in our db
|
// check if we already have the status in our db
|
||||||
|
@ -105,7 +105,7 @@ func (d *deref) GetRemoteStatus(ctx context.Context, username string, remoteStat
|
||||||
}
|
}
|
||||||
gtsStatus.ID = ulid
|
gtsStatus.ID = ulid
|
||||||
|
|
||||||
if err := d.populateStatusFields(ctx, gtsStatus, username, includeParent, includeChilds); err != nil {
|
if err := d.populateStatusFields(ctx, gtsStatus, username, includeParent); err != nil {
|
||||||
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error populating status fields: %s", err)
|
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error populating status fields: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func (d *deref) GetRemoteStatus(ctx context.Context, username string, remoteStat
|
||||||
} else {
|
} else {
|
||||||
gtsStatus.ID = maybeStatus.ID
|
gtsStatus.ID = maybeStatus.ID
|
||||||
|
|
||||||
if err := d.populateStatusFields(ctx, gtsStatus, username, includeParent, includeChilds); err != nil {
|
if err := d.populateStatusFields(ctx, gtsStatus, username, includeParent); err != nil {
|
||||||
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error populating status fields: %s", err)
|
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: error populating status fields: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ func (d *deref) dereferenceStatusable(ctx context.Context, username string, remo
|
||||||
// This function will deference all of the above, insert them in the database as necessary,
|
// This function will deference all of the above, insert them in the database as necessary,
|
||||||
// and attach them to the status. The status itself will not be added to the database yet,
|
// and attach them to the status. The status itself will not be added to the database yet,
|
||||||
// that's up the caller to do.
|
// that's up the caller to do.
|
||||||
func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Status, requestingUsername string, includeParent, includeChilds bool) error {
|
func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Status, requestingUsername string, includeParent bool) error {
|
||||||
l := d.log.WithFields(logrus.Fields{
|
l := d.log.WithFields(logrus.Fields{
|
||||||
"func": "dereferenceStatusFields",
|
"func": "dereferenceStatusFields",
|
||||||
"status": fmt.Sprintf("%+v", status),
|
"status": fmt.Sprintf("%+v", status),
|
||||||
|
@ -275,12 +275,10 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu
|
||||||
// 3. Emojis
|
// 3. Emojis
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
// 4. Mentions (only if requested)
|
// 4. Mentions
|
||||||
// TODO: do we need to handle removing empty mention objects and just using mention IDs slice?
|
// TODO: do we need to handle removing empty mention objects and just using mention IDs slice?
|
||||||
if includeChilds {
|
if err := d.populateStatusMentions(ctx, status, requestingUsername); err != nil {
|
||||||
if err := d.populateStatusMentions(ctx, status, requestingUsername); err != nil {
|
return fmt.Errorf("populateStatusFields: error populating status mentions: %s", err)
|
||||||
return fmt.Errorf("populateStatusFields: error populating status mentions: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Replied-to-status (only if requested)
|
// 5. Replied-to-status (only if requested)
|
||||||
|
@ -325,10 +323,10 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta
|
||||||
errs := []string{}
|
errs := []string{}
|
||||||
|
|
||||||
// check if account is in the db already
|
// check if account is in the db already
|
||||||
if a, err := d.db.GetAccountByURL(ctx, targetAccountURI.String()); err != nil {
|
if a, err := d.db.GetAccountByURI(ctx, targetAccountURI.String()); err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
} else {
|
} else {
|
||||||
l.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURL", targetAccountURI, a.ID)
|
l.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURI", targetAccountURI, a.ID)
|
||||||
targetAccount = a
|
targetAccount = a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +357,7 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta
|
||||||
Status: m.Status,
|
Status: m.Status,
|
||||||
CreatedAt: status.CreatedAt,
|
CreatedAt: status.CreatedAt,
|
||||||
UpdatedAt: status.UpdatedAt,
|
UpdatedAt: status.UpdatedAt,
|
||||||
OriginAccountID: status.Account.ID,
|
OriginAccountID: status.AccountID,
|
||||||
OriginAccountURI: status.AccountURI,
|
OriginAccountURI: status.AccountURI,
|
||||||
OriginAccount: status.Account,
|
OriginAccount: status.Account,
|
||||||
TargetAccountID: targetAccount.ID,
|
TargetAccountID: targetAccount.ID,
|
||||||
|
@ -426,7 +424,7 @@ func (d *deref) populateStatusRepliedTo(ctx context.Context, status *gtsmodel.St
|
||||||
replyToStatus, err := d.db.GetStatusByURI(ctx, status.InReplyToURI)
|
replyToStatus, err := d.db.GetStatusByURI(ctx, status.InReplyToURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Status was not in the DB, try fetch
|
// Status was not in the DB, try fetch
|
||||||
replyToStatus, _, _, err = d.GetRemoteStatus(ctx, requestingUsername, statusURI, false, false, false)
|
replyToStatus, _, _, err = d.GetRemoteStatus(ctx, requestingUsername, statusURI, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("populateStatusRepliedTo: couldn't get reply to status with uri %s: %s", status.InReplyToURI, err)
|
return fmt.Errorf("populateStatusRepliedTo: couldn't get reply to status with uri %s: %s", status.InReplyToURI, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (suite *StatusTestSuite) TestDereferenceSimpleStatus() {
|
||||||
fetchingAccount := suite.testAccounts["local_account_1"]
|
fetchingAccount := suite.testAccounts["local_account_1"]
|
||||||
|
|
||||||
statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839")
|
statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE4NTHKWW7THT67EF10EB839")
|
||||||
status, statusable, new, err := suite.dereferencer.GetRemoteStatus(context.Background(), fetchingAccount.Username, statusURL, false, false, false)
|
status, statusable, new, err := suite.dereferencer.GetRemoteStatus(context.Background(), fetchingAccount.Username, statusURL, false, false)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.NotNil(status)
|
suite.NotNil(status)
|
||||||
suite.NotNil(statusable)
|
suite.NotNil(statusable)
|
||||||
|
@ -80,7 +80,7 @@ func (suite *StatusTestSuite) TestDereferenceStatusWithMention() {
|
||||||
fetchingAccount := suite.testAccounts["local_account_1"]
|
fetchingAccount := suite.testAccounts["local_account_1"]
|
||||||
|
|
||||||
statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV")
|
statusURL := testrig.URLMustParse("https://unknown-instance.com/users/brand_new_person/statuses/01FE5Y30E3W4P7TRE0R98KAYQV")
|
||||||
status, statusable, new, err := suite.dereferencer.GetRemoteStatus(context.Background(), fetchingAccount.Username, statusURL, false, false, true)
|
status, statusable, new, err := suite.dereferencer.GetRemoteStatus(context.Background(), fetchingAccount.Username, statusURL, false, false)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.NotNil(status)
|
suite.NotNil(status)
|
||||||
suite.NotNil(statusable)
|
suite.NotNil(statusable)
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (d *deref) DereferenceThread(ctx context.Context, username string, statusIR
|
||||||
}
|
}
|
||||||
|
|
||||||
// first make sure we have this status in our db
|
// first make sure we have this status in our db
|
||||||
_, statusable, _, err := d.GetRemoteStatus(ctx, username, statusIRI, true, false, false)
|
_, statusable, _, err := d.GetRemoteStatus(ctx, username, statusIRI, true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("DereferenceThread: error getting status with id %s: %s", statusIRI.String(), err)
|
return fmt.Errorf("DereferenceThread: error getting status with id %s: %s", statusIRI.String(), err)
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI
|
||||||
|
|
||||||
// If we reach here, we're looking at a remote status -- make sure we have it in our db by calling GetRemoteStatus
|
// If we reach here, we're looking at a remote status -- make sure we have it in our db by calling GetRemoteStatus
|
||||||
// We call it with refresh to true because we want the statusable representation to parse inReplyTo from.
|
// We call it with refresh to true because we want the statusable representation to parse inReplyTo from.
|
||||||
_, statusable, _, err := d.GetRemoteStatus(ctx, username, &statusIRI, true, false, false)
|
_, statusable, _, err := d.GetRemoteStatus(ctx, username, &statusIRI, true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Debugf("error getting remote status: %s", err)
|
l.Debugf("error getting remote status: %s", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -214,7 +214,7 @@ func (d *deref) iterateDescendants(ctx context.Context, username string, statusI
|
||||||
foundReplies = foundReplies + 1
|
foundReplies = foundReplies + 1
|
||||||
|
|
||||||
// get the remote statusable and put it in the db
|
// get the remote statusable and put it in the db
|
||||||
_, statusable, new, err := d.GetRemoteStatus(ctx, username, itemURI, false, false, false)
|
_, statusable, new, err := d.GetRemoteStatus(ctx, username, itemURI, false, false)
|
||||||
if new && err == nil && statusable != nil {
|
if new && err == nil && statusable != nil {
|
||||||
// now iterate descendants of *that* status
|
// now iterate descendants of *that* status
|
||||||
if err := d.iterateDescendants(ctx, username, *itemURI, statusable); err != nil {
|
if err := d.iterateDescendants(ctx, username, *itemURI, statusable); err != nil {
|
||||||
|
|
|
@ -62,8 +62,8 @@ type Federator interface {
|
||||||
GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
|
GetRemoteAccount(ctx context.Context, username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error)
|
||||||
EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
|
EnrichRemoteAccount(ctx context.Context, username string, account *gtsmodel.Account) (*gtsmodel.Account, error)
|
||||||
|
|
||||||
GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent, includeChilds bool) (*gtsmodel.Status, ap.Statusable, bool, error)
|
GetRemoteStatus(ctx context.Context, username string, remoteStatusID *url.URL, refresh, includeParent bool) (*gtsmodel.Status, ap.Statusable, bool, error)
|
||||||
EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent, includeChilds bool) (*gtsmodel.Status, error)
|
EnrichRemoteStatus(ctx context.Context, username string, status *gtsmodel.Status, includeParent bool) (*gtsmodel.Status, error)
|
||||||
|
|
||||||
GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
|
GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ func (p *processor) ProcessFromFederator(ctx context.Context, federatorMsg messa
|
||||||
return errors.New("note was not parseable as *gtsmodel.Status")
|
return errors.New("note was not parseable as *gtsmodel.Status")
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := p.federator.EnrichRemoteStatus(ctx, federatorMsg.ReceivingAccount.Username, incomingStatus, false, false)
|
status, err := p.federator.EnrichRemoteStatus(ctx, federatorMsg.ReceivingAccount.Username, incomingStatus, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,6 +82,75 @@ func (suite *FromFederatorTestSuite) TestProcessFederationAnnounce() {
|
||||||
suite.False(notif.Read)
|
suite.False(notif.Read)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *FromFederatorTestSuite) TestProcessReplyMention() {
|
||||||
|
repliedAccount := suite.testAccounts["local_account_1"]
|
||||||
|
repliedStatus := suite.testStatuses["local_account_1_status_1"]
|
||||||
|
replyingAccount := suite.testAccounts["remote_account_1"]
|
||||||
|
replyingStatus := >smodel.Status{
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
URI: "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552",
|
||||||
|
URL: "http://fossbros-anonymous.io/@foss_satan/106221634728637552",
|
||||||
|
Content: `<p><span class="h-card"><a href="http://localhost:8080/@the_mighty_zork" class="u-url mention">@<span>the_mighty_zork</span></a></span> nice there it is:</p><p><a href="http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="ellipsis">social.pixie.town/users/f0x/st</span><span class="invisible">atuses/106221628567855262/activity</span></a></p>`,
|
||||||
|
Mentions: []*gtsmodel.Mention{
|
||||||
|
{
|
||||||
|
TargetAccountURI: repliedAccount.URI,
|
||||||
|
NameString: "@the_mighty_zork@localhost:8080",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AccountID: replyingAccount.ID,
|
||||||
|
AccountURI: replyingAccount.URI,
|
||||||
|
InReplyToID: repliedStatus.ID,
|
||||||
|
InReplyToURI: repliedStatus.URI,
|
||||||
|
InReplyToAccountID: repliedAccount.ID,
|
||||||
|
Visibility: gtsmodel.VisibilityUnlocked,
|
||||||
|
ActivityStreamsType: ap.ObjectNote,
|
||||||
|
Federated: true,
|
||||||
|
Boostable: true,
|
||||||
|
Replyable: true,
|
||||||
|
Likeable: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// id the status based on the time it was created
|
||||||
|
statusID, err := id.NewULIDFromTime(replyingStatus.CreatedAt)
|
||||||
|
suite.NoError(err)
|
||||||
|
replyingStatus.ID = statusID
|
||||||
|
|
||||||
|
err = suite.db.PutStatus(context.Background(), replyingStatus)
|
||||||
|
suite.NoError(err)
|
||||||
|
|
||||||
|
err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{
|
||||||
|
APObjectType: ap.ObjectNote,
|
||||||
|
APActivityType: ap.ActivityCreate,
|
||||||
|
GTSModel: replyingStatus,
|
||||||
|
ReceivingAccount: suite.testAccounts["local_account_1"],
|
||||||
|
})
|
||||||
|
suite.NoError(err)
|
||||||
|
|
||||||
|
// side effects should be triggered
|
||||||
|
// 1. status should be in the database
|
||||||
|
suite.NotEmpty(replyingStatus.ID)
|
||||||
|
_, err = suite.db.GetStatusByID(context.Background(), replyingStatus.ID)
|
||||||
|
suite.NoError(err)
|
||||||
|
|
||||||
|
// 2. a notification should exist for the mention
|
||||||
|
where := []db.Where{
|
||||||
|
{
|
||||||
|
Key: "status_id",
|
||||||
|
Value: replyingStatus.ID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
notif := >smodel.Notification{}
|
||||||
|
err = suite.db.GetWhere(context.Background(), where, notif)
|
||||||
|
suite.NoError(err)
|
||||||
|
suite.Equal(gtsmodel.NotificationMention, notif.NotificationType)
|
||||||
|
suite.Equal(replyingStatus.InReplyToAccountID, notif.TargetAccountID)
|
||||||
|
suite.Equal(replyingStatus.AccountID, notif.OriginAccountID)
|
||||||
|
suite.Equal(replyingStatus.ID, notif.StatusID)
|
||||||
|
suite.False(notif.Read)
|
||||||
|
}
|
||||||
|
|
||||||
func TestFromFederatorTestSuite(t *testing.T) {
|
func TestFromFederatorTestSuite(t *testing.T) {
|
||||||
suite.Run(t, &FromFederatorTestSuite{})
|
suite.Run(t, &FromFederatorTestSuite{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ func (p *processor) searchStatusByURI(ctx context.Context, authed *oauth.Auth, u
|
||||||
|
|
||||||
// we don't have it locally so dereference it if we're allowed to
|
// we don't have it locally so dereference it if we're allowed to
|
||||||
if resolve {
|
if resolve {
|
||||||
status, _, _, err := p.federator.GetRemoteStatus(ctx, authed.Account.Username, uri, true, false, false)
|
status, _, _, err := p.federator.GetRemoteStatus(ctx, authed.Account.Username, uri, true, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := p.federator.DereferenceRemoteThread(ctx, authed.Account.Username, uri); err != nil {
|
if err := p.federator.DereferenceRemoteThread(ctx, authed.Account.Username, uri); err != nil {
|
||||||
// try to deref the thread while we're here
|
// try to deref the thread while we're here
|
||||||
|
|
|
@ -25,328 +25,19 @@
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-fed/activity/streams"
|
"github.com/go-fed/activity/streams"
|
||||||
|
"github.com/go-fed/activity/streams/vocab"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ASToInternalTestSuite struct {
|
type ASToInternalTestSuite struct {
|
||||||
ConverterStandardTestSuite
|
TypeUtilsTestSuite
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
statusWithMentionsActivityJson = `{
|
|
||||||
"@context": [
|
|
||||||
"https://www.w3.org/ns/activitystreams",
|
|
||||||
{
|
|
||||||
"ostatus": "http://ostatus.org#",
|
|
||||||
"atomUri": "ostatus:atomUri",
|
|
||||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
|
||||||
"conversation": "ostatus:conversation",
|
|
||||||
"sensitive": "as:sensitive",
|
|
||||||
"toot": "http://joinmastodon.org/ns#",
|
|
||||||
"votersCount": "toot:votersCount"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/activity",
|
|
||||||
"type": "Create",
|
|
||||||
"actor": "https://ondergrond.org/users/dumpsterqueer",
|
|
||||||
"published": "2021-05-12T09:58:38Z",
|
|
||||||
"to": [
|
|
||||||
"https://ondergrond.org/users/dumpsterqueer/followers"
|
|
||||||
],
|
|
||||||
"cc": [
|
|
||||||
"https://www.w3.org/ns/activitystreams#Public",
|
|
||||||
"https://social.pixie.town/users/f0x"
|
|
||||||
],
|
|
||||||
"object": {
|
|
||||||
"id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552",
|
|
||||||
"type": "Note",
|
|
||||||
"summary": null,
|
|
||||||
"inReplyTo": "https://social.pixie.town/users/f0x/statuses/106221628567855262",
|
|
||||||
"published": "2021-05-12T09:58:38Z",
|
|
||||||
"url": "https://ondergrond.org/@dumpsterqueer/106221634728637552",
|
|
||||||
"attributedTo": "https://ondergrond.org/users/dumpsterqueer",
|
|
||||||
"to": [
|
|
||||||
"https://ondergrond.org/users/dumpsterqueer/followers"
|
|
||||||
],
|
|
||||||
"cc": [
|
|
||||||
"https://www.w3.org/ns/activitystreams#Public",
|
|
||||||
"https://social.pixie.town/users/f0x"
|
|
||||||
],
|
|
||||||
"sensitive": false,
|
|
||||||
"atomUri": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552",
|
|
||||||
"inReplyToAtomUri": "https://social.pixie.town/users/f0x/statuses/106221628567855262",
|
|
||||||
"conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation",
|
|
||||||
"content": "<p><span class=\"h-card\"><a href=\"https://social.pixie.town/@f0x\" class=\"u-url mention\">@<span>f0x</span></a></span> nice there it is:</p><p><a href=\"https://social.pixie.town/users/f0x/statuses/106221628567855262/activity\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">social.pixie.town/users/f0x/st</span><span class=\"invisible\">atuses/106221628567855262/activity</span></a></p>",
|
|
||||||
"contentMap": {
|
|
||||||
"en": "<p><span class=\"h-card\"><a href=\"https://social.pixie.town/@f0x\" class=\"u-url mention\">@<span>f0x</span></a></span> nice there it is:</p><p><a href=\"https://social.pixie.town/users/f0x/statuses/106221628567855262/activity\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">social.pixie.town/users/f0x/st</span><span class=\"invisible\">atuses/106221628567855262/activity</span></a></p>"
|
|
||||||
},
|
|
||||||
"attachment": [],
|
|
||||||
"tag": [
|
|
||||||
{
|
|
||||||
"type": "Mention",
|
|
||||||
"href": "https://social.pixie.town/users/f0x",
|
|
||||||
"name": "@f0x@pixie.town"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"replies": {
|
|
||||||
"id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/replies",
|
|
||||||
"type": "Collection",
|
|
||||||
"first": {
|
|
||||||
"type": "CollectionPage",
|
|
||||||
"next": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/replies?only_other_accounts=true&page=true",
|
|
||||||
"partOf": "https://ondergrond.org/users/dumpsterqueer/statuses/106221634728637552/replies",
|
|
||||||
"items": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
statusWithEmojisAndTagsAsActivityJson = `{
|
|
||||||
"@context": [
|
|
||||||
"https://www.w3.org/ns/activitystreams",
|
|
||||||
{
|
|
||||||
"ostatus": "http://ostatus.org#",
|
|
||||||
"atomUri": "ostatus:atomUri",
|
|
||||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
|
||||||
"conversation": "ostatus:conversation",
|
|
||||||
"sensitive": "as:sensitive",
|
|
||||||
"toot": "http://joinmastodon.org/ns#",
|
|
||||||
"votersCount": "toot:votersCount",
|
|
||||||
"Hashtag": "as:Hashtag",
|
|
||||||
"Emoji": "toot:Emoji",
|
|
||||||
"focalPoint": {
|
|
||||||
"@container": "@list",
|
|
||||||
"@id": "toot:focalPoint"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/activity",
|
|
||||||
"type": "Create",
|
|
||||||
"actor": "https://ondergrond.org/users/dumpsterqueer",
|
|
||||||
"published": "2021-05-12T09:41:38Z",
|
|
||||||
"to": [
|
|
||||||
"https://ondergrond.org/users/dumpsterqueer/followers"
|
|
||||||
],
|
|
||||||
"cc": [
|
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
|
||||||
],
|
|
||||||
"object": {
|
|
||||||
"id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704",
|
|
||||||
"type": "Note",
|
|
||||||
"summary": null,
|
|
||||||
"inReplyTo": null,
|
|
||||||
"published": "2021-05-12T09:41:38Z",
|
|
||||||
"url": "https://ondergrond.org/@dumpsterqueer/106221567884565704",
|
|
||||||
"attributedTo": "https://ondergrond.org/users/dumpsterqueer",
|
|
||||||
"to": [
|
|
||||||
"https://ondergrond.org/users/dumpsterqueer/followers"
|
|
||||||
],
|
|
||||||
"cc": [
|
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
|
||||||
],
|
|
||||||
"sensitive": false,
|
|
||||||
"atomUri": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704",
|
|
||||||
"inReplyToAtomUri": null,
|
|
||||||
"conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation",
|
|
||||||
"content": "<p>just testing activitypub representations of <a href=\"https://ondergrond.org/tags/tags\" class=\"mention hashtag\" rel=\"tag\">#<span>tags</span></a> and <a href=\"https://ondergrond.org/tags/emoji\" class=\"mention hashtag\" rel=\"tag\">#<span>emoji</span></a> :party_parrot: :amaze: :blobsunglasses: </p><p>don't mind me....</p>",
|
|
||||||
"contentMap": {
|
|
||||||
"en": "<p>just testing activitypub representations of <a href=\"https://ondergrond.org/tags/tags\" class=\"mention hashtag\" rel=\"tag\">#<span>tags</span></a> and <a href=\"https://ondergrond.org/tags/emoji\" class=\"mention hashtag\" rel=\"tag\">#<span>emoji</span></a> :party_parrot: :amaze: :blobsunglasses: </p><p>don't mind me....</p>"
|
|
||||||
},
|
|
||||||
"attachment": [],
|
|
||||||
"tag": [
|
|
||||||
{
|
|
||||||
"type": "Hashtag",
|
|
||||||
"href": "https://ondergrond.org/tags/tags",
|
|
||||||
"name": "#tags"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "Hashtag",
|
|
||||||
"href": "https://ondergrond.org/tags/emoji",
|
|
||||||
"name": "#emoji"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "https://ondergrond.org/emojis/2390",
|
|
||||||
"type": "Emoji",
|
|
||||||
"name": ":party_parrot:",
|
|
||||||
"updated": "2020-11-06T13:42:11Z",
|
|
||||||
"icon": {
|
|
||||||
"type": "Image",
|
|
||||||
"mediaType": "image/gif",
|
|
||||||
"url": "https://ondergrond.org/system/custom_emojis/images/000/002/390/original/ef133aac7ab23341.gif"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "https://ondergrond.org/emojis/2395",
|
|
||||||
"type": "Emoji",
|
|
||||||
"name": ":amaze:",
|
|
||||||
"updated": "2020-09-26T12:29:56Z",
|
|
||||||
"icon": {
|
|
||||||
"type": "Image",
|
|
||||||
"mediaType": "image/png",
|
|
||||||
"url": "https://ondergrond.org/system/custom_emojis/images/000/002/395/original/2c7d9345e57367ed.png"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "https://ondergrond.org/emojis/764",
|
|
||||||
"type": "Emoji",
|
|
||||||
"name": ":blobsunglasses:",
|
|
||||||
"updated": "2020-09-26T12:13:23Z",
|
|
||||||
"icon": {
|
|
||||||
"type": "Image",
|
|
||||||
"mediaType": "image/png",
|
|
||||||
"url": "https://ondergrond.org/system/custom_emojis/images/000/000/764/original/3f8eef9de773c90d.png"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"replies": {
|
|
||||||
"id": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/replies",
|
|
||||||
"type": "Collection",
|
|
||||||
"first": {
|
|
||||||
"type": "CollectionPage",
|
|
||||||
"next": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/replies?only_other_accounts=true&page=true",
|
|
||||||
"partOf": "https://ondergrond.org/users/dumpsterqueer/statuses/106221567884565704/replies",
|
|
||||||
"items": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
gargronAsActivityJson = `{
|
|
||||||
"@context": [
|
|
||||||
"https://www.w3.org/ns/activitystreams",
|
|
||||||
"https://w3id.org/security/v1",
|
|
||||||
{
|
|
||||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
|
||||||
"toot": "http://joinmastodon.org/ns#",
|
|
||||||
"featured": {
|
|
||||||
"@id": "toot:featured",
|
|
||||||
"@type": "@id"
|
|
||||||
},
|
|
||||||
"featuredTags": {
|
|
||||||
"@id": "toot:featuredTags",
|
|
||||||
"@type": "@id"
|
|
||||||
},
|
|
||||||
"alsoKnownAs": {
|
|
||||||
"@id": "as:alsoKnownAs",
|
|
||||||
"@type": "@id"
|
|
||||||
},
|
|
||||||
"movedTo": {
|
|
||||||
"@id": "as:movedTo",
|
|
||||||
"@type": "@id"
|
|
||||||
},
|
|
||||||
"schema": "http://schema.org#",
|
|
||||||
"PropertyValue": "schema:PropertyValue",
|
|
||||||
"value": "schema:value",
|
|
||||||
"IdentityProof": "toot:IdentityProof",
|
|
||||||
"discoverable": "toot:discoverable",
|
|
||||||
"Device": "toot:Device",
|
|
||||||
"Ed25519Signature": "toot:Ed25519Signature",
|
|
||||||
"Ed25519Key": "toot:Ed25519Key",
|
|
||||||
"Curve25519Key": "toot:Curve25519Key",
|
|
||||||
"EncryptedMessage": "toot:EncryptedMessage",
|
|
||||||
"publicKeyBase64": "toot:publicKeyBase64",
|
|
||||||
"deviceId": "toot:deviceId",
|
|
||||||
"claim": {
|
|
||||||
"@type": "@id",
|
|
||||||
"@id": "toot:claim"
|
|
||||||
},
|
|
||||||
"fingerprintKey": {
|
|
||||||
"@type": "@id",
|
|
||||||
"@id": "toot:fingerprintKey"
|
|
||||||
},
|
|
||||||
"identityKey": {
|
|
||||||
"@type": "@id",
|
|
||||||
"@id": "toot:identityKey"
|
|
||||||
},
|
|
||||||
"devices": {
|
|
||||||
"@type": "@id",
|
|
||||||
"@id": "toot:devices"
|
|
||||||
},
|
|
||||||
"messageFranking": "toot:messageFranking",
|
|
||||||
"messageType": "toot:messageType",
|
|
||||||
"cipherText": "toot:cipherText",
|
|
||||||
"suspended": "toot:suspended",
|
|
||||||
"focalPoint": {
|
|
||||||
"@container": "@list",
|
|
||||||
"@id": "toot:focalPoint"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": "https://mastodon.social/users/Gargron",
|
|
||||||
"type": "Person",
|
|
||||||
"following": "https://mastodon.social/users/Gargron/following",
|
|
||||||
"followers": "https://mastodon.social/users/Gargron/followers",
|
|
||||||
"inbox": "https://mastodon.social/users/Gargron/inbox",
|
|
||||||
"outbox": "https://mastodon.social/users/Gargron/outbox",
|
|
||||||
"featured": "https://mastodon.social/users/Gargron/collections/featured",
|
|
||||||
"featuredTags": "https://mastodon.social/users/Gargron/collections/tags",
|
|
||||||
"preferredUsername": "Gargron",
|
|
||||||
"name": "Eugen",
|
|
||||||
"summary": "<p>Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.</p>",
|
|
||||||
"url": "https://mastodon.social/@Gargron",
|
|
||||||
"manuallyApprovesFollowers": false,
|
|
||||||
"discoverable": true,
|
|
||||||
"devices": "https://mastodon.social/users/Gargron/collections/devices",
|
|
||||||
"alsoKnownAs": [
|
|
||||||
"https://tooting.ai/users/Gargron"
|
|
||||||
],
|
|
||||||
"publicKey": {
|
|
||||||
"id": "https://mastodon.social/users/Gargron#main-key",
|
|
||||||
"owner": "https://mastodon.social/users/Gargron",
|
|
||||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvXc4vkECU2/CeuSo1wtn\nFoim94Ne1jBMYxTZ9wm2YTdJq1oiZKif06I2fOqDzY/4q/S9uccrE9Bkajv1dnkO\nVm31QjWlhVpSKynVxEWjVBO5Ienue8gND0xvHIuXf87o61poqjEoepvsQFElA5ym\novljWGSA/jpj7ozygUZhCXtaS2W5AD5tnBQUpcO0lhItYPYTjnmzcc4y2NbJV8hz\n2s2G8qKv8fyimE23gY1XrPJg+cRF+g4PqFXujjlJ7MihD9oqtLGxbu7o1cifTn3x\nBfIdPythWu5b4cujNsB3m3awJjVmx+MHQ9SugkSIYXV0Ina77cTNS0M2PYiH1PFR\nTwIDAQAB\n-----END PUBLIC KEY-----\n"
|
|
||||||
},
|
|
||||||
"tag": [],
|
|
||||||
"attachment": [
|
|
||||||
{
|
|
||||||
"type": "PropertyValue",
|
|
||||||
"name": "Patreon",
|
|
||||||
"value": "<a href=\"https://www.patreon.com/mastodon\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"\">patreon.com/mastodon</span><span class=\"invisible\"></span></a>"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "PropertyValue",
|
|
||||||
"name": "Homepage",
|
|
||||||
"value": "<a href=\"https://zeonfederated.com\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">zeonfederated.com</span><span class=\"invisible\"></span></a>"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "IdentityProof",
|
|
||||||
"name": "gargron",
|
|
||||||
"signatureAlgorithm": "keybase",
|
|
||||||
"signatureValue": "5cfc20c7018f2beefb42a68836da59a792e55daa4d118498c9b1898de7e845690f"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"endpoints": {
|
|
||||||
"sharedInbox": "https://mastodon.social/inbox"
|
|
||||||
},
|
|
||||||
"icon": {
|
|
||||||
"type": "Image",
|
|
||||||
"mediaType": "image/jpeg",
|
|
||||||
"url": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"
|
|
||||||
},
|
|
||||||
"image": {
|
|
||||||
"type": "Image",
|
|
||||||
"mediaType": "image/png",
|
|
||||||
"url": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png"
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
)
|
|
||||||
|
|
||||||
func (suite *ASToInternalTestSuite) SetupSuite() {
|
|
||||||
suite.config = testrig.NewTestConfig()
|
|
||||||
suite.db = testrig.NewTestDB()
|
|
||||||
suite.log = testrig.NewTestLog()
|
|
||||||
suite.accounts = testrig.NewTestAccounts()
|
|
||||||
suite.people = testrig.NewTestFediPeople()
|
|
||||||
suite.typeconverter = typeutils.NewConverter(suite.config, suite.db, suite.log)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *ASToInternalTestSuite) SetupTest() {
|
|
||||||
testrig.StandardDBSetup(suite.db, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ASToInternalTestSuite) TestParsePerson() {
|
func (suite *ASToInternalTestSuite) TestParsePerson() {
|
||||||
testPerson := suite.people["https://unknown-instance.com/users/brand_new_person"]
|
testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
|
||||||
|
|
||||||
acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, false)
|
acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, false)
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
|
@ -384,8 +75,48 @@ func (suite *ASToInternalTestSuite) TestParseGargron() {
|
||||||
// TODO: write assertions here, rn we're just eyeballing the output
|
// TODO: write assertions here, rn we're just eyeballing the output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ASToInternalTestSuite) TearDownTest() {
|
func (suite *ASToInternalTestSuite) TestParseReplyWithMention() {
|
||||||
testrig.StandardDBTeardown(suite.db)
|
m := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(statusWithMentionsActivityJson), &m)
|
||||||
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
|
t, err := streams.ToType(context.Background(), m)
|
||||||
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
|
create, ok := t.(vocab.ActivityStreamsCreate)
|
||||||
|
suite.True(ok)
|
||||||
|
|
||||||
|
object := create.GetActivityStreamsObject()
|
||||||
|
var status *gtsmodel.Status
|
||||||
|
for i := object.Begin(); i != nil; i = i.Next() {
|
||||||
|
statusable := i.GetActivityStreamsNote()
|
||||||
|
s, err := suite.typeconverter.ASStatusToStatus(context.Background(), statusable)
|
||||||
|
suite.NoError(err)
|
||||||
|
status = s
|
||||||
|
break
|
||||||
|
}
|
||||||
|
suite.NotNil(status)
|
||||||
|
|
||||||
|
postingAccount := suite.testAccounts["remote_account_1"]
|
||||||
|
inReplyToAccount := suite.testAccounts["local_account_1"]
|
||||||
|
inReplyToStatus := suite.testStatuses["local_account_1_status_1"]
|
||||||
|
|
||||||
|
suite.Equal("http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552", status.URI)
|
||||||
|
suite.Equal(postingAccount.ID, status.AccountID)
|
||||||
|
suite.Equal(postingAccount.URI, status.AccountURI)
|
||||||
|
suite.Equal(inReplyToAccount.ID, status.InReplyToAccountID)
|
||||||
|
suite.Equal(inReplyToStatus.ID, status.InReplyToID)
|
||||||
|
suite.Equal(inReplyToStatus.URI, status.InReplyToURI)
|
||||||
|
suite.True(status.Federated)
|
||||||
|
suite.True(status.Boostable)
|
||||||
|
suite.True(status.Replyable)
|
||||||
|
suite.True(status.Likeable)
|
||||||
|
suite.Equal(`<p><span class="h-card"><a href="http://localhost:8080/@the_mighty_zork" class="u-url mention">@<span>the_mighty_zork</span></a></span> nice there it is:</p><p><a href="http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="ellipsis">social.pixie.town/users/f0x/st</span><span class="invisible">atuses/106221628567855262/activity</span></a></p>`, status.Content)
|
||||||
|
suite.Len(status.Mentions, 1)
|
||||||
|
m1 := status.Mentions[0]
|
||||||
|
suite.Equal(inReplyToAccount.URI, m1.TargetAccountURI)
|
||||||
|
suite.Equal("@the_mighty_zork@localhost:8080", m1.NameString)
|
||||||
|
suite.Equal(gtsmodel.VisibilityUnlocked, status.Visibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestASToInternalTestSuite(t *testing.T) {
|
func TestASToInternalTestSuite(t *testing.T) {
|
||||||
|
|
|
@ -26,16 +26,329 @@
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||||
)
|
)
|
||||||
|
|
||||||
// nolint
|
const (
|
||||||
type ConverterStandardTestSuite struct {
|
statusWithMentionsActivityJson = `{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
{
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"votersCount": "toot:votersCount"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/activity",
|
||||||
|
"type": "Create",
|
||||||
|
"actor": "http://fossbros-anonymous.io/users/foss_satan",
|
||||||
|
"published": "2021-05-12T09:58:38Z",
|
||||||
|
"to": [
|
||||||
|
"http://fossbros-anonymous.io/users/foss_satan/followers"
|
||||||
|
],
|
||||||
|
"cc": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public",
|
||||||
|
"http://localhost:8080/users/the_mighty_zork"
|
||||||
|
],
|
||||||
|
"object": {
|
||||||
|
"id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552",
|
||||||
|
"type": "Note",
|
||||||
|
"summary": null,
|
||||||
|
"inReplyTo": "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY",
|
||||||
|
"published": "2021-05-12T09:58:38Z",
|
||||||
|
"url": "https://ondergrond.org/@dumpsterqueer/106221634728637552",
|
||||||
|
"attributedTo": "http://fossbros-anonymous.io/users/foss_satan",
|
||||||
|
"to": [
|
||||||
|
"http://fossbros-anonymous.io/users/foss_satan/followers"
|
||||||
|
],
|
||||||
|
"cc": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public",
|
||||||
|
"http://localhost:8080/users/the_mighty_zork"
|
||||||
|
],
|
||||||
|
"sensitive": false,
|
||||||
|
"conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation",
|
||||||
|
"content": "<p><span class=\"h-card\"><a href=\"http://localhost:8080/@the_mighty_zork\" class=\"u-url mention\">@<span>the_mighty_zork</span></a></span> nice there it is:</p><p><a href=\"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">social.pixie.town/users/f0x/st</span><span class=\"invisible\">atuses/106221628567855262/activity</span></a></p>",
|
||||||
|
"contentMap": {
|
||||||
|
"en": "<p><span class=\"h-card\"><a href=\"http://localhost:8080/@the_mighty_zork\" class=\"u-url mention\">@<span>the_mighty_zork</span></a></span> nice there it is:</p><p><a href=\"http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY/activity\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">social.pixie.town/users/f0x/st</span><span class=\"invisible\">atuses/106221628567855262/activity</span></a></p>"
|
||||||
|
},
|
||||||
|
"attachment": [],
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"type": "Mention",
|
||||||
|
"href": "http://localhost:8080/users/the_mighty_zork",
|
||||||
|
"name": "@the_mighty_zork@localhost:8080"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"replies": {
|
||||||
|
"id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/replies",
|
||||||
|
"type": "Collection",
|
||||||
|
"first": {
|
||||||
|
"type": "CollectionPage",
|
||||||
|
"next": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/replies?only_other_accounts=true&page=true",
|
||||||
|
"partOf": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221634728637552/replies",
|
||||||
|
"items": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
statusWithEmojisAndTagsAsActivityJson = `{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
{
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"votersCount": "toot:votersCount",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"Emoji": "toot:Emoji",
|
||||||
|
"focalPoint": {
|
||||||
|
"@container": "@list",
|
||||||
|
"@id": "toot:focalPoint"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/activity",
|
||||||
|
"type": "Create",
|
||||||
|
"actor": "http://fossbros-anonymous.io/users/foss_satan",
|
||||||
|
"published": "2021-05-12T09:41:38Z",
|
||||||
|
"to": [
|
||||||
|
"http://fossbros-anonymous.io/users/foss_satan/followers"
|
||||||
|
],
|
||||||
|
"cc": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"object": {
|
||||||
|
"id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704",
|
||||||
|
"type": "Note",
|
||||||
|
"summary": null,
|
||||||
|
"inReplyTo": null,
|
||||||
|
"published": "2021-05-12T09:41:38Z",
|
||||||
|
"url": "https://ondergrond.org/@dumpsterqueer/106221567884565704",
|
||||||
|
"attributedTo": "http://fossbros-anonymous.io/users/foss_satan",
|
||||||
|
"to": [
|
||||||
|
"http://fossbros-anonymous.io/users/foss_satan/followers"
|
||||||
|
],
|
||||||
|
"cc": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"sensitive": false,
|
||||||
|
"atomUri": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704",
|
||||||
|
"inReplyToAtomUri": null,
|
||||||
|
"conversation": "tag:ondergrond.org,2021-05-12:objectId=1132361:objectType=Conversation",
|
||||||
|
"content": "<p>just testing activitypub representations of <a href=\"https://ondergrond.org/tags/tags\" class=\"mention hashtag\" rel=\"tag\">#<span>tags</span></a> and <a href=\"https://ondergrond.org/tags/emoji\" class=\"mention hashtag\" rel=\"tag\">#<span>emoji</span></a> :party_parrot: :amaze: :blobsunglasses: </p><p>don't mind me....</p>",
|
||||||
|
"contentMap": {
|
||||||
|
"en": "<p>just testing activitypub representations of <a href=\"https://ondergrond.org/tags/tags\" class=\"mention hashtag\" rel=\"tag\">#<span>tags</span></a> and <a href=\"https://ondergrond.org/tags/emoji\" class=\"mention hashtag\" rel=\"tag\">#<span>emoji</span></a> :party_parrot: :amaze: :blobsunglasses: </p><p>don't mind me....</p>"
|
||||||
|
},
|
||||||
|
"attachment": [],
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": "https://ondergrond.org/tags/tags",
|
||||||
|
"name": "#tags"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": "https://ondergrond.org/tags/emoji",
|
||||||
|
"name": "#emoji"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "https://ondergrond.org/emojis/2390",
|
||||||
|
"type": "Emoji",
|
||||||
|
"name": ":party_parrot:",
|
||||||
|
"updated": "2020-11-06T13:42:11Z",
|
||||||
|
"icon": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/gif",
|
||||||
|
"url": "https://ondergrond.org/system/custom_emojis/images/000/002/390/original/ef133aac7ab23341.gif"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "https://ondergrond.org/emojis/2395",
|
||||||
|
"type": "Emoji",
|
||||||
|
"name": ":amaze:",
|
||||||
|
"updated": "2020-09-26T12:29:56Z",
|
||||||
|
"icon": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/png",
|
||||||
|
"url": "https://ondergrond.org/system/custom_emojis/images/000/002/395/original/2c7d9345e57367ed.png"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "https://ondergrond.org/emojis/764",
|
||||||
|
"type": "Emoji",
|
||||||
|
"name": ":blobsunglasses:",
|
||||||
|
"updated": "2020-09-26T12:13:23Z",
|
||||||
|
"icon": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/png",
|
||||||
|
"url": "https://ondergrond.org/system/custom_emojis/images/000/000/764/original/3f8eef9de773c90d.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"replies": {
|
||||||
|
"id": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/replies",
|
||||||
|
"type": "Collection",
|
||||||
|
"first": {
|
||||||
|
"type": "CollectionPage",
|
||||||
|
"next": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/replies?only_other_accounts=true&page=true",
|
||||||
|
"partOf": "http://fossbros-anonymous.io/users/foss_satan/statuses/106221567884565704/replies",
|
||||||
|
"items": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
gargronAsActivityJson = `{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"featured": {
|
||||||
|
"@id": "toot:featured",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"featuredTags": {
|
||||||
|
"@id": "toot:featuredTags",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"alsoKnownAs": {
|
||||||
|
"@id": "as:alsoKnownAs",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"movedTo": {
|
||||||
|
"@id": "as:movedTo",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"schema": "http://schema.org#",
|
||||||
|
"PropertyValue": "schema:PropertyValue",
|
||||||
|
"value": "schema:value",
|
||||||
|
"IdentityProof": "toot:IdentityProof",
|
||||||
|
"discoverable": "toot:discoverable",
|
||||||
|
"Device": "toot:Device",
|
||||||
|
"Ed25519Signature": "toot:Ed25519Signature",
|
||||||
|
"Ed25519Key": "toot:Ed25519Key",
|
||||||
|
"Curve25519Key": "toot:Curve25519Key",
|
||||||
|
"EncryptedMessage": "toot:EncryptedMessage",
|
||||||
|
"publicKeyBase64": "toot:publicKeyBase64",
|
||||||
|
"deviceId": "toot:deviceId",
|
||||||
|
"claim": {
|
||||||
|
"@type": "@id",
|
||||||
|
"@id": "toot:claim"
|
||||||
|
},
|
||||||
|
"fingerprintKey": {
|
||||||
|
"@type": "@id",
|
||||||
|
"@id": "toot:fingerprintKey"
|
||||||
|
},
|
||||||
|
"identityKey": {
|
||||||
|
"@type": "@id",
|
||||||
|
"@id": "toot:identityKey"
|
||||||
|
},
|
||||||
|
"devices": {
|
||||||
|
"@type": "@id",
|
||||||
|
"@id": "toot:devices"
|
||||||
|
},
|
||||||
|
"messageFranking": "toot:messageFranking",
|
||||||
|
"messageType": "toot:messageType",
|
||||||
|
"cipherText": "toot:cipherText",
|
||||||
|
"suspended": "toot:suspended",
|
||||||
|
"focalPoint": {
|
||||||
|
"@container": "@list",
|
||||||
|
"@id": "toot:focalPoint"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "https://mastodon.social/users/Gargron",
|
||||||
|
"type": "Person",
|
||||||
|
"following": "https://mastodon.social/users/Gargron/following",
|
||||||
|
"followers": "https://mastodon.social/users/Gargron/followers",
|
||||||
|
"inbox": "https://mastodon.social/users/Gargron/inbox",
|
||||||
|
"outbox": "https://mastodon.social/users/Gargron/outbox",
|
||||||
|
"featured": "https://mastodon.social/users/Gargron/collections/featured",
|
||||||
|
"featuredTags": "https://mastodon.social/users/Gargron/collections/tags",
|
||||||
|
"preferredUsername": "Gargron",
|
||||||
|
"name": "Eugen",
|
||||||
|
"summary": "<p>Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.</p>",
|
||||||
|
"url": "https://mastodon.social/@Gargron",
|
||||||
|
"manuallyApprovesFollowers": false,
|
||||||
|
"discoverable": true,
|
||||||
|
"devices": "https://mastodon.social/users/Gargron/collections/devices",
|
||||||
|
"alsoKnownAs": [
|
||||||
|
"https://tooting.ai/users/Gargron"
|
||||||
|
],
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://mastodon.social/users/Gargron#main-key",
|
||||||
|
"owner": "https://mastodon.social/users/Gargron",
|
||||||
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvXc4vkECU2/CeuSo1wtn\nFoim94Ne1jBMYxTZ9wm2YTdJq1oiZKif06I2fOqDzY/4q/S9uccrE9Bkajv1dnkO\nVm31QjWlhVpSKynVxEWjVBO5Ienue8gND0xvHIuXf87o61poqjEoepvsQFElA5ym\novljWGSA/jpj7ozygUZhCXtaS2W5AD5tnBQUpcO0lhItYPYTjnmzcc4y2NbJV8hz\n2s2G8qKv8fyimE23gY1XrPJg+cRF+g4PqFXujjlJ7MihD9oqtLGxbu7o1cifTn3x\nBfIdPythWu5b4cujNsB3m3awJjVmx+MHQ9SugkSIYXV0Ina77cTNS0M2PYiH1PFR\nTwIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||||
|
},
|
||||||
|
"tag": [],
|
||||||
|
"attachment": [
|
||||||
|
{
|
||||||
|
"type": "PropertyValue",
|
||||||
|
"name": "Patreon",
|
||||||
|
"value": "<a href=\"https://www.patreon.com/mastodon\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"\">patreon.com/mastodon</span><span class=\"invisible\"></span></a>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PropertyValue",
|
||||||
|
"name": "Homepage",
|
||||||
|
"value": "<a href=\"https://zeonfederated.com\" rel=\"me nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">zeonfederated.com</span><span class=\"invisible\"></span></a>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "IdentityProof",
|
||||||
|
"name": "gargron",
|
||||||
|
"signatureAlgorithm": "keybase",
|
||||||
|
"signatureValue": "5cfc20c7018f2beefb42a68836da59a792e55daa4d118498c9b1898de7e845690f"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"endpoints": {
|
||||||
|
"sharedInbox": "https://mastodon.social/inbox"
|
||||||
|
},
|
||||||
|
"icon": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/jpeg",
|
||||||
|
"url": "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg"
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/png",
|
||||||
|
"url": "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png"
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
|
type TypeUtilsTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
config *config.Config
|
config *config.Config
|
||||||
db db.DB
|
db db.DB
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
accounts map[string]*gtsmodel.Account
|
testAccounts map[string]*gtsmodel.Account
|
||||||
people map[string]vocab.ActivityStreamsPerson
|
testStatuses map[string]*gtsmodel.Status
|
||||||
|
testPeople map[string]vocab.ActivityStreamsPerson
|
||||||
|
|
||||||
typeconverter typeutils.TypeConverter
|
typeconverter typeutils.TypeConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *TypeUtilsTestSuite) SetupSuite() {
|
||||||
|
suite.config = testrig.NewTestConfig()
|
||||||
|
suite.db = testrig.NewTestDB()
|
||||||
|
suite.log = testrig.NewTestLog()
|
||||||
|
suite.testAccounts = testrig.NewTestAccounts()
|
||||||
|
suite.testStatuses = testrig.NewTestStatuses()
|
||||||
|
suite.testPeople = testrig.NewTestFediPeople()
|
||||||
|
suite.typeconverter = typeutils.NewConverter(suite.config, suite.db, suite.log)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *TypeUtilsTestSuite) SetupTest() {
|
||||||
|
testrig.StandardDBSetup(suite.db, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *TypeUtilsTestSuite) TearDownTest() {
|
||||||
|
testrig.StandardDBTeardown(suite.db)
|
||||||
|
}
|
||||||
|
|
|
@ -27,37 +27,14 @@
|
||||||
"github.com/go-fed/activity/streams"
|
"github.com/go-fed/activity/streams"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
|
||||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type InternalToASTestSuite struct {
|
type InternalToASTestSuite struct {
|
||||||
ConverterStandardTestSuite
|
TypeUtilsTestSuite
|
||||||
}
|
|
||||||
|
|
||||||
// SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout
|
|
||||||
func (suite *InternalToASTestSuite) SetupSuite() {
|
|
||||||
// setup standard items
|
|
||||||
suite.config = testrig.NewTestConfig()
|
|
||||||
suite.db = testrig.NewTestDB()
|
|
||||||
suite.log = testrig.NewTestLog()
|
|
||||||
suite.accounts = testrig.NewTestAccounts()
|
|
||||||
suite.people = testrig.NewTestFediPeople()
|
|
||||||
suite.typeconverter = typeutils.NewConverter(suite.config, suite.db, suite.log)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *InternalToASTestSuite) SetupTest() {
|
|
||||||
testrig.StandardDBSetup(suite.db, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TearDownTest drops tables to make sure there's no data in the db
|
|
||||||
func (suite *InternalToASTestSuite) TearDownTest() {
|
|
||||||
testrig.StandardDBTeardown(suite.db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *InternalToASTestSuite) TestAccountToAS() {
|
func (suite *InternalToASTestSuite) TestAccountToAS() {
|
||||||
testAccount := suite.accounts["local_account_1"] // take zork for this test
|
testAccount := suite.testAccounts["local_account_1"] // take zork for this test
|
||||||
|
|
||||||
asPerson, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
|
asPerson, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
|
|
Loading…
Reference in a new issue