From 061c84349dc3eedbe1b3d4f1d3b913beb56f5d30 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Thu, 21 Mar 2019 19:13:36 +0000 Subject: [PATCH] Recognize the 3 variants of the Public collection URI when parsing audience --- src/Web/ActivityPub.hs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Web/ActivityPub.hs b/src/Web/ActivityPub.hs index 07b0706..7155d3b 100644 --- a/src/Web/ActivityPub.hs +++ b/src/Web/ActivityPub.hs @@ -43,6 +43,7 @@ module Web.ActivityPub , Activity (..) -- * Utilities + , publicURI , hActivityPubActor , provideAP , APGetError (..) @@ -110,6 +111,12 @@ as2context = "https://www.w3.org/ns/activitystreams" secContext :: Text secContext = "https://w3id.org/security/v1" +publicURI :: FedURI +publicURI = FedURI "www.w3.org" "/ns/activitystreams" "#Public" + +publicT :: Text +publicT = renderFedURI publicURI + actorContext :: [Text] actorContext = [as2context, secContext] @@ -407,6 +414,20 @@ data Audience = Audience , audienceGeneral :: Vector FedURI } +newtype AdaptAudience = AdaptAudience + { unAdapt :: FedURI + } + +instance FromJSON AdaptAudience where + parseJSON = parseJSON . adapt + where + adapt v = + case v of + String t + | t == "Public" -> String publicT + | t == "as:Public" -> String publicT + _ -> v + parseAudience :: Object -> Parser Audience parseAudience o = Audience @@ -415,6 +436,10 @@ parseAudience o = <*> o .:? "cc" .!= V.empty <*> o .:? "bcc" .!= V.empty <*> o .:? "audience" .!= V.empty + where + obj .:& key = do + vec <- obj .:? key .!= V.empty + return $ unAdapt <$> vec encodeAudience :: Audience -> Series encodeAudience (Audience to bto cc bcc aud)