Change type of Actor.Streams to be just an item collection

This commit is contained in:
mariusor 2022-01-28 12:47:59 +01:00
parent 8f025c2e36
commit c61421fde8
No known key found for this signature in database
GPG key ID: DBF5E47F5DBC4D21
4 changed files with 13 additions and 31 deletions

View file

@ -156,8 +156,8 @@ type Actor struct {
// to a JSON-LD document with these properties.
Endpoints *Endpoints `jsonld:"endpoints,omitempty"`
// A list of supplementary Collections which may be of interest.
Streams []ItemCollection `jsonld:"streams,omitempty"`
PublicKey PublicKey `jsonld:"publicKey,omitempty"`
Streams ItemCollection `jsonld:"streams,omitempty"`
PublicKey PublicKey `jsonld:"publicKey,omitempty"`
}
// GetID returns the ID corresponding to the current Actor
@ -396,11 +396,7 @@ func (a Actor) MarshalJSON() ([]byte, error) {
}
if len(a.Streams) > 0 {
writePropJSONName(&b, "streams")
lNotEmpty := true
for _, ss := range a.Streams {
lNotEmpty = writeItemCollectionJSONValue(&b, ss) || lNotEmpty
}
notEmpty = lNotEmpty || notEmpty
notEmpty = notEmpty || writeItemCollectionJSONValue(&b, a.Streams)
}
if len(a.PublicKey.PublicKeyPem)+len(a.PublicKey.ID) > 0 {
if v, err := a.PublicKey.MarshalJSON(); err == nil && len(v) > 0 {

View file

@ -73,11 +73,11 @@ func unmapActorProperties(mm map[string][]byte, a *Actor) error {
return err
}
}
//if raw, ok := mm["streams"]; ok {
// if err = a.Streams.GobDecode(raw); err != nil {
// return err
// }
//}
if raw, ok := mm["streams"]; ok {
if a.Streams, err = gobDecodeItems(raw); err != nil {
return err
}
}
if raw, ok := mm["publicKey"]; ok {
if err = a.PublicKey.GobDecode(raw); err != nil {
return err

View file

@ -132,11 +132,6 @@ func JSONGetPublicKey(val *fastjson.Value, prop string) PublicKey {
return key
}
func JSONGetStreams(val *fastjson.Value, prop string) []ItemCollection {
// TODO(marius)
return nil
}
func itemsFn(val *fastjson.Value) (Item, error) {
if val.Type() == fastjson.TypeArray {
it := val.GetArray()
@ -512,7 +507,7 @@ func loadActor(val *fastjson.Value, a *Actor) error {
a.Outbox = JSONGetItem(val, "outbox")
a.Liked = JSONGetItem(val, "liked")
a.Endpoints = JSONGetActorEndpoints(val, "endpoints")
a.Streams = JSONGetStreams(val, "streams")
a.Streams = JSONGetItems(val, "streams")
a.PublicKey = JSONGetPublicKey(val, "publicKey")
return nil
}

View file

@ -47,15 +47,6 @@ func gobEncodeBool(t bool) ([]byte, error) {
return b.Bytes(), nil
}
func gobEncodeBytes(s []byte) ([]byte, error) {
b := bytes.Buffer{}
gg := gob.NewEncoder(&b)
if err := gg.Encode(s); err != nil {
return nil, err
}
return b.Bytes(), nil
}
func gobEncodeStringLikeType(g *gob.Encoder, s []byte) error {
if err := g.Encode(s); err != nil {
return err
@ -459,10 +450,10 @@ func mapActorProperties(mm map[string][]byte, a *Actor) (hasData bool, err error
hasData = true
}
if len(a.Streams) > 0 {
//if mm["streams"], err = gobDecodeItem(a.Streams); err != nil {
// return hasData, err
//}
//hasData = true
if mm["streams"], err = gobEncodeItems(a.Streams); err != nil {
return hasData, err
}
hasData = true
}
if len(a.PublicKey.PublicKeyPem)+len(a.PublicKey.ID) > 0 {
if mm["publicKey"], err = a.PublicKey.GobEncode(); err != nil {