Adding Tag property unmarshalling for Objects
This commit is contained in:
parent
c53d21a18e
commit
9dcc89db96
5 changed files with 61 additions and 2 deletions
|
@ -122,7 +122,7 @@ func (l *Link) UnmarshalJSON(data []byte) error {
|
|||
l.Name = getAPNaturalLanguageField(data, "name")
|
||||
l.HrefLang = getAPLangRefField(data, "hrefLang")
|
||||
u := getURIField(data, "href")
|
||||
if !u.IsObject() {
|
||||
if u != nil && !u.IsObject() {
|
||||
l.Href = u.GetLink()
|
||||
}
|
||||
|
||||
|
@ -130,3 +130,13 @@ func (l *Link) UnmarshalJSON(data []byte) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON
|
||||
func (m *Mention) UnmarshalJSON(data []byte) error {
|
||||
l := Link{}
|
||||
|
||||
err := l.UnmarshalJSON(data)
|
||||
*m = Mention(l)
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -198,6 +198,9 @@ func getAPObjectByType(typ ActivityVocabularyType) (Item, error) {
|
|||
ret = &View{}
|
||||
o := ret.(*View)
|
||||
o.Type = typ
|
||||
case "":
|
||||
// when no type is available use a plain Object
|
||||
ret = &Object{}
|
||||
default:
|
||||
ret = nil
|
||||
err = fmt.Errorf("unrecognized ActivityPub type %q", typ)
|
||||
|
|
|
@ -629,6 +629,9 @@ func (o *Object) UnmarshalJSON(data []byte) error {
|
|||
o.Replies = &r
|
||||
}
|
||||
}
|
||||
|
||||
tag := getAPItemCollection(data, "tag")
|
||||
if tag != nil {
|
||||
o.Tag = tag
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
17
tests/mocks/object_with_tags.json
Normal file
17
tests/mocks/object_with_tags.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"type": "Object",
|
||||
"id": "http://www.test.example/object/1",
|
||||
"name": "A Simple, non-specific object",
|
||||
"tag": [
|
||||
{
|
||||
"name": "#my_tag",
|
||||
"ID": "http://example.com/tag/my_tag"
|
||||
},
|
||||
{
|
||||
"name": "@ana",
|
||||
"type": "Mention",
|
||||
"ID": "http://example.com/users/ana"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -234,6 +234,32 @@ var allTests = tests{
|
|||
}},
|
||||
},
|
||||
},
|
||||
"object_with_tags": testPair{
|
||||
expected: true,
|
||||
blank: &a.Object{},
|
||||
result: &a.Object{
|
||||
Type: a.ObjectType,
|
||||
ID: a.ObjectID("http://www.test.example/object/1"),
|
||||
Name: a.NaturalLanguageValue{{
|
||||
a.NilLangRef, "A Simple, non-specific object",
|
||||
}},
|
||||
Tag: a.ItemCollection{
|
||||
&a.Object{
|
||||
Name: a.NaturalLanguageValue{{
|
||||
a.NilLangRef, "#my_tag",
|
||||
}},
|
||||
ID: a.ObjectID("http://example.com/tag/my_tag"),
|
||||
},
|
||||
&a.Mention{
|
||||
Name: a.NaturalLanguageValue{{
|
||||
a.NilLangRef, "@ana",
|
||||
}},
|
||||
Type: a.MentionType,
|
||||
ID: a.ObjectID("http://example.com/users/ana"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"object_with_replies": testPair{
|
||||
expected: true,
|
||||
blank: &a.Object{},
|
||||
|
|
Reference in a new issue