From 08c02ea307d056a2825d51699e1f2e111d41a7f0 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Mon, 30 Oct 2017 01:35:12 +0000 Subject: allow messageData to get peerinfos --- src/Network/Tox/Crypto/Transport.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Network/Tox') diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs index 4b2e97ce..5b9a0661 100644 --- a/src/Network/Tox/Crypto/Transport.hs +++ b/src/Network/Tox/Crypto/Transport.hs @@ -402,12 +402,17 @@ class HasMessageData x where instance HasMessageData CryptoMessage where getMessageData (UpToN (fromEnum -> 0x63) (sizedAtLeastN 9 -> B.splitAt 9 -> (_,mdata))) = mdata getMessageData (UpToN (fromEnum -> 0xC7) (sizedAtLeastN 9 -> B.splitAt 9 -> (_,mdata))) = mdata + getMessageData (UpToN (fromEnum -> 0x62) (sizedAtLeastN 3 -> B.splitAt 2 -> (_,B.uncons -> Just (0x09,peerinfos)))) = peerinfos + -- getMessageData on 0x62:0a is equivalent to getTitle but without decoding the utf8 + getMessageData (UpToN (fromEnum -> 0x62) (sizedAtLeastN 3 -> B.splitAt 2 -> (_,B.uncons -> Just (0x0a,title)))) = title getMessageData _ = error "getMessageData on CryptoMessage without message data field." setMessageData (UpToN xE@(fromEnum -> 0x63) (sizedAtLeastN 9 -> B.splitAt 9 -> (bs,xs))) messagedata -- MESSAGE_GROUPCHAT = UpToN xE (B.concat [bs,messagedata]) setMessageData (UpToN xE@(fromEnum -> 0xC7) (sizedAtLeastN 9 -> B.splitAt 9 -> (bs,xs))) messagedata -- LOSSY_GROUPCHAT = UpToN xE (B.concat [bs,messagedata]) + setMessageData (UpToN xE@(fromEnum -> 0x62) (sizedAtLeastN 3 -> B.splitAt 3 -> (bs,xs))) peerinfosOrTitle -- peer/title response packets + = UpToN xE (B.concat [bs,peerinfosOrTitle]) setMessageData _ _ = error "setMessageData on CryptoMessage without message data field." messageData :: (Functor f, HasMessageData x) => (MessageData -> f MessageData) -> (x -> f x) @@ -418,14 +423,14 @@ class HasTitle x where setTitle :: x -> Text -> x instance HasTitle CryptoMessage where - getTitle (UpToN DIRECT_GROUPCHAT {-Ox62-} (sizedAtLeastN 4 -> B.splitAt 3 -> (_,B.uncons -> Just (0x0a,mdata)))) = decodeUtf8 mdata - getTitle (UpToN xE (sizedAtLeastN 4 -> B.splitAt 3 -> (_,B.uncons -> Just (toEnum . fromIntegral -> GroupchatTitleChange,mdata)))) + getTitle (UpToN DIRECT_GROUPCHAT {-Ox62-} (sizedAtLeastN 3 -> B.splitAt 2 -> (_,B.uncons -> Just (0x0a,mdata)))) = decodeUtf8 mdata + getTitle (UpToN xE (sizedAtLeastN 9 -> B.splitAt 8 -> (_,B.uncons -> Just (toEnum . fromIntegral -> GroupchatTitleChange,mdata)))) | isIndirectGrpChat xE = decodeUtf8 mdata getTitle _ = error "getTitle on CryptoMessage without title field." - setTitle (UpToN xE@DIRECT_GROUPCHAT {-0x62-} (sizedAtLeastN 4 -> B.splitAt 3 -> (bs,B.uncons -> Just (_,xs)))) messagedata + setTitle (UpToN xE@DIRECT_GROUPCHAT {-0x62-} (sizedAtLeastN 3 -> B.splitAt 2 -> (bs,B.uncons -> Just (_,xs)))) messagedata = UpToN xE (B.concat [bs,B.cons 0x0a (encodeUtf8 messagedata)]) - setTitle (UpToN xE (sizedAtLeastN 4 -> B.splitAt 3 -> (bs,B.uncons -> Just (_,xs)))) title + setTitle (UpToN xE (sizedAtLeastN 9 -> B.splitAt 8 -> (bs,B.uncons -> Just (_,xs)))) title | isIndirectGrpChat xE = UpToN xE (B.concat [bs,B.cons (fromIntegral $ fromEnum GroupchatTitleChange) (encodeUtf8 title)]) setTitle _ _ = error "setTitle on CryptoMessage without title field." -- cgit v1.2.3