summaryrefslogtreecommitdiff
path: root/Presence/XMPP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/XMPP.hs')
-rw-r--r--Presence/XMPP.hs24
1 files changed, 13 insertions, 11 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 89fd420f..3c68da4a 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -578,14 +578,14 @@ seekRemotePeers config chan = do
578 return () 578 return ()
579-} 579-}
580 580
581data OutBoundMessage = OutBoundPresence Presence | PresenceProbe JID 581data OutBoundMessage = OutBoundPresence Presence | PresenceProbe JID JID
582 deriving Prelude.Show 582 deriving Prelude.Show
583 583
584newServerConnections = newTVar Map.empty 584newServerConnections = newTVar Map.empty
585 585
586data CachedMessages = CachedMessages 586data CachedMessages = CachedMessages
587 { presences :: Map JID JabberShow 587 { presences :: Map JID JabberShow
588 , probes :: Set JID 588 , probes :: Map JID (Set JID)
589 } 589 }
590 590
591connect_to_server chan peer = (>> return ()) . runMaybeT $ do 591connect_to_server chan peer = (>> return ()) . runMaybeT $ do
@@ -595,7 +595,7 @@ connect_to_server chan peer = (>> return ()) . runMaybeT $ do
595 595
596 -- We'll cache Presence notifications until the socket 596 -- We'll cache Presence notifications until the socket
597 -- is ready. 597 -- is ready.
598 cached <- liftIO $ newIORef (CachedMessages Map.empty Set.empty) 598 cached <- liftIO $ newIORef (CachedMessages Map.empty Map.empty)
599 599
600 sock <- MaybeT . fix $ \loop -> do 600 sock <- MaybeT . fix $ \loop -> do
601 e <- atomically $ orElse 601 e <- atomically $ orElse
@@ -610,9 +610,10 @@ connect_to_server chan peer = (>> return ()) . runMaybeT $ do
610 cache <- readIORef cached 610 cache <- readIORef cached
611 writeIORef cached (cache { presences=Map.insert jid st . presences $ cache }) 611 writeIORef cached (cache { presences=Map.insert jid st . presences $ cache })
612 loop 612 loop
613 Left (PresenceProbe jid) -> do 613 Left (PresenceProbe from to) -> do
614 cache <- readIORef cached 614 cache <- readIORef cached
615 writeIORef cached (cache { probes=Set.insert jid . probes $ cache }) 615 let probes' = Map.adjust (Set.insert from) to $ probes cache
616 writeIORef cached (cache { probes=probes' })
616 loop 617 loop
617 {- 618 {-
618 Left event -> do 619 Left event -> do
@@ -627,7 +628,7 @@ connect_to_server chan peer = (>> return ()) . runMaybeT $ do
627 let snk = packetSink h 628 let snk = packetSink h
628 cache <- readIORef $ cached 629 cache <- readIORef $ cached
629 -- hint garbage collector: we're done with this... 630 -- hint garbage collector: we're done with this...
630 writeIORef cached (CachedMessages Map.empty Set.empty) 631 writeIORef cached (CachedMessages Map.empty Map.empty)
631 handleOutgoingToPeer (restrictSocket sock) cache chan snk 632 handleOutgoingToPeer (restrictSocket sock) cache chan snk
632 633
633 634
@@ -651,18 +652,19 @@ toPeer sock cache chan = do
651 forM_ (Map.assocs . presences $ cache) $ \(jid,st) -> do 652 forM_ (Map.assocs . presences $ cache) $ \(jid,st) -> do
652 r <- lift $ xmlifyPresenceForPeer sock (Presence jid st) 653 r <- lift $ xmlifyPresenceForPeer sock (Presence jid st)
653 send r 654 send r
654 forM_ (Set.toList . probes $ cache) $ \jid -> do 655 forM_ (Map.assocs . probes $ cache) $ \(to,froms) -> do
655 -- TODO: send probe 656 forM_ (Set.toList froms) $ \from ->
656 return () 657 -- TODO: send probe
658 return ()
657 fix $ \loop -> do 659 fix $ \loop -> do
658 event <- lift . atomically $ readTChan chan 660 event <- lift . atomically $ readTChan chan
659 case event of 661 case event of
660 OutBoundPresence p -> do 662 OutBoundPresence p -> do
661 r <- lift $ xmlifyPresenceForPeer sock p 663 r <- lift $ xmlifyPresenceForPeer sock p
662 send r 664 send r
663 PresenceProbe jid -> do 665 PresenceProbe from to -> do
664 -- TODO: send probe 666 -- TODO: send probe
665 liftIO $ putStrLn ("Connection ready, PresenceProbe " ++ show jid ++ " (NOT IMPLEMENTED)") 667 liftIO $ putStrLn ("Connection ready, PresenceProbe " ++ show (from,to) ++ " (NOT IMPLEMENTED)")
666 loop 668 loop
667 send goodbyePeer 669 send goodbyePeer
668 670