diff options
author | joe <joe@jerkface.net> | 2014-03-08 23:37:09 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-03-08 23:37:09 -0500 |
commit | 0d9594428d6e197ea4dde15e3e1f53fc48c0bcf9 (patch) | |
tree | 8dd45f915965cd16ae8b6429bf928a6c36cbe003 | |
parent | f857a452f0b7ec41d0dc211845c55fd642a510ae (diff) |
peerInformSubscription
-rw-r--r-- | xmppServer.hs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/xmppServer.hs b/xmppServer.hs index 94a20c8a..7b220c95 100644 --- a/xmppServer.hs +++ b/xmppServer.hs | |||
@@ -680,6 +680,14 @@ resolvedFromRoster doit u = do | |||
680 | addr <- liftMT $ resolvePeer h | 680 | addr <- liftMT $ resolvePeer h |
681 | return (mu,PeerKey addr) | 681 | return (mu,PeerKey addr) |
682 | 682 | ||
683 | clientCons state ktc u = do | ||
684 | mlp <- atomically $ do | ||
685 | cmap <- readTVar $ clientsByUser state | ||
686 | return $ Map.lookup u cmap | ||
687 | let ks = do lp <- maybeToList mlp | ||
688 | Map.keys (networkClients lp) | ||
689 | return $ mapMaybe (flip Map.lookup ktc) ks | ||
690 | |||
683 | peerSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () | 691 | peerSubscriptionRequest :: PresenceState -> IO () -> ConnectionKey -> Stanza -> TChan Stanza -> IO () |
684 | peerSubscriptionRequest state fail k stanza chan = do | 692 | peerSubscriptionRequest state fail k stanza chan = do |
685 | putStrLn $ "Handling pending subscription from remote" | 693 | putStrLn $ "Handling pending subscription from remote" |
@@ -722,12 +730,8 @@ peerSubscriptionRequest state fail k stanza chan = do | |||
722 | -- contact ∉ subscribers & contact ∈ pending --> SHOULD NOT | 730 | -- contact ∉ subscribers & contact ∈ pending --> SHOULD NOT |
723 | when (not already_pending) $ do | 731 | when (not already_pending) $ do |
724 | -- contact ∉ subscribers & contact ∉ pending --> MUST | 732 | -- contact ∉ subscribers & contact ∉ pending --> MUST |
725 | mlp <- atomically $ do | 733 | |
726 | cmap <- readTVar $ clientsByUser state | 734 | chans <- clientCons state ktc u |
727 | return $ Map.lookup u cmap | ||
728 | let ks = do lp <- maybeToList mlp | ||
729 | Map.keys (networkClients lp) | ||
730 | chans = mapMaybe (flip Map.lookup ktc) ks | ||
731 | forM_ chans $ \Conn { connChan=chan } -> do | 735 | forM_ chans $ \Conn { connChan=chan } -> do |
732 | -- send to clients | 736 | -- send to clients |
733 | -- TODO: interested/available clients only? | 737 | -- TODO: interested/available clients only? |
@@ -820,9 +824,21 @@ peerInformSubscription state fail k stanza = do | |||
820 | , ConfigFiles.modifyBuddies ) | 824 | , ConfigFiles.modifyBuddies ) |
821 | addToRosterFile addf user from'' addrs | 825 | addToRosterFile addf user from'' addrs |
822 | removeFromRosterFile remf user from'' addrs | 826 | removeFromRosterFile remf user from'' addrs |
823 | -- TODO | 827 | |
824 | -- send update to clients | 828 | ktc <- atomically $ readTVar (keyToChan state) |
825 | return () | 829 | flip (maybe fail) (Map.lookup k ktc) |
830 | $ \Conn { auxAddr=laddr } -> do | ||
831 | hostname <- textHostName | ||
832 | let to' = unsplitJID (Just user, hostname, Nothing) | ||
833 | (_,fromtup) <- rewriteJIDForClient laddr from | ||
834 | chans <- clientCons state ktc user | ||
835 | forM_ chans $ \Conn { connChan=chan } -> do | ||
836 | update <- makeRosterUpdate to' from relationship | ||
837 | sendModifiedStanzaToClient update chan | ||
838 | dup <- cloneStanza stanza | ||
839 | sendModifiedStanzaToClient dup { stanzaFrom = Just $ unsplitJID fromtup | ||
840 | , stanzaTo = Just to' } | ||
841 | chan | ||
826 | 842 | ||
827 | main = runResourceT $ do | 843 | main = runResourceT $ do |
828 | state <- liftIO . atomically $ do | 844 | state <- liftIO . atomically $ do |