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)