summaryrefslogtreecommitdiff
path: root/Presence/XMPP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/XMPP.hs')
-rw-r--r--Presence/XMPP.hs19
1 files changed, 4 insertions, 15 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 01852f43..9dfee14e 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -478,27 +478,20 @@ handlePeer st src snk = do
478 session_factory = hHead st' 478 session_factory = hHead st'
479 name <- fmap bshow $ getPeerName sock 479 name <- fmap bshow $ getPeerName sock
480 L.putStrLn $ "(P) connected " <++> name 480 L.putStrLn $ "(P) connected " <++> name
481 jids <- newTVarIO Set.empty
482 session <- newSession session_factory sock 481 session <- newSession session_factory sock
483 482
484 finally ( src $= parseBytes def $$ fromPeer (session,jids) ) 483 finally ( src $= parseBytes def $$ fromPeer session )
485 $ do 484 $ do
486 L.putStrLn $ "(P) disconnected " <++> name 485 L.putStrLn $ "(P) disconnected " <++> name
487 js <- fmap Set.toList (readTVarIO jids)
488 let offline jid = Presence jid Offline
489 forM_ js $ announcePresence session . offline
490 closeSession session 486 closeSession session
491 487
492 488
493handlePeerPresence (session,jids) stanza False = do 489handlePeerPresence session stanza False = do
494 -- Offline 490 -- Offline
495 withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do 491 withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do
496 peer_jid <- liftIO $ parseAddressJID (L.fromChunks [S.encodeUtf8 jid]) 492 peer_jid <- liftIO $ parseAddressJID (L.fromChunks [S.encodeUtf8 jid])
497 liftIO . atomically $ do
498 jids_ <- readTVar jids
499 writeTVar jids (Set.delete peer_jid jids_)
500 liftIO $ announcePresence session (Presence peer_jid Offline) 493 liftIO $ announcePresence session (Presence peer_jid Offline)
501handlePeerPresence (session,jids) stanza True = do 494handlePeerPresence session stanza True = do
502 -- online (Available or Away) 495 -- online (Available or Away)
503 let log = liftIO . L.putStrLn . ("(P) " <++>) 496 let log = liftIO . L.putStrLn . ("(P) " <++>)
504 withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do 497 withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do
@@ -517,10 +510,6 @@ handlePeerPresence (session,jids) stanza True = do
517 toStat "chat" = Available 510 toStat "chat" = Available
518 511
519 stat' <- parseChildren Available 512 stat' <- parseChildren Available
520
521 liftIO . atomically $ do
522 jids_ <- readTVar jids
523 writeTVar jids (Set.insert pjid jids_)
524 liftIO $ announcePresence session (Presence pjid stat') 513 liftIO $ announcePresence session (Presence pjid stat')
525 log $ bshow (Presence pjid stat') 514 log $ bshow (Presence pjid stat')
526 515
@@ -546,7 +535,7 @@ isPresenceOf (EventBeginElement name attrs) testType
546isPresenceOf _ _ = False 535isPresenceOf _ _ = False
547 536
548fromPeer :: (MonadThrow m,MonadIO m, XMPPSession session) => 537fromPeer :: (MonadThrow m,MonadIO m, XMPPSession session) =>
549 (session, TVar (Set JID)) -> Sink XML.Event m () 538 session -> Sink XML.Event m ()
550fromPeer session = doNestingXML $ do 539fromPeer session = doNestingXML $ do
551 let log = liftIO . L.putStrLn . ("(P) " <++>) 540 let log = liftIO . L.putStrLn . ("(P) " <++>)
552 withXML $ \begindoc -> do 541 withXML $ \begindoc -> do