From fe905494c23a56cc21afd702381486de5d892cf8 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Tue, 29 May 2018 00:42:44 +0000 Subject: more session commands --- src/Network/Tox/Crypto/Handlers.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Network/Tox/Crypto') diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 92cb19b8..2902685c 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -806,6 +806,19 @@ setStatusMsg crypto session msg = do addMsgToLastN False (cm ^. messageType) session (Out cm) sendCrypto crypto session updateLocal cm +sendChatMsg :: TransportCrypto -> NetCryptoSession -> ByteString -> IO (Either String ()) +sendChatMsg crypto session msg = do + let Just (_,maxlen) = msgSizeParam MESSAGE + if B.length msg > maxlen + then return (Left $ "status message must not exceed " ++ show maxlen ++ " bytes.") + else do + let updateLocal = do + view <- readTVar (ncView session) + writeTVar (svStatusMsg view) msg + let cm = UpToN MESSAGE msg + addMsgToLastN False (cm ^. messageType) session (Out cm) + sendCrypto crypto session updateLocal cm + -- | handles nothings defaultCryptoDataHooks :: Map.Map MessageType [NetCryptoHook] defaultCryptoDataHooks -- cgit v1.2.3