From 43014ca473cfc5ca201fa917d00ddc8dee06a313 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 10 Nov 2023 16:08:15 +0100 Subject: [PATCH] Implement MarshallJSON for Star activity --- modules/forgefed/star.go | 12 ++++++++++++ modules/forgefed/star_test.go | 15 ++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/forgefed/star.go b/modules/forgefed/star.go index a32fb173a6..e0001c7cbb 100644 --- a/modules/forgefed/star.go +++ b/modules/forgefed/star.go @@ -52,3 +52,15 @@ func StarNew(id ap.ID, ob ap.ID) *Star { 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 +} diff --git a/modules/forgefed/star_test.go b/modules/forgefed/star_test.go index e6a7d8311d..04e6373778 100644 --- a/modules/forgefed/star_test.go +++ b/modules/forgefed/star_test.go @@ -26,19 +26,12 @@ func Test_StarMarshalJSON(t *testing.T) { item: Star{ Source: "forgejo", Activity: ap.Activity{ - ID: "https://repo.prod.meissa.de/api/activitypub/user-id/1", - Type: "Star", - Object: ap.Object{ - ID: "https://codeberg.org/api/activitypub/repository-id/1", - }, + Actor: ap.IRI("https://repo.prod.meissa.de/api/activitypub/user-id/1"), + Type: "Star", + Object: ap.IRI("https://codeberg.org/api/activitypub/repository-id/1"), }, }, - want: []byte(`{ - "type": "Star", - "source": "forgejo", - "actor": "https://repo.prod.meissa.de/api/activitypub/user-id/1", - "object": "https://codeberg.org/api/activitypub/repository-id/1" - }`), + 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"}`), }, }