~mariusor/activitypub-go

4 2

Specifying a custom NotEmpty function and exporting JSON write functions

Anthony Wang <a@exozy.me>
Details
Message ID
<f23190d1-1376-6ad1-63ee-9c0d291d1eb5@exozy.me>
DKIM signature
missing
Download raw message
Hi Marius,

The default go-ap NotEmpty function seems to fail on ForgeFed types, so 
I created this patch so that I can specify a custom NotEmpty function 
that handles ForgeFed types:

diff --git a/decoding_json.go b/decoding_json.go
index 5bd1334..1423284 100644
--- a/decoding_json.go
+++ b/decoding_json.go
@@ -25,6 +25,9 @@ var ItemTyperFunc TyperFn = GetItemByType
  // JSONItemUnmarshal can be set externally to populate a custom object 
based on its type
  var JSONItemUnmarshal JSONUnmarshalerFn = nil

+// NotEmptyChecker checks if an object is empty
+var NotEmptyChecker NotEmptyCheckerFn = NotEmpty
+
  // TyperFn is the type of the function which returns an Item struct 
instance
  // for a specific ActivityVocabularyType
  type TyperFn func(ActivityVocabularyType) (Item, error)
@@ -33,6 +36,9 @@ type TyperFn func(ActivityVocabularyType) (Item, error)
  // that the current package doesn't know about.
  type JSONUnmarshalerFn func(ActivityVocabularyType, *fastjson.Value, 
Item) error

+// NotEmptyCheckerFn is the type of a function that checks if an object 
is empty
+type NotEmptyCheckerFn func(Item) bool
+
  func JSONGetID(val *fastjson.Value) ID {
         i := val.Get("id").GetStringBytes()
         return ID(i)
@@ -186,7 +192,7 @@ func JSONLoadItem(val *fastjson.Value) (Item, error) {
         if err != nil || IsNil(i) {
                 return nil, nil
         }
-       var empty = func(i Item) bool { return !NotEmpty(i) }
+       var empty = func(i Item) bool { return !NotEmptyChecker(i) }

         switch typ {
         case "":


Also, could you export all the write* functions as JSONWrite*? It's 
basically just sed -i "s/write/JSONWrite/g" as you can see here: 
https://gitea.com/xy/activitypub/commit/29bb602eb100acca041ee025d8cffa0a8baf3195

Thanks!

~Anthony Wang
Details
Message ID
<20221128030433.wsjddt35py5vizrl@tp>
In-Reply-To
<f23190d1-1376-6ad1-63ee-9c0d291d1eb5@exozy.me> (view parent)
DKIM signature
pass
Download raw message
On 22-11-26 11:23:40, Anthony Wang wrote:
> Hi Marius,
> 
> The default go-ap NotEmpty function seems to fail on ForgeFed types, so I
> created this patch so that I can specify a custom NotEmpty function that
> handles ForgeFed types:

Hey Anthony, thank you for the patch. It will have to wait until the end
of the year, as I'm on holiday and focusing on other parts of the library
at the moment.

Will ping you when I get back and have the time to review it.

Cheers,
/Marius
Anthony Wang <a@exozy.me>
Details
Message ID
<069deca6-e0cc-751f-dd36-ec1099961fe8@exozy.me>
In-Reply-To
<20221128030433.wsjddt35py5vizrl@tp> (view parent)
DKIM signature
missing
Download raw message
On 11/27/22 22:04, Marius Orcsik wrote:
> Hey Anthony, thank you for the patch. It will have to wait until the end
> of the year, as I'm on holiday and focusing on other parts of the library
> at the moment.
>
> Will ping you when I get back and have the time to review it.

Hi Marius,

Do you have time now to review the patch?

Thanks

~Anthony Wang
Details
Message ID
<20230116094951.dgfvmt72ia6xfo7t@tp>
In-Reply-To
<069deca6-e0cc-751f-dd36-ec1099961fe8@exozy.me> (view parent)
DKIM signature
pass
Download raw message
On 23-01-15 13:35:07, Anthony Wang wrote:
> On 11/27/22 22:04, Marius Orcsik wrote:
> Hi Marius,
> 
> Do you have time now to review the patch?
> 

Hi Anthony, apologies, I must delay again. I am cought up in some
stressful activities until the end of the month.

Are you OK with waiting until then?

Best,
/Marius
Anthony Wang <a@exozy.me>
Details
Message ID
<3286e0ae-d45a-9411-3900-5a4d06f02495@exozy.me>
In-Reply-To
<20230116094951.dgfvmt72ia6xfo7t@tp> (view parent)
DKIM signature
missing
Download raw message
On 1/16/23 04:49, Marius Orcsik wrote:
> Hi Anthony, apologies, I must delay again. I am cought up in some
> stressful activities until the end of the month.
>
> Are you OK with waiting until then?

Yes, that's fine.

Thanks!

~Anthony
Reply to thread Export thread (mbox)