|
21 | 21 | {-# LANGUAGE TypeFamilies #-} |
22 | 22 | {-# LANGUAGE UndecidableInstances #-} |
23 | 23 | {-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-} |
| 24 | +{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-} |
24 | 25 |
|
25 | 26 | -- | |
26 | 27 | -- Module : Simplex.Messaging.Agent.Protocol |
@@ -117,6 +118,7 @@ module Simplex.Messaging.Agent.Protocol |
117 | 118 | ConnShortLink (..), |
118 | 119 | AConnShortLink (..), |
119 | 120 | CreatedConnLink (..), |
| 121 | + ACreatedConnLink (..), |
120 | 122 | ContactConnType (..), |
121 | 123 | ShortLinkScheme (..), |
122 | 124 | LinkKey (..), |
@@ -164,8 +166,9 @@ module Simplex.Messaging.Agent.Protocol |
164 | 166 | where |
165 | 167 |
|
166 | 168 | import Control.Applicative (optional, (<|>)) |
167 | | -import Data.Aeson (FromJSON (..), ToJSON (..)) |
| 169 | +import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), (.:), (.:?)) |
168 | 170 | import qualified Data.Aeson.TH as J |
| 171 | +import qualified Data.Aeson.Types as JT |
169 | 172 | import Data.Attoparsec.ByteString.Char8 (Parser) |
170 | 173 | import qualified Data.Attoparsec.ByteString.Char8 as A |
171 | 174 | import qualified Data.ByteString.Base64.URL as B64 |
@@ -1404,6 +1407,10 @@ data ConnectionLink m = CLFull (ConnectionRequestUri m) | CLShort (ConnShortLink |
1404 | 1407 | data CreatedConnLink m = CCLink {connFullLink :: ConnectionRequestUri m, connShortLink :: Maybe (ConnShortLink m)} |
1405 | 1408 | deriving (Eq, Show) |
1406 | 1409 |
|
| 1410 | +data ACreatedConnLink = forall m. ConnectionModeI m => ACCL (SConnectionMode m) (CreatedConnLink m) |
| 1411 | + |
| 1412 | +deriving instance Show ACreatedConnLink |
| 1413 | + |
1407 | 1414 | data AConnectionLink = forall m. ConnectionModeI m => ACL (SConnectionMode m) (ConnectionLink m) |
1408 | 1415 |
|
1409 | 1416 | deriving instance Show AConnectionLink |
@@ -1911,3 +1918,15 @@ instance ConnectionModeI m => FromJSON (CreatedConnLink m) where |
1911 | 1918 | instance ConnectionModeI m => ToJSON (CreatedConnLink m) where |
1912 | 1919 | toEncoding = $(J.mkToEncoding defaultJSON ''CreatedConnLink) |
1913 | 1920 | toJSON = $(J.mkToJSON defaultJSON ''CreatedConnLink) |
| 1921 | + |
| 1922 | +instance FromJSON ACreatedConnLink where |
| 1923 | + parseJSON (Object v) = do |
| 1924 | + ACR m cReq <- v .: "connFullLink" |
| 1925 | + shortLink <- v .:? "connShortLink" |
| 1926 | + pure $ ACCL m $ CCLink cReq shortLink |
| 1927 | + parseJSON invalid = |
| 1928 | + JT.prependFailure "bad ACreatedConnLink, " (JT.typeMismatch "Object" invalid) |
| 1929 | + |
| 1930 | +instance ToJSON ACreatedConnLink where |
| 1931 | + toEncoding (ACCL _ ccLink) = toEncoding ccLink |
| 1932 | + toJSON (ACCL _ ccLink) = toJSON ccLink |
0 commit comments