Manually approves followers (#146)

* update go-fed

* update go-fed

* manuallyapprovesfollowers

* serialize manuallyApprovesFollowers
This commit is contained in:
tobi 2021-08-23 12:46:05 +02:00 committed by GitHub
commit 071eca20ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 931 additions and 308 deletions

View file

@ -39,6 +39,7 @@ type Accountable interface {
WithFollowing
WithFollowers
WithFeatured
WithManuallyApprovesFollowers
}
// Statusable represents the minimum activitypub interface for representing a 'status'.
@ -319,3 +320,8 @@ type WithPartOf interface {
type WithItems interface {
GetActivityStreamsItems() vocab.ActivityStreamsItemsProperty
}
// WithManuallyApprovesFollowers represents a Person or profile with the ManuallyApprovesFollowers property.
type WithManuallyApprovesFollowers interface {
GetActivityStreamsManuallyApprovesFollowers() vocab.ActivityStreamsManuallyApprovesFollowersProperty
}

View file

@ -78,7 +78,7 @@ type Account struct {
*/
// Does this account need an approval for new followers?
Locked bool `pg:",default:true"`
Locked bool `pg:",default:true,use_zero"`
// Should this account be shown in the instance's profile directory?
Discoverable bool `pg:",default:false"`
// Default post privacy for this account

View file

@ -105,7 +105,12 @@ func (c *converter) ASRepresentationToAccount(accountable ap.Accountable, update
}
acct.ActorType = accountable.GetTypeName()
// TODO: locked aka manuallyApprovesFollowers
// locked aka manuallyApprovesFollowers
acct.Locked = true // assume locked by default
maf := accountable.GetActivityStreamsManuallyApprovesFollowers()
if maf != nil && maf.IsXMLSchemaBoolean() {
acct.Locked = maf.Get()
}
// discoverable
// default to false -- take custom value if it's set though

View file

@ -346,14 +346,26 @@ func (suite *ASToInternalTestSuite) SetupTest() {
}
func (suite *ASToInternalTestSuite) TestParsePerson() {
testPerson := suite.people["new_person_1"]
acct, err := suite.typeconverter.ASRepresentationToAccount(testPerson, false)
assert.NoError(suite.T(), err)
fmt.Printf("%+v", acct)
// TODO: write assertions here, rn we're just eyeballing the output
suite.Equal("https://unknown-instance.com/users/brand_new_person", acct.URI)
suite.Equal("https://unknown-instance.com/users/brand_new_person/following", acct.FollowingURI)
suite.Equal("https://unknown-instance.com/users/brand_new_person/followers", acct.FollowersURI)
suite.Equal("https://unknown-instance.com/users/brand_new_person/inbox", acct.InboxURI)
suite.Equal("https://unknown-instance.com/users/brand_new_person/outbox", acct.OutboxURI)
suite.Equal("https://unknown-instance.com/users/brand_new_person/collections/featured", acct.FeaturedCollectionURI)
suite.Equal("brand_new_person", acct.Username)
suite.Equal("Geoff Brando New Personson", acct.DisplayName)
suite.Equal("hey I'm a new person, your instance hasn't seen me yet uwu", acct.Note)
suite.Equal("https://unknown-instance.com/@brand_new_person", acct.URL)
suite.True(acct.Discoverable)
suite.Equal("https://unknown-instance.com/users/brand_new_person#main-key", acct.PublicKeyURI)
suite.Equal("https://unknown-instance.com/media/some_avatar_filename.jpeg", acct.AvatarRemoteURL)
suite.Equal("https://unknown-instance.com/media/some_header_filename.jpeg", acct.HeaderRemoteURL)
suite.False(acct.Locked)
}
func (suite *ASToInternalTestSuite) TestParseGargron() {

View file

@ -143,7 +143,9 @@ func (c *converter) AccountToAS(a *gtsmodel.Account) (vocab.ActivityStreamsPerso
// manuallyApprovesFollowers
// Will be shown as a locked account.
// TODO: NOT IMPLEMENTED **YET** -- this needs to be added as an activitypub extension to https://github.com/go-fed/activity, see https://github.com/go-fed/activity/tree/master/astool
manuallyApprovesFollowersProp := streams.NewActivityStreamsManuallyApprovesFollowersProperty()
manuallyApprovesFollowersProp.Set(a.Locked)
person.SetActivityStreamsManuallyApprovesFollowers(manuallyApprovesFollowersProp)
// discoverable
// Will be shown in the profile directory.