mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 11:16:11 +01:00
Implement MarshallJSON for Star activity
This commit is contained in:
parent
a1885a5767
commit
43014ca473
|
@ -52,3 +52,15 @@ func StarNew(id ap.ID, ob ap.ID) *Star {
|
||||||
func AddStar(ctx *context.APIContext) {
|
func AddStar(ctx *context.APIContext) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a Star) MarshalJSON() ([]byte, error) {
|
||||||
|
b := make([]byte, 0)
|
||||||
|
ap.JSONWrite(&b, '{')
|
||||||
|
|
||||||
|
ap.JSONWriteStringProp(&b, "source", string(a.Source))
|
||||||
|
if !ap.JSONWriteActivityValue(&b, a.Activity) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
ap.JSONWrite(&b, '}')
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
|
@ -26,19 +26,12 @@ func Test_StarMarshalJSON(t *testing.T) {
|
||||||
item: Star{
|
item: Star{
|
||||||
Source: "forgejo",
|
Source: "forgejo",
|
||||||
Activity: ap.Activity{
|
Activity: ap.Activity{
|
||||||
ID: "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
Actor: ap.IRI("https://repo.prod.meissa.de/api/activitypub/user-id/1"),
|
||||||
Type: "Star",
|
Type: "Star",
|
||||||
Object: ap.Object{
|
Object: ap.IRI("https://codeberg.org/api/activitypub/repository-id/1"),
|
||||||
ID: "https://codeberg.org/api/activitypub/repository-id/1",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []byte(`{
|
want: []byte(`{"source":"forgejo","type":"Star","actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1","object":"https://codeberg.org/api/activitypub/repository-id/1"}`),
|
||||||
"type": "Star",
|
|
||||||
"source": "forgejo",
|
|
||||||
"actor": "https://repo.prod.meissa.de/api/activitypub/user-id/1",
|
|
||||||
"object": "https://codeberg.org/api/activitypub/repository-id/1"
|
|
||||||
}`),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue