Recognize the 3 variants of the Public collection URI when parsing audience

This commit is contained in:
fr33domlover 2019-03-21 19:13:36 +00:00
parent 77324442fc
commit 061c84349d

View file

@ -43,6 +43,7 @@ module Web.ActivityPub
, Activity (..) , Activity (..)
-- * Utilities -- * Utilities
, publicURI
, hActivityPubActor , hActivityPubActor
, provideAP , provideAP
, APGetError (..) , APGetError (..)
@ -110,6 +111,12 @@ as2context = "https://www.w3.org/ns/activitystreams"
secContext :: Text secContext :: Text
secContext = "https://w3id.org/security/v1" secContext = "https://w3id.org/security/v1"
publicURI :: FedURI
publicURI = FedURI "www.w3.org" "/ns/activitystreams" "#Public"
publicT :: Text
publicT = renderFedURI publicURI
actorContext :: [Text] actorContext :: [Text]
actorContext = [as2context, secContext] actorContext = [as2context, secContext]
@ -407,6 +414,20 @@ data Audience = Audience
, audienceGeneral :: Vector FedURI , 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 :: Object -> Parser Audience
parseAudience o = parseAudience o =
Audience Audience
@ -415,6 +436,10 @@ parseAudience o =
<*> o .:? "cc" .!= V.empty <*> o .:? "cc" .!= V.empty
<*> o .:? "bcc" .!= V.empty <*> o .:? "bcc" .!= V.empty
<*> o .:? "audience" .!= V.empty <*> o .:? "audience" .!= V.empty
where
obj .:& key = do
vec <- obj .:? key .!= V.empty
return $ unAdapt <$> vec
encodeAudience :: Audience -> Series encodeAudience :: Audience -> Series
encodeAudience (Audience to bto cc bcc aud) encodeAudience (Audience to bto cc bcc aud)