summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-06-19 01:55:04 -0400
committerjoe <joe@jerkface.net>2013-06-19 01:55:04 -0400
commit4322ba246f8276e82fb0538c40e0c41d584fa6b2 (patch)
treecf6abfdca6a1b2491f947a821aa7b6c75846b141 /Presence
parent4bbc8d6475589469976698925162982f5633970e (diff)
xml presence notifications now sent to client.
Diffstat (limited to 'Presence')
-rw-r--r--Presence/XMPPServer.hs21
1 files changed, 19 insertions, 2 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index 192e9d47..660853b6 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -68,6 +68,18 @@ data JabberShow = Offline
68data Presence = Presence JID JabberShow 68data Presence = Presence JID JabberShow
69 deriving Show 69 deriving Show
70 70
71xmlifyPresence (Presence jid stat) = L.unlines
72 [ "<presence from='" <++> bshow jid <++> "' " <++> typ stat <++> ">"
73 , "<show>" <++> shw stat <++> "</show>"
74 , "</presence>"
75 ]
76 where
77 typ Offline = " type='unavailable'"
78 typ _ = ""
79 shw Available = "chat"
80 shw Away = "away"
81 shw Offline = "away" -- Is this right?
82
71instance NFData Presence where 83instance NFData Presence where
72 rnf (Presence jid stat) = rnf jid `seq` stat `seq` () 84 rnf (Presence jid stat) = rnf jid `seq` stat `seq` ()
73 85
@@ -114,15 +126,20 @@ startCon session_factory sock st = do
114 pchan <- subscribe session Nothing 126 pchan <- subscribe session Nothing
115 cmdChan <- atomically newTChan 127 cmdChan <- atomically newTChan
116 reader <- forkIO $ 128 reader <- forkIO $
117 handle (\(SomeException _) -> L.putStrLn "quit reader.") $ 129 handle (\(SomeException _) -> L.putStrLn "quit reader via exception.") $
118 fix $ \loop -> do 130 fix $ \loop -> do
119 event <- atomically $ 131 event <- atomically $
120 (fmap Left $ readTChan pchan) 132 (fmap Left $ readTChan pchan)
121 `orElse` 133 `orElse`
122 (fmap Right $ readTChan cmdChan) 134 (fmap Right $ readTChan cmdChan)
123 case event of 135 case event of
124 Left presence -> 136 Left presence -> do
125 L.putStrLn $ "PRESENCE: " <++> bshow presence 137 L.putStrLn $ "PRESENCE: " <++> bshow presence
138 -- TODO: it violates spec to send presence information before
139 -- a resource is bound.
140 let r = xmlifyPresence presence
141 hPutStrLn h r
142 L.putStrLn $ "\nOUT:\n" <++> r
126 Right (Send r) -> 143 Right (Send r) ->
127 hPutStrLn h r 144 hPutStrLn h r
128 loop 145 loop