summaryrefslogtreecommitdiff
path: root/xmppServer.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-03-06 17:54:47 -0500
committerjoe <joe@jerkface.net>2014-03-06 17:54:47 -0500
commit8dc56b8f1d6417f2699171fd823fdbfd683ec0ac (patch)
tree567b24f2eec5cd723f410501bff2c7545cb9b7ef /xmppServer.hs
parentd35c2a82fa274c45ab1b2383405d3490656de3af (diff)
Send cached presence to client.
Diffstat (limited to 'xmppServer.hs')
-rw-r--r--xmppServer.hs35
1 files changed, 30 insertions, 5 deletions
diff --git a/xmppServer.hs b/xmppServer.hs
index 63420076..709137dc 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -87,7 +87,7 @@ data LocalPresence = LocalPresence
87 } 87 }
88 88
89data RemotePresence = RemotePresence 89data RemotePresence = RemotePresence
90 { resources :: Map Text () 90 { resources :: Map Text Stanza
91 -- , localSubscribers :: Map Text () 91 -- , localSubscribers :: Map Text ()
92 -- ^ subset of clientsByUser who should be 92 -- ^ subset of clientsByUser who should be
93 -- notified about this presence. 93 -- notified about this presence.
@@ -490,8 +490,8 @@ informPeerPresence state k stanza = do
490 maybe (Map.empty) 490 maybe (Map.empty)
491 (Map.delete resource . resources) 491 (Map.delete resource . resources)
492 $ Map.lookup user umap 492 $ Map.lookup user umap
493 _ -> maybe (Map.singleton resource ()) 493 _ -> maybe (Map.singleton resource stanza)
494 (Map.insert resource () . resources ) 494 (Map.insert resource stanza . resources )
495 $ Map.lookup user umap 495 $ Map.lookup user umap
496 umap' = Map.insert user (RemotePresence rp) umap 496 umap' = Map.insert user (RemotePresence rp) umap
497 writeTVar (remotesByPeer state) $ Map.insert k umap' rbp 497 writeTVar (remotesByPeer state) $ Map.insert k umap' rbp
@@ -506,12 +506,12 @@ informPeerPresence state k stanza = do
506 return (ck,con,client) 506 return (ck,con,client)
507 putStrLn $ "xmppInformPeerPresence (length clients="++show (length clients)++")" 507 putStrLn $ "xmppInformPeerPresence (length clients="++show (length clients)++")"
508 forM_ clients $ \(ck,con,client) -> do 508 forM_ clients $ \(ck,con,client) -> do
509 from' <- do 509 froms <- do
510 let ClientKey laddr = ck 510 let ClientKey laddr = ck
511 (_,trip) <- multiplyJIDForClient laddr from 511 (_,trip) <- multiplyJIDForClient laddr from
512 return (map unsplitJID trip) 512 return (map unsplitJID trip)
513 putStrLn $ "sending to client: " ++ show (stanzaType stanza) 513 putStrLn $ "sending to client: " ++ show (stanzaType stanza)
514 forM_ from' $ \from' -> do 514 forM_ froms $ \from' -> do
515 dup <- cloneStanza stanza 515 dup <- cloneStanza stanza
516 sendModifiedStanzaToClient (dup { stanzaFrom=Just from' }) 516 sendModifiedStanzaToClient (dup { stanzaFrom=Just from' })
517 (connChan con) 517 (connChan con)
@@ -551,6 +551,30 @@ answerProbe state k stanza chan = do
551 pstanza <- makePresenceStanza "jabber:server" (Just jid) Offline 551 pstanza <- makePresenceStanza "jabber:server" (Just jid) Offline
552 atomically $ writeTChan (connChan conn) pstanza 552 atomically $ writeTChan (connChan conn) pstanza
553 553
554sendCachedPresence state k chan = do
555 -- TODO: send buddies in remotesByPeer
556 forClient state k (return ()) $ \client -> do
557 rbp <- atomically $ readTVar (remotesByPeer state)
558 jids <- configText ConfigFiles.getBuddies (clientUser client)
559 let hosts = map ((\(_,h,_)->h) . splitJID) jids
560 addrs <- resolveAllPeers hosts
561 let onlines = rbp `Map.intersection` Map.mapKeys PeerKey addrs
562 ClientKey laddr = k
563 forM_ (Map.toList onlines) $ \(pk, umap) -> do
564 forM_ (Map.toList umap) $ \(user,rp) -> do
565 let h = peerKeyToText pk
566 forM_ (Map.toList $ resources rp) $ \(resource,stanza) -> do
567 let jid = unsplitJID (Just user,h,Just resource)
568 (mine,js) <- multiplyJIDForClient laddr jid
569 forM_ js $ \jid -> do
570 let from' = unsplitJID jid
571 dup <- cloneStanza stanza
572 sendModifiedStanzaToClient (dup { stanzaFrom=Just from' })
573 chan -- (connChan con)
574
575 -- TODO: send local buddies in clientsByUser
576 return ()
577
554main = runResourceT $ do 578main = runResourceT $ do
555 state <- liftIO . atomically $ do 579 state <- liftIO . atomically $ do
556 clients <- newTVar Map.empty 580 clients <- newTVar Map.empty
@@ -586,6 +610,7 @@ main = runResourceT $ do
586 , xmppInformClientPresence = informClientPresence state 610 , xmppInformClientPresence = informClientPresence state
587 , xmppInformPeerPresence = informPeerPresence state 611 , xmppInformPeerPresence = informPeerPresence state
588 , xmppAnswerProbe = answerProbe state 612 , xmppAnswerProbe = answerProbe state
613 , xmppSendCachedPresenceToClient = sendCachedPresence state
589 } 614 }
590 liftIO $ do 615 liftIO $ do
591 atomically $ putTMVar (server state) sv 616 atomically $ putTMVar (server state) sv