From f99bcf0fd196d0ea075be76b4fce3d9713d193f3 Mon Sep 17 00:00:00 2001 From: Philipp Balzarek Date: Wed, 17 Sep 2014 15:57:49 +0200 Subject: [PATCH] pass JID to onPresenceChange callback --- source/Network/Xmpp/Concurrent/Types.hs | 10 +++++++++- source/Network/Xmpp/IM/PresenceTracker.hs | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/source/Network/Xmpp/Concurrent/Types.hs b/source/Network/Xmpp/Concurrent/Types.hs index 4085150..92ea47e 100644 --- a/source/Network/Xmpp/Concurrent/Types.hs +++ b/source/Network/Xmpp/Concurrent/Types.hs @@ -87,7 +87,15 @@ data SessionConfiguration = SessionConfiguration , enableRoster :: Bool -- | Track incomming presence stancas. , enablePresenceTracking :: Bool - , onPresenceChange :: Maybe (PeerStatus -> PeerStatus -> IO ()) + -- | Callback that is invoked when the presence status of a peer changes, + -- i.e. it comes online, goes offline or its IM presence changes. The + -- arguments are the (full) JID of the peer, the old state and the new + -- state. The function is called in a new thread to avoid blocking + -- handling stanzas + , onPresenceChange :: Maybe ( Jid + -> PeerStatus + -> PeerStatus + -> IO ()) } instance Default SessionConfiguration where diff --git a/source/Network/Xmpp/IM/PresenceTracker.hs b/source/Network/Xmpp/IM/PresenceTracker.hs index c4ff0ad..5e4cd1b 100644 --- a/source/Network/Xmpp/IM/PresenceTracker.hs +++ b/source/Network/Xmpp/IM/PresenceTracker.hs @@ -59,7 +59,7 @@ peerMapPeerAvailable :: Jid -> Peers -> Bool peerMapPeerAvailable j | isFull j = not . nullOf (peerStatusL j . _PeerAvailable) | otherwise = not . nullOf (_peers . at j . _Just) -handlePresence :: Maybe (PeerStatus -> PeerStatus -> IO ()) +handlePresence :: Maybe (Jid -> PeerStatus -> PeerStatus -> IO ()) -> TVar Peers -> StanzaHandler handlePresence onChange peers _ st _ = do @@ -82,7 +82,7 @@ handlePresence onChange peers _ st _ = do return oldStatus unless (os == newStatus) $ case onChange of Nothing -> return () - Just oc -> void . forkIO $ oc os newStatus + Just oc -> void . forkIO $ oc fr os newStatus return () -- | Check whether a given jid is available