summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-05-29 18:26:25 -0400
committerjoe <joe@jerkface.net>2018-05-29 18:26:25 -0400
commit71f7ca88339f1793f21fecbd36e84f6e18e915bd (patch)
tree506d1f2528d0271a55e64ef546edecb540fe6816 /examples
parent620fdb0a2a6a80427895e4a40b9de3ec792c8d7c (diff)
WIP: Deliver friend-request to xmpp client.
Diffstat (limited to 'examples')
-rw-r--r--examples/dhtd.hs16
1 files changed, 9 insertions, 7 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 60d60258..78090794 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -1216,23 +1216,24 @@ toxAnnounceInterval = 15
1216-- 1216--
1217-- These hooks will be invoked in order to connect to *.tox hosts in a user's 1217-- These hooks will be invoked in order to connect to *.tox hosts in a user's
1218-- XMPP roster. 1218-- XMPP roster.
1219toxman :: Announcer -> [(String,TVar (BucketList Tox.NodeInfo))] -> Tox.Tox -> ToxManager ConnectionKey 1219toxman :: Announcer -> [(String,TVar (BucketList Tox.NodeInfo))] -> Tox.Tox -> PresenceState -> ToxManager ConnectionKey
1220toxman announcer toxbkts tox = ToxManager 1220toxman announcer toxbkts tox presence = ToxManager
1221 { activateAccount = \k pubname seckey -> do 1221 { activateAccount = \k pubname seckey -> do
1222 hPutStrLn stderr $ "toxman ACTIVATE " ++ show (Tox.key2id $ toPublic seckey) 1222 hPutStrLn stderr $ "toxman ACTIVATE " ++ show (Tox.key2id $ toPublic seckey)
1223 let ContactInfo{ accounts } = Tox.toxContactInfo tox 1223 let ContactInfo{ accounts } = Tox.toxContactInfo tox
1224 pub = toPublic seckey 1224 pub = toPublic seckey
1225 pubid = Tox.key2id pub 1225 pubid = Tox.key2id pub
1226 newlyActive <- atomically $ do 1226 (mcon,newlyActive) <- atomically $ do
1227 macnt <- HashMap.lookup pubid <$> readTVar accounts 1227 macnt <- HashMap.lookup pubid <$> readTVar accounts
1228 acnt <- maybe (newAccount seckey) return macnt 1228 acnt <- maybe (newAccount seckey) return macnt
1229 rs <- readTVar $ clientRefs acnt 1229 rs <- readTVar $ clientRefs acnt
1230 writeTVar (clientRefs acnt) $! Set.insert k rs 1230 writeTVar (clientRefs acnt) $! Set.insert k rs
1231 modifyTVar accounts (HashMap.insert pubid acnt) 1231 modifyTVar accounts (HashMap.insert pubid acnt)
1232 mcon <- fmap ((,) acnt) . Map.lookup k <$> readTVar (keyToChan presence)
1232 if not (Set.null rs) 1233 if not (Set.null rs)
1233 then return [] 1234 then return (mcon,[])
1234 else do 1235 else do
1235 forM toxbkts $ \(nm,bkts) -> do 1236 fmap ((,) mcon) $ forM toxbkts $ \(nm,bkts) -> do
1236 akey <- packAnnounceKey announcer (nm ++ "id:" ++ show pubid) 1237 akey <- packAnnounceKey announcer (nm ++ "id:" ++ show pubid)
1237 return (akey,bkts) 1238 return (akey,bkts)
1238 forM_ newlyActive $ \(akey,bkts) -> do 1239 forM_ newlyActive $ \(akey,bkts) -> do
@@ -1246,8 +1247,8 @@ toxman announcer toxbkts tox = ToxManager
1246 pubid 1247 pubid
1247 toxAnnounceInterval) 1248 toxAnnounceInterval)
1248 pub 1249 pub
1249 -- 1250
1250 -- Schedule recurring search for all non-connected contacts. 1251 forM_ mcon $ \(acnt,conn) -> forkAccountWatcher acnt tox conn
1251 return () 1252 return ()
1252 , deactivateAccount = \k pubname -> do 1253 , deactivateAccount = \k pubname -> do
1253 bStopped <- fmap (fromMaybe False) $ atomically $ do 1254 bStopped <- fmap (fromMaybe False) $ atomically $ do
@@ -1628,6 +1629,7 @@ main = runResourceT $ liftBaseWith $ \resT -> do
1628 [ lookupBkts "tox4" toxdhts 1629 [ lookupBkts "tox4" toxdhts
1629 , lookupBkts "tox6" toxdhts 1630 , lookupBkts "tox6" toxdhts
1630 ] 1631 ]
1632
1631 state <- newPresenceState cw (toxman announcer toxbkts <$> mbtox) serverVar 1633 state <- newPresenceState cw (toxman announcer toxbkts <$> mbtox) serverVar
1632 1634
1633 sv <- resT $ xmppServer (presenceHooks state (verbosity opts) (Just cport) (Just sport)) 1635 sv <- resT $ xmppServer (presenceHooks state (verbosity opts) (Just cport) (Just sport))