summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-06-26 03:56:41 -0400
committerjoe <joe@jerkface.net>2013-06-26 03:56:41 -0400
commit3cd15d1fd7fc1a06f850830e0f03008e1da49f70 (patch)
tree682d13bfaff6d7daab98eaf6c17f1801b63b360d /Presence
parentdbd78810ee46bd815ae7f2c9791883a79009436a (diff)
Send offline events when a peer goes down.
Diffstat (limited to 'Presence')
-rw-r--r--Presence/XMPPServer.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index 3684925a..3413dcfb 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -481,12 +481,17 @@ startPeer session_factory sock st = do
481 let h = hOccursFst st :: Handle 481 let h = hOccursFst st :: Handle
482 name <- fmap bshow $ getPeerName sock 482 name <- fmap bshow $ getPeerName sock
483 L.putStrLn $ "IN peer: connected " <++> name 483 L.putStrLn $ "IN peer: connected " <++> name
484 let quit = L.putStrLn $ "IN peer: disconnected " <++> name 484 jids <- newTVarIO Set.empty
485 session <- newSession session_factory sock h 485 session <- newSession session_factory sock h
486 return ( session .*. ConnectionFinalizer quit .*. st ) 486 let quit = do
487 L.putStrLn $ "IN peer: disconnected " <++> name
488 js <- fmap Set.toList (readTVarIO jids)
489 let offline jid = Presence jid Offline
490 forM_ js $ announcePresence session . offline
491 return ( (session,jids) .*. ConnectionFinalizer quit .*. st )
487 492
488doPeer st elem cont = do 493doPeer st elem cont = do
489 let session = hHead st 494 let (session,jids) = hHead st
490 L.putStrLn $ "IN peer: " <++> bshow elem 495 L.putStrLn $ "IN peer: " <++> bshow elem
491 case elem of 496 case elem of
492 Element e@(Elem (N "presence") attrs content) -> do 497 Element e@(Elem (N "presence") attrs content) -> do
@@ -497,10 +502,13 @@ doPeer st elem cont = do
497 L.putStrLn $ "IN peer: PRESENCE! Offline jid=" <++> jid 502 L.putStrLn $ "IN peer: PRESENCE! Offline jid=" <++> jid
498 -- parseAddressJID -- convert peer reported user@address to JID data structure 503 -- parseAddressJID -- convert peer reported user@address to JID data structure
499 peer_jid <- parseAddressJID jid 504 peer_jid <- parseAddressJID jid
505 atomically $ do
506 jids_ <- readTVar jids
507 writeTVar jids (Set.delete peer_jid jids_)
500 announcePresence session (Presence peer_jid Offline) 508 announcePresence session (Presence peer_jid Offline)
501 (Just jid,Just typ) -> 509 (Just jid,Just typ) ->
502 -- possible probe, ignored for now 510 -- possible probe, ignored for now
503 L.putStrLn $ "IN peer: PRESENCE! "<++>typ<++>" jid="<++>jid 511 L.putStrLn $ "IN peer: Ignored presence! "<++>typ<++>" jid="<++>jid
504 (Just jid,Nothing) -> do 512 (Just jid,Nothing) -> do
505 let string (CString _ s _) = [s] 513 let string (CString _ s _) = [s]
506 stat = listToMaybe . Prelude.concatMap string . tagcontent "show" $ content 514 stat = listToMaybe . Prelude.concatMap string . tagcontent "show" $ content
@@ -513,8 +521,11 @@ doPeer st elem cont = do
513 _ -> Available 521 _ -> Available
514 -- Available or Away. 522 -- Available or Away.
515 pjid <- parseAddressJID jid 523 pjid <- parseAddressJID jid
516 names <- getNamesForPeer (peer pjid) 524 -- names <- getNamesForPeer (peer pjid)
517 -- L.putStrLn $ "IN peer: PRESENCE! "<++>bshow (stat,names)<++>" avail/away jid=" <++> jid 525 -- L.putStrLn $ "IN peer: PRESENCE! "<++>bshow (stat,names)<++>" avail/away jid=" <++> jid
526 atomically $ do
527 jids_ <- readTVar jids
528 writeTVar jids (Set.insert pjid jids_)
518 announcePresence session (Presence pjid stat') 529 announcePresence session (Presence pjid stat')
519 L.putStrLn $ "IN peer: " <++> bshow (Presence pjid stat') 530 L.putStrLn $ "IN peer: " <++> bshow (Presence pjid stat')
520 _ -> return () -- putStrLn $ "inbound unhandled: "++show v 531 _ -> return () -- putStrLn $ "inbound unhandled: "++show v