summaryrefslogtreecommitdiff
path: root/ToxToXMPP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ToxToXMPP.hs')
-rw-r--r--ToxToXMPP.hs25
1 files changed, 23 insertions, 2 deletions
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index eec04846..acd1e45b 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -7,6 +7,7 @@ import qualified Data.Conduit.List as CL
7import Data.XML.Types as XML 7import Data.XML.Types as XML
8import Network.Tox.Crypto.Transport as Tox 8import Network.Tox.Crypto.Transport as Tox
9import XMPPServer as XMPP 9import XMPPServer as XMPP
10import EventUtil
10 11
11import ClientState 12import ClientState
12import Control.Concurrent.STM 13import Control.Concurrent.STM
@@ -36,10 +37,30 @@ xmppToTox :: Conduit XML.Event IO Tox.CryptoMessage
36xmppToTox = do 37xmppToTox = do
37 awaitForever (\_ -> return ()) 38 awaitForever (\_ -> return ())
38 39
39toxToXmpp :: Text -> Conduit Tox.CryptoMessage IO XML.Event 40toxToXmpp :: Monad m => Text -> Conduit Tox.CryptoMessage m XML.Event
40toxToXmpp toxhost = do 41toxToXmpp toxhost = do
41 CL.sourceList $ XMPP.greet' "jabber:server" toxhost 42 CL.sourceList $ XMPP.greet' "jabber:server" toxhost
42 awaitForever (\_ -> return ()) 43 awaitForever $ \toxmsg -> do
44 xmppInstantMessage "jabber:server" (Just toxhost) (T.pack $ show $ msgID toxmsg)
45
46xmppInstantMessage :: Monad m => Text -> Maybe Text -> Text -> ConduitM i Event m ()
47xmppInstantMessage namespace mfrom text = do
48 let ns n = n { nameNamespace = Just namespace }
49 C.yield $ EventBeginElement (ns "message")
50 ((maybe id (\t->(attr "from" t:)) mfrom)
51 [attr "type" "normal" ])
52 C.yield $ EventBeginElement (ns "body") []
53 C.yield $ EventContent $ ContentText text
54 C.yield $ EventEndElement (ns "body")
55 C.yield $ EventBeginElement "{http://jabber.org/protocol/xhtml-im}html" []
56 C.yield $ EventBeginElement "{http://www.w3.org/1999/xhtml}body" []
57 C.yield $ EventBeginElement "{http://www.w3.org/1999/xhtml}p"
58 [ attr "style" "font-weight:bold; color:red" ]
59 C.yield $ EventContent $ ContentText text
60 C.yield $ EventEndElement "{http://www.w3.org/1999/xhtml}p"
61 C.yield $ EventEndElement "{http://www.w3.org/1999/xhtml}body"
62 C.yield $ EventEndElement "{http://jabber.org/protocol/xhtml-im}html"
63 C.yield $ EventEndElement (ns "message")
43 64
44key2jid :: Word32 -> PublicKey -> Text 65key2jid :: Word32 -> PublicKey -> Text
45key2jid nospam key = T.pack $ show $ NoSpamId nsp key 66key2jid nospam key = T.pack $ show $ NoSpamId nsp key