1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-28 07:44:50 +09:00

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
This commit is contained in:
fr33domlover 2019-04-01 23:40:29 +00:00
parent 0c280c7af6
commit 1d854423cb
2 changed files with 20 additions and 20 deletions

View file

@ -79,12 +79,12 @@ parseAudience :: Monad m => Audience -> Text -> ExceptT Text m FedURI
parseAudience (Audience to bto cc bcc aud) t = parseAudience (Audience to bto cc bcc aud) t =
case toSingleton to of case toSingleton to of
Just fu Just fu
| V.null bto && V.null cc && V.null bcc && V.null aud -> | null bto && null cc && null bcc && null aud ->
return fu return fu
_ -> throwE t _ -> throwE t
where where
toSingleton v = toSingleton v =
case V.toList v of case v of
[x] -> Just x [x] -> Just x
_ -> Nothing _ -> Nothing

View file

@ -318,20 +318,20 @@ instance ActivityPub Actor where
<> "publicKey" `pair` encodePublicKeySet host pkeys <> "publicKey" `pair` encodePublicKeySet host pkeys
data Audience = Audience data Audience = Audience
{ audienceTo :: Vector FedURI { audienceTo :: [FedURI]
, audienceBto :: Vector FedURI , audienceBto :: [FedURI]
, audienceCc :: Vector FedURI , audienceCc :: [FedURI]
, audienceBcc :: Vector FedURI , audienceBcc :: [FedURI]
, audienceGeneral :: Vector FedURI , audienceGeneral :: [FedURI]
} }
deliverTo :: FedURI -> Audience deliverTo :: FedURI -> Audience
deliverTo to = Audience deliverTo to = Audience
{ audienceTo = V.singleton to { audienceTo = [to]
, audienceBto = V.empty , audienceBto = []
, audienceCc = V.empty , audienceCc = []
, audienceBcc = V.empty , audienceBcc = []
, audienceGeneral = V.empty , audienceGeneral = []
} }
newtype AdaptAudience = AdaptAudience newtype AdaptAudience = AdaptAudience
@ -351,15 +351,15 @@ instance FromJSON AdaptAudience where
parseAudience :: Object -> Parser Audience parseAudience :: Object -> Parser Audience
parseAudience o = parseAudience o =
Audience Audience
<$> o .:? "to" .!= V.empty <$> o .:& "to"
<*> o .:? "bto" .!= V.empty <*> o .:& "bto"
<*> o .:? "cc" .!= V.empty <*> o .:& "cc"
<*> o .:? "bcc" .!= V.empty <*> o .:& "bcc"
<*> o .:? "audience" .!= V.empty <*> o .:& "audience"
where where
obj .:& key = do obj .:& key = do
vec <- obj .:? key .!= V.empty l <- obj .:? key .!= []
return $ unAdapt <$> vec return $ map unAdapt l
encodeAudience :: Audience -> Series encodeAudience :: Audience -> Series
encodeAudience (Audience to bto cc bcc aud) encodeAudience (Audience to bto cc bcc aud)
@ -370,7 +370,7 @@ encodeAudience (Audience to bto cc bcc aud)
<> "audience" .=% aud <> "audience" .=% aud
where where
t .=% v = t .=% v =
if V.null v if null v
then mempty then mempty
else t .= v else t .= v