diff options
author | 2024-01-19 14:02:04 +0100 | |
---|---|---|
committer | 2024-01-19 13:02:04 +0000 | |
commit | 5ca86b1c575f9c42ad8d3d4a2b2d3e70c89e90df (patch) | |
tree | 3ac7578cd35b9c2f1dfb3903ef769d32f9c58d3d /internal/ap | |
parent | [performance] overhaul struct (+ result) caching library for simplicity, perf... (diff) | |
download | gotosocial-5ca86b1c575f9c42ad8d3d4a2b2d3e70c89e90df.tar.xz |
[chore] Harden up boolptr logic on Accounts, warn if not set (#2544)
Diffstat (limited to 'internal/ap')
-rw-r--r-- | internal/ap/extract.go | 12 | ||||
-rw-r--r-- | internal/ap/properties.go | 23 |
2 files changed, 23 insertions, 12 deletions
diff --git a/internal/ap/extract.go b/internal/ap/extract.go index 11c20494c..2b49c6477 100644 --- a/internal/ap/extract.go +++ b/internal/ap/extract.go @@ -492,18 +492,6 @@ func ExtractFields(i WithAttachment) []*gtsmodel.Field { return fields } -// ExtractDiscoverable extracts the Discoverable boolean -// of the given WithDiscoverable interface. Will return -// an error if Discoverable was nil. -func ExtractDiscoverable(i WithDiscoverable) (bool, error) { - discoverableProp := i.GetTootDiscoverable() - if discoverableProp == nil { - return false, gtserror.New("discoverable was nil") - } - - return discoverableProp.Get(), nil -} - // ExtractURL extracts the first URI it can find from the // given WithURL interface, or an error if no URL was set. // The ID of a type will not work, this function wants a URI diff --git a/internal/ap/properties.go b/internal/ap/properties.go index 2b23c7cb2..6103608d6 100644 --- a/internal/ap/properties.go +++ b/internal/ap/properties.go @@ -424,6 +424,8 @@ func SetVotersCount(with WithVotersCount, count int) { } // GetDiscoverable returns the boolean contained in the Discoverable property of 'with'. +// +// Returns default 'false' if property unusable or not set. func GetDiscoverable(with WithDiscoverable) bool { discoverProp := with.GetTootDiscoverable() if discoverProp == nil || !discoverProp.IsXMLSchemaBoolean() { @@ -442,6 +444,27 @@ func SetDiscoverable(with WithDiscoverable, discoverable bool) { discoverProp.Set(discoverable) } +// GetManuallyApprovesFollowers returns the boolean contained in the ManuallyApprovesFollowers property of 'with'. +// +// Returns default 'true' if property unusable or not set. +func GetManuallyApprovesFollowers(with WithManuallyApprovesFollowers) bool { + mafProp := with.GetActivityStreamsManuallyApprovesFollowers() + if mafProp == nil || !mafProp.IsXMLSchemaBoolean() { + return true + } + return mafProp.Get() +} + +// SetManuallyApprovesFollowers sets the given boolean on the ManuallyApprovesFollowers property of 'with'. +func SetManuallyApprovesFollowers(with WithManuallyApprovesFollowers, manuallyApprovesFollowers bool) { + mafProp := with.GetActivityStreamsManuallyApprovesFollowers() + if mafProp == nil { + mafProp = streams.NewActivityStreamsManuallyApprovesFollowersProperty() + with.SetActivityStreamsManuallyApprovesFollowers(mafProp) + } + mafProp.Set(manuallyApprovesFollowers) +} + func getIRIs[T TypeOrIRI](prop Property[T]) []*url.URL { if prop == nil || prop.Len() == 0 { return nil |