MCPcopy
hub / github.com/writefreely/writefreely / unmarshalActor

Function unmarshalActor

activitypub.go:1115–1153  ·  view source on GitHub ↗

unmarshal actor normalizes the actor response to conform to the type Person from github.com/writeas/web-core/activitysteams some implementations return different context field types this converts any non-slice contexts into a slice

(actorResp []byte, actor *activitystreams.Person)

Source from the content-addressed store, hash-verified

1113// some implementations return different context field types
1114// this converts any non-slice contexts into a slice
1115func unmarshalActor(actorResp []byte, actor *activitystreams.Person) error {
1116 // FIXME: Hubzilla has an object for the Actor's url: cannot unmarshal object into Go struct field Person.url of type string
1117
1118 // flexActor overrides the Context field to allow
1119 // all valid representations during unmarshal
1120 flexActor := struct {
1121 activitystreams.Person
1122 Context json.RawMessage `json:"@context,omitempty"`
1123 }{}
1124 if err := json.Unmarshal(actorResp, &flexActor); err != nil {
1125 return err
1126 }
1127
1128 actor.Endpoints = flexActor.Endpoints
1129 actor.Followers = flexActor.Followers
1130 actor.Following = flexActor.Following
1131 actor.ID = flexActor.ID
1132 actor.Icon = flexActor.Icon
1133 actor.Inbox = flexActor.Inbox
1134 actor.Name = flexActor.Name
1135 actor.Outbox = flexActor.Outbox
1136 actor.PreferredUsername = flexActor.PreferredUsername
1137 actor.PublicKey = flexActor.PublicKey
1138 actor.Summary = flexActor.Summary
1139 actor.Type = flexActor.Type
1140 actor.URL = flexActor.URL
1141
1142 func(val interface{}) {
1143 switch val.(type) {
1144 case []interface{}:
1145 // already a slice, do nothing
1146 actor.Context = val.([]interface{})
1147 default:
1148 actor.Context = []interface{}{val}
1149 }
1150 }(flexActor.Context)
1151
1152 return nil
1153}
1154
1155func parsePostIDFromURL(app *App, u *url.URL) (string, error) {
1156 // Get post ID from URL

Callers 2

TestUnmarshalActorFunction · 0.85
getActorFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestUnmarshalActorFunction · 0.68