1+ {-# LANGUAGE CPP #-}
12{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE RecordWildCards #-}
34
@@ -40,6 +41,9 @@ import Data.Aeson (FromJSON (..), Value (Object, String), encode, object, (.:),
4041import Data.ByteString.Lazy (fromStrict )
4142import Data.ByteString.Lazy.Base64.URL (encodeBase64Unpadded )
4243import Data.Digest.Pure.SHA (bytestringDigest , sha256 )
44+ #if MIN_VERSION_aeson(2,0,0)
45+ import qualified Data.Aeson.KeyMap as KeyMap
46+ #endif
4347import qualified Data.HashMap.Strict as HM
4448import Data.List (lookup )
4549import Data.List.NonEmpty (NonEmpty )
@@ -50,6 +54,14 @@ import Data.Text.Lazy (toStrict)
5054import qualified Network.HTTP.Client as HTTP
5155import Network.Matrix.Internal
5256
57+ #if MIN_VERSION_aeson(2,0,0)
58+ toKVList :: KeyMap. KeyMap v -> [(Text , v )]
59+ toKVList = HM. toList . KeyMap. toHashMapText
60+ #else
61+ toKVList :: HM. HashMap Text v -> [(Text , v )]
62+ toKVList = HM. toList
63+ #endif
64+
5365-- $setup
5466-- >>> import Data.Aeson (decode)
5567
@@ -123,7 +135,7 @@ instance FromJSON IdentityLookupResponse where
123135 parseJSON (Object v) = do
124136 mappings <- v .: " mappings"
125137 case mappings of
126- (Object kv) -> pure . IdentityLookupResponse $ mapMaybe toTuple (HM. toList kv)
138+ (Object kv) -> pure . IdentityLookupResponse $ mapMaybe toTuple (toKVList kv)
127139 _ -> mzero
128140 where
129141 toTuple (k, String s) = Just (HashedAddress k, UserID s)
0 commit comments