update chat protocol to use JSON encoding for chat messages (#182)
* started chat protocol * text message example * events json * same style comments * jsonc * num for rendering * try to fix comment rendering * revert num * chat protocol: make msg params closer to types * AppMessage type * combine new and old simplexmq dependencies * json parsers * version-compatible types for connection requests * more parsers * remove import * decode/encode from/to AppMessage * make group invitation a property in params * switch chat to the new agent * remove "compatibility" attempt * new JSON encoding for chat messages * simplexmq from github * update MsgContent name Co-authored-by: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
44845ad563
commit
be537f3a24
@@ -1,47 +1,44 @@
|
||||
{-# LANGUAGE OverloadedLists #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
-- {-# LANGUAGE OverloadedLists #-}
|
||||
-- {-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module ProtocolTests where
|
||||
|
||||
import Data.ByteString.Char8 (ByteString)
|
||||
import Simplex.Chat.Protocol
|
||||
import Simplex.Messaging.Parsers (parseAll)
|
||||
import Test.Hspec
|
||||
-- import Data.ByteString.Char8 (ByteString)
|
||||
-- import Simplex.Chat.Protocol.Legacy
|
||||
-- import Simplex.Messaging.Parsers (parseAll)
|
||||
-- import Test.Hspec
|
||||
|
||||
protocolTests :: Spec
|
||||
protocolTests = do
|
||||
parseChatMessageTest
|
||||
-- protocolTests :: Spec
|
||||
-- protocolTests = do
|
||||
-- parseChatMessageTest
|
||||
|
||||
(#==) :: ByteString -> RawChatMessage -> Expectation
|
||||
s #== msg = parseAll rawChatMessageP s `shouldBe` Right msg
|
||||
-- (#==) :: ByteString -> RawChatMessage -> Expectation
|
||||
-- s #== msg = parseAll rawChatMessageP s `shouldBe` Right msg
|
||||
|
||||
parseChatMessageTest :: Spec
|
||||
parseChatMessageTest = describe "Raw chat message format" $ do
|
||||
it "no parameters and content" $
|
||||
"5 x.grp.mem.leave " #== RawChatMessage (Just 5) "x.grp.mem.leave" [] []
|
||||
it "one parameter, no content" $
|
||||
"6 x.msg.del 3 " #== RawChatMessage (Just 6) "x.msg.del" ["3"] []
|
||||
it "with content that fits the message" $
|
||||
"7 x.msg.new c.text x.text:11 hello there "
|
||||
#== RawChatMessage
|
||||
(Just 7)
|
||||
"x.msg.new"
|
||||
["c.text"]
|
||||
[RawMsgBodyContent (RawContentType "x" "text") "hello there"]
|
||||
it "with DAG reference and partial content" $
|
||||
"8 x.msg.new c.image x.dag:16,x.text:7,m.image/jpg:6 0123456789012345 picture abcdef "
|
||||
#== RawChatMessage
|
||||
(Just 8)
|
||||
"x.msg.new"
|
||||
["c.image"]
|
||||
[ RawMsgBodyContent (RawContentType "x" "dag") "0123456789012345",
|
||||
RawMsgBodyContent (RawContentType "x" "text") "picture",
|
||||
RawMsgBodyContent (RawContentType "m" "image/jpg") "abcdef"
|
||||
]
|
||||
it "without message id" $
|
||||
" x.grp.mem.inv 23456,123 x.json:46 {\"contactRef\":\"john\",\"displayName\":\"John Doe\"} "
|
||||
#== RawChatMessage
|
||||
Nothing
|
||||
"x.grp.mem.inv"
|
||||
["23456", "123"]
|
||||
[RawMsgBodyContent (RawContentType "x" "json") "{\"contactRef\":\"john\",\"displayName\":\"John Doe\"}"]
|
||||
-- parseChatMessageTest :: Spec
|
||||
-- parseChatMessageTest = describe "Raw chat message format" $ do
|
||||
-- it "no parameters and content" $
|
||||
-- "5 x.grp.mem.leave " #== RawChatMessage "x.grp.mem.leave" [] []
|
||||
-- it "one parameter, no content" $
|
||||
-- "6 x.msg.del 3 " #== RawChatMessage "x.msg.del" ["3"] []
|
||||
-- it "with content that fits the message" $
|
||||
-- "7 x.msg.new c.text x.text:11 hello there "
|
||||
-- #== RawChatMessage
|
||||
-- "x.msg.new"
|
||||
-- ["c.text"]
|
||||
-- [RawMsgBodyContent (RawContentType "x" "text") "hello there"]
|
||||
-- it "with DAG reference and partial content" $
|
||||
-- "8 x.msg.new c.image x.dag:16,x.text:7,m.image/jpg:6 0123456789012345 picture abcdef "
|
||||
-- #== RawChatMessage
|
||||
-- "x.msg.new"
|
||||
-- ["c.image"]
|
||||
-- [ RawMsgBodyContent (RawContentType "x" "dag") "0123456789012345",
|
||||
-- RawMsgBodyContent (RawContentType "x" "text") "picture",
|
||||
-- RawMsgBodyContent (RawContentType "m" "image/jpg") "abcdef"
|
||||
-- ]
|
||||
-- it "without message id" $
|
||||
-- " x.grp.mem.inv 23456,123 x.json:46 {\"contactRef\":\"john\",\"displayName\":\"John Doe\"} "
|
||||
-- #== RawChatMessage
|
||||
-- "x.grp.mem.inv"
|
||||
-- ["23456", "123"]
|
||||
-- [RawMsgBodyContent (RawContentType "x" "json") "{\"contactRef\":\"john\",\"displayName\":\"John Doe\"}"]
|
||||
|
||||
Reference in New Issue
Block a user