summaryrefslogtreecommitdiff
path: root/Presence/Presence.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-05-24 22:11:47 -0400
committerjoe <joe@jerkface.net>2018-05-24 22:11:47 -0400
commit70edecc06f24aeb973f94db0fa111a4b8889ac56 (patch)
treec68f7fc3e5d4f9635c8542296e3d4dcf47d587a5 /Presence/Presence.hs
parent8c428b1cd2a2e34bed4c1128bb52222e8449be2d (diff)
More comments.
Diffstat (limited to 'Presence/Presence.hs')
-rw-r--r--Presence/Presence.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index c6bf9ffa..4765b05a 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -300,8 +300,10 @@ chooseResourceName state k addr clientsNameForMe desired = do
300 ) 300 )
301 muid 301 muid
302 302
303forClient :: PresenceState 303-- Perform action with 'ClientState' associated with the given 'ConnectionKey'.
304 -> ConnectionKey -> IO b -> (ClientState -> IO b) -> IO b 304-- If there is no associated 'ClientState', then perform the supplied fallback
305-- action.
306forClient :: PresenceState -> ConnectionKey -> IO b -> (ClientState -> IO b) -> IO b
305forClient state k fallback f = do 307forClient state k fallback f = do
306 mclient <- atomically $ do 308 mclient <- atomically $ do
307 cs <- readTVar (clients state) 309 cs <- readTVar (clients state)
@@ -321,6 +323,7 @@ resolveAllPeers :: [Text] -> IO (Map SockAddr ())
321resolveAllPeers hosts = fmap (toMapUnit . concat) $ Prelude.mapM (fmap (take 1) . resolvePeer) hosts 323resolveAllPeers hosts = fmap (toMapUnit . concat) $ Prelude.mapM (fmap (take 1) . resolvePeer) hosts
322 324
323 325
326-- Read a roster file and start trying to connect to all relevent peers.
324rosterGetStuff 327rosterGetStuff
325 :: (ConfigFiles.User -> ConfigFiles.Profile -> IO [L.ByteString]) 328 :: (ConfigFiles.User -> ConfigFiles.Profile -> IO [L.ByteString])
326 -> PresenceState -> ConnectionKey -> IO [Text] 329 -> PresenceState -> ConnectionKey -> IO [Text]
@@ -328,11 +331,15 @@ rosterGetStuff what state k = forClient state k (return [])
328 $ \client -> do 331 $ \client -> do
329 jids <- configText what (clientUser client) (clientProfile client) 332 jids <- configText what (clientUser client) (clientProfile client)
330 let hosts = map ((\(_,h,_)->h) . splitJID) jids 333 let hosts = map ((\(_,h,_)->h) . splitJID) jids
334 -- Using case to bring 'status' type variable to Connection.Manager into scope.
331 case state of 335 case state of
332 PresenceState { server = svVar } -> do 336 PresenceState { server = svVar } -> do
333 (sv,conns) <- atomically $ takeTMVar svVar 337 (sv,conns) <- atomically $ takeTMVar svVar
334 -- Grok peers to associate with from the roster: 338 -- Grok peers to associate with from the roster:
335 forM_ hosts $ \host -> do 339 forM_ hosts $ \host -> do
340 -- We need either conns :: Connection.Manager TCPStatus Text
341 -- or toxman :: ToxManager ConnectionKey
342 -- It is decided by checking hostnames for .tox ending.
336 let policySetter = fromMaybe (Connection.setPolicy conns host) $ do 343 let policySetter = fromMaybe (Connection.setPolicy conns host) $ do
337 toxman <- toxManager state 344 toxman <- toxManager state
338 (me , ".tox") <- Just $ Text.splitAt 43 (clientProfile client) 345 (me , ".tox") <- Just $ Text.splitAt 43 (clientProfile client)
@@ -348,6 +355,7 @@ rosterGetBuddies state k = rosterGetStuff ConfigFiles.getBuddies state k
348rosterGetSolicited :: PresenceState -> ConnectionKey -> IO [Text] 355rosterGetSolicited :: PresenceState -> ConnectionKey -> IO [Text]
349rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited 356rosterGetSolicited = rosterGetStuff ConfigFiles.getSolicited
350 357
358-- XXX: Should we be connecting to these peers?
351rosterGetOthers :: PresenceState -> ConnectionKey -> IO [Text] 359rosterGetOthers :: PresenceState -> ConnectionKey -> IO [Text]
352rosterGetOthers = rosterGetStuff ConfigFiles.getOthers 360rosterGetOthers = rosterGetStuff ConfigFiles.getOthers
353 361
@@ -357,6 +365,7 @@ rosterGetSubscribers = rosterGetStuff ConfigFiles.getSubscribers
357data Conn = Conn { connChan :: TChan Stanza 365data Conn = Conn { connChan :: TChan Stanza
358 , auxAddr :: SockAddr } 366 , auxAddr :: SockAddr }
359 367
368-- Read config file as Text content rather than UTF8 bytestrings.
360configText :: Functor f => 369configText :: Functor f =>
361 (ConfigFiles.User -> ConfigFiles.Profile -> f [L.ByteString]) 370 (ConfigFiles.User -> ConfigFiles.Profile -> f [L.ByteString])
362 -> Text -- user 371 -> Text -- user