Skip to content

Commit a66163d

Browse files
authored
agent: additional short link types and encodings (#1509)
1 parent bdf8bf0 commit a66163d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Simplex/Messaging/Agent/Protocol.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
{-# LANGUAGE TypeFamilies #-}
2222
{-# LANGUAGE UndecidableInstances #-}
2323
{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
24+
{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-}
2425

2526
-- |
2627
-- Module : Simplex.Messaging.Agent.Protocol
@@ -117,6 +118,7 @@ module Simplex.Messaging.Agent.Protocol
117118
ConnShortLink (..),
118119
AConnShortLink (..),
119120
CreatedConnLink (..),
121+
ACreatedConnLink (..),
120122
ContactConnType (..),
121123
ShortLinkScheme (..),
122124
LinkKey (..),
@@ -164,8 +166,9 @@ module Simplex.Messaging.Agent.Protocol
164166
where
165167

166168
import Control.Applicative (optional, (<|>))
167-
import Data.Aeson (FromJSON (..), ToJSON (..))
169+
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), (.:), (.:?))
168170
import qualified Data.Aeson.TH as J
171+
import qualified Data.Aeson.Types as JT
169172
import Data.Attoparsec.ByteString.Char8 (Parser)
170173
import qualified Data.Attoparsec.ByteString.Char8 as A
171174
import qualified Data.ByteString.Base64.URL as B64
@@ -1404,6 +1407,10 @@ data ConnectionLink m = CLFull (ConnectionRequestUri m) | CLShort (ConnShortLink
14041407
data CreatedConnLink m = CCLink {connFullLink :: ConnectionRequestUri m, connShortLink :: Maybe (ConnShortLink m)}
14051408
deriving (Eq, Show)
14061409

1410+
data ACreatedConnLink = forall m. ConnectionModeI m => ACCL (SConnectionMode m) (CreatedConnLink m)
1411+
1412+
deriving instance Show ACreatedConnLink
1413+
14071414
data AConnectionLink = forall m. ConnectionModeI m => ACL (SConnectionMode m) (ConnectionLink m)
14081415

14091416
deriving instance Show AConnectionLink
@@ -1911,3 +1918,15 @@ instance ConnectionModeI m => FromJSON (CreatedConnLink m) where
19111918
instance ConnectionModeI m => ToJSON (CreatedConnLink m) where
19121919
toEncoding = $(J.mkToEncoding defaultJSON ''CreatedConnLink)
19131920
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

Comments
 (0)