diff options
author | James Crayne <jim.crayne@gmail.com> | 2019-09-28 13:43:29 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 19:27:53 -0500 |
commit | 11987749fc6e6d3e53ea737d46d5ab13a16faeb8 (patch) | |
tree | 5716463275c2d3e902889db619908ded2a73971c /Presence/LocalChat.hs | |
parent | add2c76bced51fde5e9917e7449ef52be70faf87 (diff) |
Factor out some new libraries
word64-map:
Data.Word64Map
network-addr:
Network.Address
tox-crypto:
Crypto.Tox
lifted-concurrent:
Control.Concurrent.Lifted.Instrument
Control.Concurrent.Async.Lifted.Instrument
psq-wrap:
Data.Wrapper.PSQInt
Data.Wrapper.PSQ
minmax-psq:
Data.MinMaxPSQ
tasks:
Control.Concurrent.Tasks
kad:
Network.Kademlia
Network.Kademlia.Bootstrap
Network.Kademlia.Routing
Network.Kademlia.CommonAPI
Network.Kademlia.Persistence
Network.Kademlia.Search
Diffstat (limited to 'Presence/LocalChat.hs')
-rw-r--r-- | Presence/LocalChat.hs | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/Presence/LocalChat.hs b/Presence/LocalChat.hs deleted file mode 100644 index eab54a03..00000000 --- a/Presence/LocalChat.hs +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
2 | module LocalChat | ||
3 | ( module Chat | ||
4 | , module LocalChat | ||
5 | ) where | ||
6 | |||
7 | import Debug.Trace | ||
8 | import Control.Concurrent.STM | ||
9 | import Control.Monad | ||
10 | import Data.Function | ||
11 | import Data.List | ||
12 | import qualified Data.Map as Map | ||
13 | ;import Data.Map (Map) | ||
14 | import qualified Data.Text as T | ||
15 | ;import Data.Text (Text) | ||
16 | |||
17 | #ifdef THREAD_DEBUG | ||
18 | import Control.Concurrent.Lifted.Instrument | ||
19 | #else | ||
20 | import Control.Concurrent.Lifted | ||
21 | import GHC.Conc (labelThread) | ||
22 | #endif | ||
23 | |||
24 | import DPut | ||
25 | import DebugTag | ||
26 | import Chat | ||
27 | import MUC | ||
28 | |||
29 | forkUntilSignaled :: String -> STM (IO ()) -> IO (IO ()) | ||
30 | forkUntilSignaled lbl action = do | ||
31 | quitSignal <- newTVarIO False | ||
32 | t <- forkIO $ do | ||
33 | fix $ \loop -> join $ atomically | ||
34 | $ orElse (do readTVar quitSignal >>= check | ||
35 | return $ return ()) | ||
36 | (fmap (>> loop) $ action) | ||
37 | labelThread t lbl | ||
38 | return $ atomically (writeTVar quitSignal True) | ||
39 | |||
40 | |||
41 | chatevents rsvar = do | ||
42 | rs <- readTVar rsvar | ||
43 | if Map.null rs | ||
44 | then retry | ||
45 | else do | ||
46 | ios <- forM rs $ \r -> do | ||
47 | ps <- roomPending r | ||
48 | trace ("roomPending " ++ show ps) $ return () | ||
49 | case Map.toList ps of | ||
50 | (k,t):ts -> do | ||
51 | roomCommit r k t | ||
52 | return $ do | ||
53 | dput XJabber $ "committed " ++ show (length ts,k,t) | ||
54 | _ -> retry | ||
55 | return $ foldl1 (>>) ios | ||
56 | |||
57 | forkLocalChat :: MUC -> IO (IO ()) | ||
58 | forkLocalChat muc = do | ||
59 | (chan, rs) <- atomically $ do | ||
60 | c <- dupTChan (mucChan muc) | ||
61 | rs <- newTVar Map.empty | ||
62 | return (c,rs) | ||
63 | forkUntilSignaled "localchat" $ orElse (chatevents rs) $ do | ||
64 | e <- readTChan chan | ||
65 | case e of | ||
66 | MUCCreate room jid nick r -> modifyTVar' rs $ Map.insert room r | ||
67 | return $ case e of | ||
68 | MUCCreate room jid nick _ -> | ||
69 | dput XJabber $ unwords $ map T.unpack | ||
70 | [ "MUCCreate", room, jid, nick ] | ||
71 | |||