diff options
author | 2023-11-21 15:13:30 +0100 | |
---|---|---|
committer | 2023-11-21 15:13:30 +0100 | |
commit | cfefbc08d822cd85787d95dc2ee253e3368826d8 (patch) | |
tree | af6d6257dddca1645ab5f8e34a1c79ac80d82e0e /internal/ap/extract.go | |
parent | [docs] Annotate split-domain setup (#2372) (diff) | |
download | gotosocial-cfefbc08d822cd85787d95dc2ee253e3368826d8.tar.xz |
[feature] Federate status language in and out (#2366)
* [feature] Federate status language in + out
* go fmt
* tests, little fix
* improve comments
* unnest a bit
* avoid unnecessary nil check
* use more descriptive variable for contentMap
* prefer instance languages when selecting from contentMap
* update docs to reflect lang selection
* rename rdfLangString -> rdfLangs
* update comments to mention Pollable
* iter through slice instead of map
Diffstat (limited to 'internal/ap/extract.go')
-rw-r--r-- | internal/ap/extract.go | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/internal/ap/extract.go b/internal/ap/extract.go index 424f77409..3d92fa2ba 100644 --- a/internal/ap/extract.go +++ b/internal/ap/extract.go @@ -631,27 +631,34 @@ func ExtractPublicKey(i WithPublicKey) ( return nil, nil, nil, gtserror.New("couldn't find public key") } -// ExtractContent returns a string representation of the -// given interface's Content property, or an empty string -// if no Content is found. -func ExtractContent(i WithContent) string { - contentProperty := i.GetActivityStreamsContent() - if contentProperty == nil { - return "" +// ExtractContent returns an intermediary representation of +// the given interface's Content and/or ContentMap property. +func ExtractContent(i WithContent) gtsmodel.Content { + content := gtsmodel.Content{} + + contentProp := i.GetActivityStreamsContent() + if contentProp == nil { + // No content at all. + return content } - for iter := contentProperty.Begin(); iter != contentProperty.End(); iter = iter.Next() { + for iter := contentProp.Begin(); iter != contentProp.End(); iter = iter.Next() { switch { - // Content may be parsed as IRI, depending on - // how it's formatted, so account for this. - case iter.IsXMLSchemaString(): - return iter.GetXMLSchemaString() - case iter.IsIRI(): - return iter.GetIRI().String() + case iter.IsRDFLangString() && + len(content.ContentMap) == 0: + content.ContentMap = iter.GetRDFLangString() + + case iter.IsXMLSchemaString() && + content.Content == "": + content.Content = iter.GetXMLSchemaString() + + case iter.IsIRI() && + content.Content == "": + content.Content = iter.GetIRI().String() } } - return "" + return content } // ExtractAttachments attempts to extract barebones MediaAttachment objects from given AS interface type. |