summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmppServer.hs23
1 files changed, 14 insertions, 9 deletions
diff --git a/xmppServer.hs b/xmppServer.hs
index 2476daec..823e1aba 100644
--- a/xmppServer.hs
+++ b/xmppServer.hs
@@ -223,9 +223,6 @@ toMapUnit xs = Map.fromList $ map (,()) xs
223resolveAllPeers :: [Text] -> IO (Map SockAddr ()) 223resolveAllPeers :: [Text] -> IO (Map SockAddr ())
224resolveAllPeers hosts = fmap (toMapUnit . concat) $ Prelude.mapM (fmap (take 1) . resolvePeer) hosts 224resolveAllPeers hosts = fmap (toMapUnit . concat) $ Prelude.mapM (fmap (take 1) . resolvePeer) hosts
225 225
226configText what u =
227 fmap (map lazyByteStringToText)
228 $ what (textToLazyByteString u)
229 226
230rosterGetStuff 227rosterGetStuff
231 :: (L.ByteString -> IO [L.ByteString]) 228 :: (L.ByteString -> IO [L.ByteString])
@@ -260,13 +257,13 @@ rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers
260data Conn = Conn { connChan :: TChan Stanza 257data Conn = Conn { connChan :: TChan Stanza
261 , auxAddr :: SockAddr } 258 , auxAddr :: SockAddr }
262 259
263textAdapter what u = fmap (map lazyByteStringToText) 260configText what u = fmap (map lazyByteStringToText)
264 $ what (textToLazyByteString u) 261 $ what (textToLazyByteString u)
265 262
266getBuddies' :: Text -> IO [Text] 263getBuddies' :: Text -> IO [Text]
267getBuddies' = textAdapter ConfigFiles.getBuddies 264getBuddies' = configText ConfigFiles.getBuddies
268getSolicited' :: Text -> IO [Text] 265getSolicited' :: Text -> IO [Text]
269getSolicited' = textAdapter ConfigFiles.getSolicited 266getSolicited' = configText ConfigFiles.getSolicited
270 267
271sendProbesAndSolicitations state k laddr chan = do 268sendProbesAndSolicitations state k laddr chan = do
272 -- get all buddies & solicited matching k for all users 269 -- get all buddies & solicited matching k for all users
@@ -469,6 +466,12 @@ setClientFlag state k flag =
469informSentRoster state k = setClientFlag state k cf_interested 466informSentRoster state k = setClientFlag state k cf_interested
470 467
471 468
469subscribedPeers user = do
470 jids <- configText ConfigFiles.getSubscribers user
471 let hosts = map ((\(_,h,_)->h) . splitJID) jids
472 fmap Map.keys $ resolveAllPeers hosts
473
474
472-- | Send presence notification to subscribed peers. 475-- | Send presence notification to subscribed peers.
473-- Note that a full JID from address will be added to the 476-- Note that a full JID from address will be added to the
474-- stanza if it is not present. 477-- stanza if it is not present.
@@ -482,9 +485,7 @@ informClientPresence state k stanza = do
482 when (not $ clientIsAvailable client) $ do 485 when (not $ clientIsAvailable client) $ do
483 setClientFlag state k cf_available 486 setClientFlag state k cf_available
484 sendCachedPresence state k 487 sendCachedPresence state k
485 jids <- configText ConfigFiles.getSubscribers (clientUser client) 488 addrs <- subscribedPeers (clientUser client)
486 let hosts = map ((\(_,h,_)->h) . splitJID) jids
487 addrs <- fmap Map.keys $ resolveAllPeers hosts
488 ktc <- atomically $ readTVar (keyToChan state) 489 ktc <- atomically $ readTVar (keyToChan state)
489 let connected = mapMaybe (flip Map.lookup ktc . PeerKey) addrs 490 let connected = mapMaybe (flip Map.lookup ktc . PeerKey) addrs
490 forM_ connected $ \con -> do 491 forM_ connected $ \con -> do
@@ -560,6 +561,10 @@ answerProbe state k stanza chan = do
560 561
561 flip (maybe $ return ()) muser $ \(u,conn,ch) -> do 562 flip (maybe $ return ()) muser $ \(u,conn,ch) -> do
562 563
564 -- only subscribed peers should get probe replies
565 addrs <- subscribedPeers u
566 when (k `elem` map PeerKey addrs) $ do
567
563 replies <- runTraversableT $ do 568 replies <- runTraversableT $ do
564 cbu <- lift . atomically $ readTVar (clientsByUser state) 569 cbu <- lift . atomically $ readTVar (clientsByUser state)
565 lpres <- liftMaybe $ Map.lookup u cbu 570 lpres <- liftMaybe $ Map.lookup u cbu