diff options
Diffstat (limited to 'ToxToXMPP.hs')
-rw-r--r-- | ToxToXMPP.hs | 25 |
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 | |||
7 | import Data.XML.Types as XML | 7 | import Data.XML.Types as XML |
8 | import Network.Tox.Crypto.Transport as Tox | 8 | import Network.Tox.Crypto.Transport as Tox |
9 | import XMPPServer as XMPP | 9 | import XMPPServer as XMPP |
10 | import EventUtil | ||
10 | 11 | ||
11 | import ClientState | 12 | import ClientState |
12 | import Control.Concurrent.STM | 13 | import Control.Concurrent.STM |
@@ -36,10 +37,30 @@ xmppToTox :: Conduit XML.Event IO Tox.CryptoMessage | |||
36 | xmppToTox = do | 37 | xmppToTox = do |
37 | awaitForever (\_ -> return ()) | 38 | awaitForever (\_ -> return ()) |
38 | 39 | ||
39 | toxToXmpp :: Text -> Conduit Tox.CryptoMessage IO XML.Event | 40 | toxToXmpp :: Monad m => Text -> Conduit Tox.CryptoMessage m XML.Event |
40 | toxToXmpp toxhost = do | 41 | toxToXmpp 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 | |||
46 | xmppInstantMessage :: Monad m => Text -> Maybe Text -> Text -> ConduitM i Event m () | ||
47 | xmppInstantMessage 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 | ||
44 | key2jid :: Word32 -> PublicKey -> Text | 65 | key2jid :: Word32 -> PublicKey -> Text |
45 | key2jid nospam key = T.pack $ show $ NoSpamId nsp key | 66 | key2jid nospam key = T.pack $ show $ NoSpamId nsp key |