diff options
Diffstat (limited to 'internal/ap/extract.go')
-rw-r--r-- | internal/ap/extract.go | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/internal/ap/extract.go b/internal/ap/extract.go index 4cefd22dc..41cc5dcbc 100644 --- a/internal/ap/extract.go +++ b/internal/ap/extract.go @@ -35,39 +35,56 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/util" ) -// ExtractObject will extract an object vocab.Type from given implementing interface. -func ExtractObject(with WithObject) vocab.Type { +// ExtractObjects will extract object vocab.Types from given implementing interface. +func ExtractObjects(with WithObject) []TypeOrIRI { // Extract the attached object (if any). - obj := with.GetActivityStreamsObject() - if obj == nil { + objProp := with.GetActivityStreamsObject() + if objProp == nil { return nil } - // Only support single - // objects (for now...) - if obj.Len() != 1 { + // Check for zero len. + if objProp.Len() == 0 { return nil } - // Extract object vocab.Type. - return obj.At(0).GetType() + // Accumulate all of the objects into a slice. + objs := make([]TypeOrIRI, objProp.Len()) + for i := 0; i < objProp.Len(); i++ { + objs[i] = objProp.At(i) + } + + return objs } // ExtractActivityData will extract the usable data type (e.g. Note, Question, etc) and corresponding JSON, from activity. -func ExtractActivityData(activity pub.Activity, rawJSON map[string]any) (vocab.Type, map[string]any, bool) { +func ExtractActivityData(activity pub.Activity, rawJSON map[string]any) ([]TypeOrIRI, []any, bool) { switch typeName := activity.GetTypeName(); { // Activity (has "object"). case isActivity(typeName): - objType := ExtractObject(activity) - if objType == nil { + objTypes := ExtractObjects(activity) + if len(objTypes) == 0 { return nil, nil, false } - objJSON, _ := rawJSON["object"].(map[string]any) - return objType, objJSON, true + + var objJSON []any + switch json := rawJSON["object"].(type) { + case nil: + // do nothing + case map[string]any: + // Wrap map in slice. + objJSON = []any{json} + case []any: + // Use existing slice. + objJSON = json + } + + return objTypes, objJSON, true // IntransitiveAcitivity (no "object"). case isIntransitiveActivity(typeName): - return activity, rawJSON, false + asTypeOrIRI := _TypeOrIRI{activity} // wrap activity. + return []TypeOrIRI{&asTypeOrIRI}, []any{rawJSON}, true // Unknown. default: |