diff options
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/XMPP.hs | 5 | ||||
-rw-r--r-- | Presence/XMPPTypes.hs | 3 | ||||
-rw-r--r-- | Presence/main.hs | 17 |
3 files changed, 23 insertions, 2 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs index 6dbc64b0..2c01d456 100644 --- a/Presence/XMPP.hs +++ b/Presence/XMPP.hs | |||
@@ -610,8 +610,10 @@ handlePeer st src snk = do | |||
610 | 610 | ||
611 | handlePeerPresence session stanza False = do | 611 | handlePeerPresence session stanza False = do |
612 | -- Offline | 612 | -- Offline |
613 | liftIO . debugStr $ "PEER-OFFLINE: "++show stanza | ||
613 | withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do | 614 | withJust (lookupAttrib "from" (tagAttrs stanza)) $ \jid -> do |
614 | peer_jid <- liftIO $ parseAddressJID (textToByteString jid) | 615 | peer_jid <- liftIO $ parseAddressJID (textToByteString jid) |
616 | liftIO . debugStr $ "PEER-OFFLINE-JID: "++show peer_jid | ||
615 | liftIO $ announcePresence session (Presence peer_jid Offline) | 617 | liftIO $ announcePresence session (Presence peer_jid Offline) |
616 | handlePeerPresence session stanza True = do | 618 | handlePeerPresence session stanza True = do |
617 | -- online (Available or Away) | 619 | -- online (Available or Away) |
@@ -632,6 +634,7 @@ handlePeerPresence session stanza True = do | |||
632 | toStat "chat" = Available | 634 | toStat "chat" = Available |
633 | 635 | ||
634 | stat' <- parseChildren Available | 636 | stat' <- parseChildren Available |
637 | liftIO . debugStr $ "announcing peer online: "++show (pjid,stat') | ||
635 | liftIO $ announcePresence session (Presence pjid stat') | 638 | liftIO $ announcePresence session (Presence pjid stat') |
636 | log $ bshow (Presence pjid stat') | 639 | log $ bshow (Presence pjid stat') |
637 | 640 | ||
@@ -683,6 +686,8 @@ handlePresenceProbe session stanza = do | |||
683 | when (peer sub == discardPort (peerAddress session)) $ do | 686 | when (peer sub == discardPort (peerAddress session)) $ do |
684 | ps <- userStatus session user | 687 | ps <- userStatus session user |
685 | -- todo: Consider making this a directed presence | 688 | -- todo: Consider making this a directed presence |
689 | forM_ ps $ \p -> do | ||
690 | debugStr ("PROBE-REPLY: "++show p) | ||
686 | mapM_ (sendPeerMessage session . OutBoundPresence) ps | 691 | mapM_ (sendPeerMessage session . OutBoundPresence) ps |
687 | return () | 692 | return () |
688 | 693 | ||
diff --git a/Presence/XMPPTypes.hs b/Presence/XMPPTypes.hs index 84da2fed..8d0bd242 100644 --- a/Presence/XMPPTypes.hs +++ b/Presence/XMPPTypes.hs | |||
@@ -100,6 +100,9 @@ data JabberShow = Offline | |||
100 | | Available | 100 | | Available |
101 | deriving (Prelude.Show,Enum,Ord,Eq,Read) | 101 | deriving (Prelude.Show,Enum,Ord,Eq,Read) |
102 | 102 | ||
103 | withResource (JID n p _) rsc = JID n p rsc | ||
104 | |||
105 | |||
103 | data Presence = Presence JID JabberShow | 106 | data Presence = Presence JID JabberShow |
104 | deriving Prelude.Show | 107 | deriving Prelude.Show |
105 | 108 | ||
diff --git a/Presence/main.hs b/Presence/main.hs index ef6a0e66..dedd546a 100644 --- a/Presence/main.hs +++ b/Presence/main.hs | |||
@@ -227,9 +227,14 @@ instance JabberClientSession ClientSession where | |||
227 | debugL $ "forCachedPresence jids = "<++> bshow jids | 227 | debugL $ "forCachedPresence jids = "<++> bshow jids |
228 | withJust (splitResource buddy) $ \(buddyU,_) -> do | 228 | withJust (splitResource buddy) $ \(buddyU,_) -> do |
229 | forM_ (Set.toList . MM.lookup buddyU $ jids) $ \(rsc,status) -> do | 229 | forM_ (Set.toList . MM.lookup buddyU $ jids) $ \(rsc,status) -> do |
230 | let p = Presence buddy status | 230 | let p = Presence (buddy `withResource` Just rsc) status |
231 | debugL $ "cached presence: " <++> bshow p | 231 | debugL $ "cached presence: " <++> bshow p |
232 | action p | 232 | action p |
233 | -- forCachedPresence jids = MM (fromList | ||
234 | -- [(JabberUser (Chunk "joe" Empty) (RemotePeer [fde3:6df:8be1:81ef:8bae:a0df:9c5d:5]:0) | ||
235 | -- ,fromList [(Chunk "tty7" Empty,Available)])]) | ||
236 | -- cached presence: Presence joe@[fde3:6df:8be1:81ef:8bae:a0df:9c5d:5] Available | ||
237 | |||
233 | 238 | ||
234 | sendPending s = do | 239 | sendPending s = do |
235 | jid <- getJID s | 240 | jid <- getJID s |
@@ -380,9 +385,11 @@ instance JabberPeerSession PeerSession where | |||
380 | let offline jid = Presence jid Offline | 385 | let offline jid = Presence jid Offline |
381 | unrefFromMap (remoteUsers . peer_global $ session) (peer_name session) | 386 | unrefFromMap (remoteUsers . peer_global $ session) (peer_name session) |
382 | $ do | 387 | $ do |
388 | debugStr ("unrefFromMap!") | ||
383 | js <- fmap (MM.toAscList) (readTVarIO . announced $ session) | 389 | js <- fmap (MM.toAscList) (readTVarIO . announced $ session) |
384 | forM_ js $ \(u,rs) -> do | 390 | forM_ js $ \(u,rs) -> do |
385 | forM_ (Set.toList rs) $ \(rsc,_) -> do | 391 | forM_ (Set.toList rs) $ \(rsc,_) -> do |
392 | debugStr ("Annoucing offline: "++show (offline $ unsplitResource u (Just rsc))) | ||
386 | announcePresence session . offline $ unsplitResource u (Just rsc) | 393 | announcePresence session . offline $ unsplitResource u (Just rsc) |
387 | 394 | ||
388 | peerSessionFactory session = PeerSessions (peer_global session) | 395 | peerSessionFactory session = PeerSessions (peer_global session) |
@@ -564,7 +571,13 @@ unrefFromMap tvar key finalizer = do | |||
564 | omap <- readTVar tvar | 571 | omap <- readTVar tvar |
565 | let (r,omap') = Map.updateLookupWithKey unref key omap | 572 | let (r,omap') = Map.updateLookupWithKey unref key omap |
566 | writeTVar tvar omap' | 573 | writeTVar tvar omap' |
567 | return (isNothing r) | 574 | -- updateLookupWithKey |
575 | -- The function returns changed value, if it is updated. | ||
576 | -- Returns the original key value if the map entry is deleted. | ||
577 | -- GAAAHGAFHASD:LFKJDSA:LKFJPOFEIWE:FLJF!#@!$@#! | ||
578 | -- FUCK YOU Data.Map | ||
579 | -- Guess I have to do another pointless logarithmic lookup. | ||
580 | return (isNothing (Map.lookup key omap')) | ||
568 | when vanished finalizer | 581 | when vanished finalizer |
569 | where | 582 | where |
570 | unref key (cnt,object) = | 583 | unref key (cnt,object) = |