summaryrefslogtreecommitdiff
path: root/Presence/XMPP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/XMPP.hs')
-rw-r--r--Presence/XMPP.hs48
1 files changed, 31 insertions, 17 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs
index 9190ee3c..173e7cdf 100644
--- a/Presence/XMPP.hs
+++ b/Presence/XMPP.hs
@@ -419,6 +419,7 @@ handleIQGet session cmdChan tag = do
419 atomically $ do 419 atomically $ do
420 writeTChan cmdChan InterestedInRoster 420 writeTChan cmdChan InterestedInRoster
421 writeTChan cmdChan . Send $ roster 421 writeTChan cmdChan . Send $ roster
422 sendPending session
422 req -> unhandledGet req 423 req -> unhandledGet req
423 424
424 425
@@ -502,15 +503,17 @@ toClient session pchan cmdChan rchan = toClient' False False
502 let loop = toClient' isBound isInterested 503 let loop = toClient' isBound isInterested
503 send xs = yield xs >> prettyPrint ">C: " xs 504 send xs = yield xs >> prettyPrint ">C: " xs
504 event <- liftIO . atomically $ 505 event <- liftIO . atomically $
505 foldr1 orElse [fmap PChan $ readTChan pchan 506 foldr1 orElse [fmap CmdChan $ readTChan cmdChan
506 ,fmap RChan $ readTChan rchan 507 ,fmap RChan $ readTChan rchan
507 ,fmap CmdChan $ readTChan cmdChan 508 ,fmap PChan $ readTChan pchan
508 ] 509 ]
509 case event of 510 case event of
510 CmdChan QuitThread -> return () 511 CmdChan QuitThread -> return ()
511 CmdChan (Send xs) -> send xs >> loop 512 CmdChan (Send xs) -> send xs >> loop
512 CmdChan BoundToResource -> toClient' True isInterested 513 CmdChan BoundToResource -> toClient' True isInterested
513 CmdChan InterestedInRoster -> toClient' isBound True 514 CmdChan InterestedInRoster -> do
515 liftIO . putStrLn $ "Roster: interested"
516 toClient' isBound True
514 -- CmdChan cmd -> liftIO (putStrLn $ "unhandled event: "++show cmd) >> loop 517 -- CmdChan cmd -> liftIO (putStrLn $ "unhandled event: "++show cmd) >> loop
515 RChan (RequestedSubscription who contact) -> do 518 RChan (RequestedSubscription who contact) -> do
516 jid <- liftIO $ getJID session 519 jid <- liftIO $ getJID session
@@ -520,11 +523,15 @@ toClient session pchan cmdChan rchan = toClient' False False
520 loop 523 loop
521 RChan (NewBuddy who contact) -> do 524 RChan (NewBuddy who contact) -> do
522 liftIO . putStrLn $ "Roster push: NewBuddy "++show (isInterested,who,contact) 525 liftIO . putStrLn $ "Roster push: NewBuddy "++show (isInterested,who,contact)
523 jid <- liftIO $ getJID session 526 (jid,me) <- liftIO $ do
527 jid <- getJID session
528 me <- asHostNameJID jid
529 return (jid,me)
530 withJust me $ \me -> do
524 when (isInterested && Just who==name jid) $ do 531 when (isInterested && Just who==name jid) $ do
525 send [ EventBeginElement "{jabber:client}presence" 532 send [ EventBeginElement "{jabber:client}presence"
526 [ attrbs "from" contact 533 [ attrbs "from" contact
527 , attrbs "to" (L.show jid) 534 , attrbs "to" me
528 , attr "type" "subscribed" 535 , attr "type" "subscribed"
529 ] 536 ]
530 , EventEndElement "{jabber:client}presence" ] 537 , EventEndElement "{jabber:client}presence" ]
@@ -537,12 +544,28 @@ toClient session pchan cmdChan rchan = toClient' False False
537 [attr "subscription" subscription] 544 [attr "subscription" subscription]
538 send r 545 send r
539 loop 546 loop
547 RChan (PendingBuddy who contact) -> do
548 liftIO . putStrLn $ "Roster: Pending buddy "++show (isInterested,who,contact)
549 (jid,me) <- liftIO $ do
550 jid <- getJID session
551 me <- asHostNameJID jid
552 return (jid,me)
553 withJust me $ \me -> do
554 when (isInterested && Just who==name jid) $ do
555 send [ EventBeginElement "{jabber:client}presence"
556 [ attrbs "from" contact
557 , attrbs "to" me
558 , attr "type" "subscribe"
559 ]
560 , EventEndElement "{jabber:client}presence" ]
561 loop
540 PChan presence -> do 562 PChan presence -> do
541 when isBound $ do 563 when isBound $ do
542 xs <- liftIO $ xmlifyPresenceForClient presence 564 xs <- liftIO $ xmlifyPresenceForClient presence
543 send xs 565 send xs
544 loop 566 loop
545 567
568
546handleClient 569handleClient
547 :: (SocketLike sock, HHead l (XMPPClass session), 570 :: (SocketLike sock, HHead l (XMPPClass session),
548 JabberClientSession session) => 571 JabberClientSession session) =>
@@ -805,21 +828,12 @@ peerRequestsSubsription session stanza = do
805 ps <- userStatus session user 828 ps <- userStatus session user
806 mapM_ (announcePresence session) ps 829 mapM_ (announcePresence session) ps
807 else 830 else
808 -- TODO 831 liftIO $ processRequest session user fromjid
809 -- if no client:
810 -- add pending
811 -- else:
812 -- notify client(s)
813 return ()
814 return ()
815 832
816clientApprovesSubscription session stanza = do 833clientApprovesSubscription session stanza = do
817 liftIO $ putStrLn $ "CLIENT APPROVES SUBSCRIPTION" 834 liftIO $ putStrLn $ "CLIENT APPROVES SUBSCRIPTION"
818 -- add subscribers 835 withJust (lookupAttrib "to" (tagAttrs stanza)) $ \to_str -> do
819 -- remove pending 836 liftIO $ approveSubscriber session (textToByteString to_str)
820 -- remove others
821 -- notify peer
822 return ()
823 837
824peerApprovesSubscription session stanza = do 838peerApprovesSubscription session stanza = do
825 liftIO $ putStrLn $ "PEER APPROVES SUBSCRIPTION" 839 liftIO $ putStrLn $ "PEER APPROVES SUBSCRIPTION"