diff options
-rw-r--r-- | xmppServer.hs | 23 |
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 | |||
223 | resolveAllPeers :: [Text] -> IO (Map SockAddr ()) | 223 | resolveAllPeers :: [Text] -> IO (Map SockAddr ()) |
224 | resolveAllPeers hosts = fmap (toMapUnit . concat) $ Prelude.mapM (fmap (take 1) . resolvePeer) hosts | 224 | resolveAllPeers hosts = fmap (toMapUnit . concat) $ Prelude.mapM (fmap (take 1) . resolvePeer) hosts |
225 | 225 | ||
226 | configText what u = | ||
227 | fmap (map lazyByteStringToText) | ||
228 | $ what (textToLazyByteString u) | ||
229 | 226 | ||
230 | rosterGetStuff | 227 | rosterGetStuff |
231 | :: (L.ByteString -> IO [L.ByteString]) | 228 | :: (L.ByteString -> IO [L.ByteString]) |
@@ -260,13 +257,13 @@ rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers | |||
260 | data Conn = Conn { connChan :: TChan Stanza | 257 | data Conn = Conn { connChan :: TChan Stanza |
261 | , auxAddr :: SockAddr } | 258 | , auxAddr :: SockAddr } |
262 | 259 | ||
263 | textAdapter what u = fmap (map lazyByteStringToText) | 260 | configText what u = fmap (map lazyByteStringToText) |
264 | $ what (textToLazyByteString u) | 261 | $ what (textToLazyByteString u) |
265 | 262 | ||
266 | getBuddies' :: Text -> IO [Text] | 263 | getBuddies' :: Text -> IO [Text] |
267 | getBuddies' = textAdapter ConfigFiles.getBuddies | 264 | getBuddies' = configText ConfigFiles.getBuddies |
268 | getSolicited' :: Text -> IO [Text] | 265 | getSolicited' :: Text -> IO [Text] |
269 | getSolicited' = textAdapter ConfigFiles.getSolicited | 266 | getSolicited' = configText ConfigFiles.getSolicited |
270 | 267 | ||
271 | sendProbesAndSolicitations state k laddr chan = do | 268 | sendProbesAndSolicitations 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 = | |||
469 | informSentRoster state k = setClientFlag state k cf_interested | 466 | informSentRoster state k = setClientFlag state k cf_interested |
470 | 467 | ||
471 | 468 | ||
469 | subscribedPeers 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 |