summaryrefslogtreecommitdiff
path: root/internal/ap/normalize.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-02-06 10:45:46 +0100
committerLibravatar GitHub <noreply@github.com>2024-02-06 09:45:46 +0000
commitaa396c78d30c129bb2145765d3990571dbc025bb (patch)
treec2046f00c80b029d4f44a1eaf97ca2e960a492cf /internal/ap/normalize.go
parent[chore]: Bump github.com/miekg/dns from 1.1.57 to 1.1.58 (#2606) (diff)
downloadgotosocial-aa396c78d30c129bb2145765d3990571dbc025bb.tar.xz
[feature] serdes for moved/also_known_as (#2600)
* [feature] serdes for moved/also_known_as * document `alsoKnownAs` and `movedTo` properties * only implicitly populate AKA uris from DB for local accounts * don't let remotes store more than 20 AKA uris to avoid shenanigans
Diffstat (limited to 'internal/ap/normalize.go')
-rw-r--r--internal/ap/normalize.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/ap/normalize.go b/internal/ap/normalize.go
index a27527b84..8e0a022c1 100644
--- a/internal/ap/normalize.go
+++ b/internal/ap/normalize.go
@@ -391,6 +391,36 @@ func NormalizeOutgoingAttachmentProp(item WithAttachment, rawJSON map[string]int
rawJSON["attachment"] = []interface{}{attachment}
}
+// NormalizeOutgoingAlsoKnownAsProp replaces single-entry alsoKnownAs values with
+// single-entry arrays, for better compatibility with other AP implementations.
+//
+// Ie:
+//
+// "alsoKnownAs": "https://example.org/users/some_user"
+//
+// becomes:
+//
+// "alsoKnownAs": ["https://example.org/users/some_user"]
+//
+// Noop for items with no attachments, or with attachments that are already a slice.
+func NormalizeOutgoingAlsoKnownAsProp(item WithAlsoKnownAs, rawJSON map[string]interface{}) {
+ alsoKnownAs, ok := rawJSON["alsoKnownAs"]
+ if !ok {
+ // No 'alsoKnownAs',
+ // nothing to change.
+ return
+ }
+
+ if _, ok := alsoKnownAs.([]interface{}); ok {
+ // Already slice,
+ // nothing to change.
+ return
+ }
+
+ // Coerce single-object to slice.
+ rawJSON["alsoKnownAs"] = []interface{}{alsoKnownAs}
+}
+
// NormalizeOutgoingContentProp normalizes go-fed's funky formatting of content and
// contentMap properties to a format better understood by other AP implementations.
//