diff options
author | joe <joe@jerkface.net> | 2013-07-29 23:50:14 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-07-29 23:50:14 -0400 |
commit | 36637654a5d18125370ba1323e9e96a6bc01441f (patch) | |
tree | 5b73b888998f17c53972f34b4832400e70e07d56 /Presence/main.hs | |
parent | 4fca264f84572a7e2c28fa6762d154bcd796fb33 (diff) |
Progress toward support for messaging.
Diffstat (limited to 'Presence/main.hs')
-rw-r--r-- | Presence/main.hs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Presence/main.hs b/Presence/main.hs index d7510f94..784faaca 100644 --- a/Presence/main.hs +++ b/Presence/main.hs | |||
@@ -56,7 +56,10 @@ import Network.Socket (Family(AF_INET,AF_INET6)) | |||
56 | import Holumbus.Data.MultiMap as MM (MultiMap) | 56 | import Holumbus.Data.MultiMap as MM (MultiMap) |
57 | import qualified Holumbus.Data.MultiMap as MM | 57 | import qualified Holumbus.Data.MultiMap as MM |
58 | 58 | ||
59 | data Client = Client { clientShow :: JabberShow } | 59 | data Client = Client { |
60 | clientShow :: JabberShow, | ||
61 | clientChan :: TChan ClientCommands | ||
62 | } | ||
60 | 63 | ||
61 | -- see Data.Map.Lazy.fromSet | 64 | -- see Data.Map.Lazy.fromSet |
62 | fromSet f = Map.fromList . map (\a -> (a,f a)) . Set.toList | 65 | fromSet f = Map.fromList . map (\a -> (a,f a)) . Set.toList |
@@ -195,7 +198,12 @@ instance JabberClientSession ClientSession where | |||
195 | let au = activeUsers . presence_state $ s | 198 | let au = activeUsers . presence_state $ s |
196 | us <- readTVar au | 199 | us <- readTVar au |
197 | sequenceA $ Map.lookup (user,tty) us >>= \(ttypid,cs) -> do | 200 | sequenceA $ Map.lookup (user,tty) us >>= \(ttypid,cs) -> do |
198 | let entry = (ttypid,Map.insert client_pid (Client {clientShow=stat}) cs) | 201 | let entry = (ttypid, Map.insert client_pid |
202 | (Client { | ||
203 | clientShow = stat, | ||
204 | clientChan = Main.clientChannel s | ||
205 | }) | ||
206 | cs) | ||
199 | Just $ do | 207 | Just $ do |
200 | writeTVar au (Map.insert (user,tty) entry us) | 208 | writeTVar au (Map.insert (user,tty) entry us) |
201 | subs <- readTVar $ subscriberMap (presence_state s) | 209 | subs <- readTVar $ subscriberMap (presence_state s) |
@@ -394,6 +402,11 @@ instance JabberClientSession ClientSession where | |||
394 | (peer cjid) | 402 | (peer cjid) |
395 | return () | 403 | return () |
396 | 404 | ||
405 | sendChat s msg = do | ||
406 | sendMessage (remotePeers . presence_state $ s) | ||
407 | (OutBoundMessage msg) | ||
408 | (peer . msgTo $ msg) | ||
409 | |||
397 | 410 | ||
398 | {- PeerSession | 411 | {- PeerSession |
399 | - | 412 | - |
@@ -508,6 +521,21 @@ instance JabberPeerSession PeerSession where | |||
508 | withJust mbuddy $ \buddy -> do | 521 | withJust mbuddy $ \buddy -> do |
509 | rosterPush (PendingSubscriber user buddy) (peer_global session) | 522 | rosterPush (PendingSubscriber user buddy) (peer_global session) |
510 | 523 | ||
524 | sendChatToClient session msg = do | ||
525 | let rsc = resource (msgTo msg) | ||
526 | g = peer_global session | ||
527 | (curtty,cmap) <- atomically $ liftM2 (,) (readTVar (currentTTY g)) | ||
528 | (readTVar (activeUsers g)) | ||
529 | |||
530 | let rsc' = maybe curtty id rsc | ||
531 | withJust (name (msgTo msg)) $ \nto -> do | ||
532 | case Map.lookup (nto,rsc') cmap of | ||
533 | Just (ttypid,clients) -> | ||
534 | forM_ (Map.toList clients) $ \(pid,client) -> do | ||
535 | atomically $ writeTChan (clientChan client) (Chat msg) | ||
536 | Nothing -> | ||
537 | -- todo: fallback | ||
538 | return () | ||
511 | 539 | ||
512 | 540 | ||
513 | type RefCount = Int | 541 | type RefCount = Int |