From 0e29f1f5bb68a48d9b837d7f4e0a16370734955b Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 9 May 2023 12:16:10 +0200 Subject: [feature] Enable federation in/out of profile PropertyValue fields (#1722) Co-authored-by: kim Co-authored-by: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> --- internal/ap/extract.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'internal/ap/extract.go') diff --git a/internal/ap/extract.go b/internal/ap/extract.go index 2742d27ac..ce7c03901 100644 --- a/internal/ap/extract.go +++ b/internal/ap/extract.go @@ -266,6 +266,59 @@ func ExtractSummary(i WithSummary) string { return "" } +func ExtractFields(i WithAttachment) []*gtsmodel.Field { + attachmentProp := i.GetActivityStreamsAttachment() + if attachmentProp == nil { + // Nothing to do. + return nil + } + + l := attachmentProp.Len() + if l == 0 { + // Nothing to do. + return nil + } + + fields := make([]*gtsmodel.Field, 0, l) + for iter := attachmentProp.Begin(); iter != attachmentProp.End(); iter = iter.Next() { + if !iter.IsSchemaPropertyValue() { + continue + } + + propertyValue := iter.GetSchemaPropertyValue() + if propertyValue == nil { + continue + } + + nameProp := propertyValue.GetActivityStreamsName() + if nameProp == nil || nameProp.Len() != 1 { + continue + } + + name := nameProp.At(0).GetXMLSchemaString() + if name == "" { + continue + } + + valueProp := propertyValue.GetSchemaValue() + if valueProp == nil || !valueProp.IsXMLSchemaString() { + continue + } + + value := valueProp.Get() + if value == "" { + continue + } + + fields = append(fields, >smodel.Field{ + Name: name, + Value: value, + }) + } + + return fields +} + // ExtractDiscoverable extracts the Discoverable boolean of an interface. func ExtractDiscoverable(i WithDiscoverable) (bool, error) { if i.GetTootDiscoverable() == nil { -- cgit v1.2.3