diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-01 23:18:50 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-02 00:21:52 -0400 |
commit | adc61071fb1c3a72f2d8f06866e0f3abaf50c6f5 (patch) | |
tree | 7bfd43a481dd99d07b201b8926fedc6a5244ead2 | |
parent | 1b3b665cb8413ed519fab1fa560716736676fa59 (diff) |
Purged TraversableT usage.
-rw-r--r-- | Presence/Presence.hs | 76 | ||||
-rw-r--r-- | dht-client.cabal | 1 |
2 files changed, 37 insertions, 40 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs index 2086133d..c2398607 100644 --- a/Presence/Presence.hs +++ b/Presence/Presence.hs | |||
@@ -42,7 +42,6 @@ import ControlMaybe | |||
42 | import DNSCache (parseAddress, strip_brackets, withPort) | 42 | import DNSCache (parseAddress, strip_brackets, withPort) |
43 | import LockedChan (LockedChan) | 43 | import LockedChan (LockedChan) |
44 | import Text.Read (readMaybe) | 44 | import Text.Read (readMaybe) |
45 | import TraversableT | ||
46 | import UTmp (ProcessID,users) | 45 | import UTmp (ProcessID,users) |
47 | import LocalPeerCred | 46 | import LocalPeerCred |
48 | import XMPPServer | 47 | import XMPPServer |
@@ -799,10 +798,9 @@ informClientPresence0 state mbk client stanza = do | |||
799 | let connected = mapMaybe (flip Map.lookup ktc) addrs | 798 | let connected = mapMaybe (flip Map.lookup ktc) addrs |
800 | forM_ connected $ \con -> do | 799 | forM_ connected $ \con -> do |
801 | let from' = clientJID con client | 800 | let from' = clientJID con client |
802 | mto <- runTraversableT $ do | 801 | mto <- maybe (return Nothing) |
803 | to <- liftT $ stanzaTo stanza | 802 | (fmap (fmap fst) . rewriteJIDForPeer (manager state $ clientProfile client)) |
804 | (to',_) <- liftMT $ rewriteJIDForPeer (manager state $ clientProfile client) to | 803 | (stanzaTo stanza) |
805 | return to' | ||
806 | dup <- cloneStanza stanza | 804 | dup <- cloneStanza stanza |
807 | sendModifiedStanzaToPeer dup { stanzaFrom = Just from' | 805 | sendModifiedStanzaToPeer dup { stanzaFrom = Just from' |
808 | , stanzaTo = mto } | 806 | , stanzaTo = mto } |
@@ -860,10 +858,11 @@ informPeerPresence state k stanza = do | |||
860 | -- all clients, we'll filter available/authorized later | 858 | -- all clients, we'll filter available/authorized later |
861 | 859 | ||
862 | ktc <- readTVar (ckeyToChan state) | 860 | ktc <- readTVar (ckeyToChan state) |
863 | runTraversableT $ do | 861 | cmap <- readTVar (clients state) |
864 | (ck,client) <- liftMT $ fmap Map.toList $ readTVar (clients state) | 862 | return $ do |
865 | con <- liftMaybe $ Map.lookup ck ktc | 863 | (ck,client) <- Map.toList cmap |
866 | return (ck,con,client) | 864 | con <- maybeToList $ Map.lookup ck ktc |
865 | return (ck,con,client) | ||
867 | dput XJabber $ "xmppInformPeerPresence (length clients="++show (length clients)++")" | 866 | dput XJabber $ "xmppInformPeerPresence (length clients="++show (length clients)++")" |
868 | (ctyp,cprof) <- atomically $ do | 867 | (ctyp,cprof) <- atomically $ do |
869 | mconn <- Map.lookup k <$> readTVar (pkeyToChan state) | 868 | mconn <- Map.lookup k <$> readTVar (pkeyToChan state) |
@@ -899,18 +898,17 @@ answerProbe :: PresenceState stat -> Maybe Text -> PeerAddress -> TChan Stanza - | |||
899 | answerProbe state mto k chan = do | 898 | answerProbe state mto k chan = do |
900 | -- dput XJabber $ "answerProbe! " ++ show (stanzaType stanza) | 899 | -- dput XJabber $ "answerProbe! " ++ show (stanzaType stanza) |
901 | ktc <- atomically $ readTVar (pkeyToChan state) | 900 | ktc <- atomically $ readTVar (pkeyToChan state) |
902 | muser <- runTraversableT $ do | 901 | muser <- fmap join $ sequence $ do |
903 | to <- liftT $ mto | 902 | to <- mto |
904 | conn <- liftT $ Map.lookup k ktc | 903 | conn <- Map.lookup k ktc |
905 | let (mu,h,_) = splitJID to -- TODO: currently resource-id is ignored on presence | 904 | let (mu,h,_) = splitJID to -- TODO: currently resource-id is ignored on presence |
906 | -- probes. Is this correct? Check the spec. | 905 | -- probes. Is this correct? Check the spec. |
907 | Left laddr = cdAddr $ auxData conn | 906 | Left laddr = cdAddr $ auxData conn |
908 | liftMT $ guardPortStrippedAddress h laddr | 907 | ch = addrToText a where Local a = laddr |
909 | u <- liftT mu | 908 | u <- mu |
910 | -- ORIG let ch = addrToText (auxAddr conn) | 909 | Just $ do |
911 | -- ORIG return (u,conn,ch) | 910 | guardPortStrippedAddress h laddr |
912 | let ch = addrToText a where Local a = laddr | 911 | <&> maybe Nothing (\_ -> Just (u,conn,ch)) |
913 | return (u,conn,ch) | ||
914 | 912 | ||
915 | forM_ muser $ \(u,conn,ch) -> do | 913 | forM_ muser $ \(u,conn,ch) -> do |
916 | 914 | ||
@@ -932,21 +930,22 @@ answerProbe state mto k chan = do | |||
932 | -- reply <- makeInformSubscription "jabber:server" to from False | 930 | -- reply <- makeInformSubscription "jabber:server" to from False |
933 | when (not $ null whitelist) $ do | 931 | when (not $ null whitelist) $ do |
934 | 932 | ||
935 | replies <- runTraversableT $ do | 933 | replies <- catMaybes <$> do -- runTraversableT $ do |
936 | cbu <- lift . atomically $ readTVar (clientsByUser state) | 934 | cbu <- atomically $ readTVar (clientsByUser state) -- Map Text LocalPresence |
937 | let lpres = maybeToList $ Map.lookup u cbu | 935 | let lpres = maybeToList $ Map.lookup u cbu |
938 | cw <- lift . atomically $ consoleClients state | 936 | cw <- atomically $ consoleClients state -- Map Text ClientState |
939 | clientState <- liftT $ (lpres >>= Map.elems . networkClients) | 937 | forM ((lpres >>= Map.elems . networkClients) ++ Map.elems cw) $ \clientState -> do |
940 | ++ Map.elems cw | 938 | -- liftIOMaybe :: IO (Maybe a) -> TraversableT [] IO a |
941 | stanza <- liftIOMaybe $ atomically (readTVar (clientStatus clientState)) | 939 | mstanza <- atomically $ readTVar (clientStatus clientState) |
942 | stanza <- lift $ cloneStanza stanza | 940 | forM mstanza $ \stanza0 -> do |
943 | let jid = unsplitJID (Just $ clientUser clientState | 941 | stanza <- cloneStanza stanza0 |
944 | , ch | 942 | let jid = unsplitJID (Just $ clientUser clientState |
945 | ,Just $ clientResource clientState) | 943 | , ch |
946 | return stanza { stanzaFrom = Just jid | 944 | ,Just $ clientResource clientState) |
947 | , stanzaType = (stanzaType stanza) | 945 | return stanza { stanzaFrom = Just jid |
948 | { presenceWhiteList = whitelist } | 946 | , stanzaType = (stanzaType stanza) |
949 | } | 947 | { presenceWhiteList = whitelist } |
948 | } | ||
950 | 949 | ||
951 | forM_ replies $ \reply -> do | 950 | forM_ replies $ \reply -> do |
952 | sendModifiedStanzaToPeer reply chan | 951 | sendModifiedStanzaToPeer reply chan |
@@ -1169,12 +1168,11 @@ resolvedFromRoster | |||
1169 | :: Connection.Manager s Text | 1168 | :: Connection.Manager s Text |
1170 | -> (ConfigFiles.User -> ConfigFiles.Profile -> IO [L.ByteString]) | 1169 | -> (ConfigFiles.User -> ConfigFiles.Profile -> IO [L.ByteString]) |
1171 | -> UserName -> Text -> IO [(Maybe UserName, PeerAddress)] | 1170 | -> UserName -> Text -> IO [(Maybe UserName, PeerAddress)] |
1172 | resolvedFromRoster man doit u profile = do | 1171 | resolvedFromRoster man doit u profile = concat <$> do |
1173 | subs <- configText doit u profile | 1172 | subs <- configText doit u profile |
1174 | runTraversableT $ do | 1173 | forM (splitJID `fmap` subs) $ \(mu,h,_) -> do |
1175 | (mu,h,_) <- liftT $ splitJID `fmap` subs | 1174 | addrs <- fmap nub $ resolvePeer man h |
1176 | addr <- liftMT $ fmap nub $ resolvePeer man h | 1175 | return $ map (mu,) addrs |
1177 | return (mu,addr) | ||
1178 | 1176 | ||
1179 | clientCons :: PresenceState stat | 1177 | clientCons :: PresenceState stat |
1180 | -> Map ClientAddress t -> Text -> IO [(t, ClientState)] | 1178 | -> Map ClientAddress t -> Text -> IO [(t, ClientState)] |
diff --git a/dht-client.cabal b/dht-client.cabal index 664dc1e6..55ca6a04 100644 --- a/dht-client.cabal +++ b/dht-client.cabal | |||
@@ -140,7 +140,6 @@ library | |||
140 | Paths | 140 | Paths |
141 | Connection.Tcp | 141 | Connection.Tcp |
142 | SockAddr | 142 | SockAddr |
143 | TraversableT | ||
144 | UTmp | 143 | UTmp |
145 | XMPPServer | 144 | XMPPServer |
146 | Util | 145 | Util |