summaryrefslogtreecommitdiff
path: root/Presence/MUC.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2019-09-28 13:43:29 -0400
committerJoe Crayne <joe@jerkface.net>2020-01-01 19:27:53 -0500
commit11987749fc6e6d3e53ea737d46d5ab13a16faeb8 (patch)
tree5716463275c2d3e902889db619908ded2a73971c /Presence/MUC.hs
parentadd2c76bced51fde5e9917e7449ef52be70faf87 (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/MUC.hs')
-rw-r--r--Presence/MUC.hs61
1 files changed, 0 insertions, 61 deletions
diff --git a/Presence/MUC.hs b/Presence/MUC.hs
deleted file mode 100644
index 639e834b..00000000
--- a/Presence/MUC.hs
+++ /dev/null
@@ -1,61 +0,0 @@
1module MUC where
2
3import Control.Monad
4import Control.Concurrent.STM
5
6import qualified Data.Map.Strict as Map
7 ;import Data.Map.Strict (Map)
8
9import Chat
10import ConnectionKey
11import Data.Text (Text)
12
13data MUC = MUC
14 { mucRooms :: TVar (Map Text (Room ClientAddress))
15 , mucChan :: TChan MUCEvent
16 }
17
18data MUCEvent = MUCCreate Text{-room-} Text{-JID-} Text{-nick-} (Room ClientAddress)
19
20
21newMUC :: STM MUC
22newMUC = MUC <$> newTVar Map.empty <*> newBroadcastTChan
23
24mucRoomList :: MUC -> IO [(Text{-room-},Maybe Text{-friendly room name-})]
25mucRoomList muc = atomically $ do
26 rs <- Map.toList <$> readTVar (mucRooms muc)
27 forM rs $ \(rkey,r) -> do
28 fn <- roomFriendlyName r
29 return (rkey,fn)
30
31mucRoomOccupants :: MUC -> Text{-room-} -> IO [(Text{-nick-},Maybe Text{-friendly name-})]
32mucRoomOccupants muc rkey = atomically $ do
33 mr <- Map.lookup rkey <$> readTVar (mucRooms muc)
34 case mr of
35 Nothing -> return []
36 Just r -> roomOccupants r
37
38mucReservedNick :: MUC -> Text{-room-} -> IO (Maybe (Text{-JID-} -> IO (Maybe Text)))
39mucReservedNick muc rkey = atomically $ do
40 mr <- Map.lookup rkey <$> readTVar (mucRooms muc)
41 case mr of
42 Nothing -> return Nothing
43 Just r -> return $ Just $ \jid -> atomically $ roomReservedNick r jid
44
45mucJoinRoom :: MUC -> Text{-JID-} -> Text{-nick-} -> Text{-room-} -> ClientAddress -> STM (JoinedRoom ClientAddress)
46mucJoinRoom muc jid nick rkey k = do
47 mr <- Map.lookup rkey <$> readTVar (mucRooms muc)
48 case mr of
49 Nothing -> do
50 -- create room.
51 r <- newRoom
52 v <- joinRoom k r (Just jid) nick
53 modifyTVar' (mucRooms muc) $ Map.insert rkey r
54 writeTChan (mucChan muc) $ MUCCreate rkey jid nick r
55 return v
56 Just r -> do
57 -- join room.
58 v <- joinRoom k r (Just jid) nick
59 return v
60
61