Skip to content

Commit dcfd64a

Browse files
Merge pull request softwarefactory-project#23 from TristanCacqueray/aeson2
Support aeson-2.0
2 parents 109b6e4 + 9007037 commit dcfd64a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

matrix-client/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.1.4.1
4+
5+
- Support aeson-2.0
6+
37
## 0.1.4.0
48

59
- Completes The Room API

matrix-client/matrix-client.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ source-repository head
3131
common common-options
3232
build-depends: base >= 4.11.0.0 && < 5
3333
, aeson-casing >= 0.2.0.0 && < 0.3.0.0
34-
, aeson >= 1.0.0.0 && < 1.6
34+
, aeson >= 1.0.0.0 && < 2.1
3535
ghc-options: -Wall
3636
-Wcompat
3737
-Widentities

matrix-client/src/Network/Matrix/Identity.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE OverloadedStrings #-}
23
{-# LANGUAGE RecordWildCards #-}
34

@@ -40,6 +41,9 @@ import Data.Aeson (FromJSON (..), Value (Object, String), encode, object, (.:),
4041
import Data.ByteString.Lazy (fromStrict)
4142
import Data.ByteString.Lazy.Base64.URL (encodeBase64Unpadded)
4243
import Data.Digest.Pure.SHA (bytestringDigest, sha256)
44+
#if MIN_VERSION_aeson(2,0,0)
45+
import qualified Data.Aeson.KeyMap as KeyMap
46+
#endif
4347
import qualified Data.HashMap.Strict as HM
4448
import Data.List (lookup)
4549
import Data.List.NonEmpty (NonEmpty)
@@ -50,6 +54,14 @@ import Data.Text.Lazy (toStrict)
5054
import qualified Network.HTTP.Client as HTTP
5155
import 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

Comments
 (0)