From 1d854423cb664d9099209867824687faf58f3933 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Mon, 1 Apr 2019 23:40:29 +0000 Subject: [PATCH] Switch Audience from Vector to list and fix Public bug * No good reason to use Vector, let's use list, it's just easier * The Public URI recognizing code wasn't being used; now it is --- src/Vervis/Federation.hs | 4 ++-- src/Web/ActivityPub.hs | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Vervis/Federation.hs b/src/Vervis/Federation.hs index 8273643..30bbe74 100644 --- a/src/Vervis/Federation.hs +++ b/src/Vervis/Federation.hs @@ -79,12 +79,12 @@ parseAudience :: Monad m => Audience -> Text -> ExceptT Text m FedURI parseAudience (Audience to bto cc bcc aud) t = case toSingleton to of Just fu - | V.null bto && V.null cc && V.null bcc && V.null aud -> + | null bto && null cc && null bcc && null aud -> return fu _ -> throwE t where toSingleton v = - case V.toList v of + case v of [x] -> Just x _ -> Nothing diff --git a/src/Web/ActivityPub.hs b/src/Web/ActivityPub.hs index 1da5a8d..9923d7e 100644 --- a/src/Web/ActivityPub.hs +++ b/src/Web/ActivityPub.hs @@ -318,20 +318,20 @@ instance ActivityPub Actor where <> "publicKey" `pair` encodePublicKeySet host pkeys data Audience = Audience - { audienceTo :: Vector FedURI - , audienceBto :: Vector FedURI - , audienceCc :: Vector FedURI - , audienceBcc :: Vector FedURI - , audienceGeneral :: Vector FedURI + { audienceTo :: [FedURI] + , audienceBto :: [FedURI] + , audienceCc :: [FedURI] + , audienceBcc :: [FedURI] + , audienceGeneral :: [FedURI] } deliverTo :: FedURI -> Audience deliverTo to = Audience - { audienceTo = V.singleton to - , audienceBto = V.empty - , audienceCc = V.empty - , audienceBcc = V.empty - , audienceGeneral = V.empty + { audienceTo = [to] + , audienceBto = [] + , audienceCc = [] + , audienceBcc = [] + , audienceGeneral = [] } newtype AdaptAudience = AdaptAudience @@ -351,15 +351,15 @@ instance FromJSON AdaptAudience where parseAudience :: Object -> Parser Audience parseAudience o = Audience - <$> o .:? "to" .!= V.empty - <*> o .:? "bto" .!= V.empty - <*> o .:? "cc" .!= V.empty - <*> o .:? "bcc" .!= V.empty - <*> o .:? "audience" .!= V.empty + <$> o .:& "to" + <*> o .:& "bto" + <*> o .:& "cc" + <*> o .:& "bcc" + <*> o .:& "audience" where obj .:& key = do - vec <- obj .:? key .!= V.empty - return $ unAdapt <$> vec + l <- obj .:? key .!= [] + return $ map unAdapt l encodeAudience :: Audience -> Series encodeAudience (Audience to bto cc bcc aud) @@ -370,7 +370,7 @@ encodeAudience (Audience to bto cc bcc aud) <> "audience" .=% aud where t .=% v = - if V.null v + if null v then mempty else t .= v