summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-07-06 05:24:37 -0400
committerJoe Crayne <joe@jerkface.net>2018-07-06 05:25:36 -0400
commitea3f4e6543b6dddd94898c945a8ad2c24a46ae77 (patch)
tree6bff1ac5a1c7ff97cf6fb9387bf1cffe201d6a3f /Presence
parent95d6ae45e07707eb93f083ecf02d8f0df0015496 (diff)
tox-to-xmpp: presence updates.
Diffstat (limited to 'Presence')
-rw-r--r--Presence/Presence.hs24
1 files changed, 19 insertions, 5 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index 4ca49f78..59926d13 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -178,7 +178,7 @@ data LocalPresence = LocalPresence
178 } 178 }
179 179
180data RemotePresence = RemotePresence 180data RemotePresence = RemotePresence
181 { resources :: Map Text Stanza 181 { resources :: Map ResourceName Stanza
182 -- , localSubscribers :: Map Text () 182 -- , localSubscribers :: Map Text ()
183 -- ^ subset of clientsByUser who should be 183 -- ^ subset of clientsByUser who should be
184 -- notified about this presence. 184 -- notified about this presence.
@@ -764,7 +764,14 @@ informPeerPresence state k stanza = do
764 -- Presence must indicate full JID with resource... 764 -- Presence must indicate full JID with resource...
765 dput XJabber $ "xmppInformPeerPresence checking from address..." 765 dput XJabber $ "xmppInformPeerPresence checking from address..."
766 forM_ (stanzaFrom stanza) $ \from -> do 766 forM_ (stanzaFrom stanza) $ \from -> do
767 let (muser,h,mresource) = splitJID from 767 let (muser0,h,mresource0) = splitJID from
768 -- We'll allow the case that user and resource are simultaneously
769 -- absent. They will be stored in the remotesByPeer map using the
770 -- empty string. This is to accomodate the tox protocol which didn't
771 -- anticipate a single peer would have multiple users or front-ends.
772 (muser,mresource) = case (muser0,mresource0) of
773 (Nothing,Nothing) -> (Just "", Just "")
774 _ -> (muser0,mresource0)
768 dput XJabber $ "xmppInformPeerPresence from = " ++ show from 775 dput XJabber $ "xmppInformPeerPresence from = " ++ show from
769 -- forM_ mresource $ \resource -> do 776 -- forM_ mresource $ \resource -> do
770 forM_ muser $ \user -> do 777 forM_ muser $ \user -> do
@@ -806,15 +813,22 @@ informPeerPresence state k stanza = do
806 con <- liftMaybe $ Map.lookup ck ktc 813 con <- liftMaybe $ Map.lookup ck ktc
807 return (ck,con,client) 814 return (ck,con,client)
808 dput XJabber $ "xmppInformPeerPresence (length clients="++show (length clients)++")" 815 dput XJabber $ "xmppInformPeerPresence (length clients="++show (length clients)++")"
816 (ctyp,cprof) <- atomically $ do
817 mconn <- Map.lookup k <$> readTVar (pkeyToChan state)
818 return $ fromMaybe (XMPP,".") $ do
819 ConnectionData _ ctyp cprof <- auxData <$> mconn
820 return (ctyp,cprof)
809 forM_ clients $ \(ck,con,client) -> do 821 forM_ clients $ \(ck,con,client) -> do
810 -- (TODO: appropriately authorized clients only.) 822 -- (TODO: appropriately authorized clients only.)
811 -- For now, all "available" clients (available = sent initial presence) 823 -- For now, all "available" clients (available = sent initial presence)
812 is_avail <- atomically $ clientIsAvailable client 824 is_avail <- atomically $ clientIsAvailable client
813 when is_avail $ do 825 when is_avail $ do
814 dput XJabber $ "reversing for client: " ++ show from 826 dput XJabber $ "reversing for client: " ++ show from
815 froms <- do -- flip (maybe $ return [from]) k . const $ do 827 froms <- case ctyp of
816 (_,trip) <- multiplyJIDForClient ck from 828 Tox | clientProfile client == cprof -> return [from]
817 return (map unsplitJID trip) 829 _ -> do -- flip (maybe $ return [from]) k . const $ do
830 (_,trip) <- multiplyJIDForClient ck from
831 return (map unsplitJID trip)
818 832
819 dput XJabber $ "sending to client: " ++ show (stanzaType stanza,froms) 833 dput XJabber $ "sending to client: " ++ show (stanzaType stanza,froms)
820 forM_ froms $ \from' -> do 834 forM_ froms $ \from' -> do