summaryrefslogtreecommitdiff
path: root/ToxManager.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-24 19:17:44 -0400
committerjoe <joe@jerkface.net>2018-06-24 19:18:01 -0400
commit0cd6528e5d87172429d3ea9969ebe2593dc47a5e (patch)
tree31fdc716546352e7b6946fca69d5d5c6395e0efe /ToxManager.hs
parentf78efaaf6fd64c77c0fd778a7666c40782ce9ec4 (diff)
xmpp: allow server to change it's name (important for tox peers).
Diffstat (limited to 'ToxManager.hs')
-rw-r--r--ToxManager.hs28
1 files changed, 10 insertions, 18 deletions
diff --git a/ToxManager.hs b/ToxManager.hs
index 360f78e8..d16a5d2e 100644
--- a/ToxManager.hs
+++ b/ToxManager.hs
@@ -44,6 +44,8 @@ toxAnnounceSendData tox pubkey token = \case
44 ni 44 ni
45 Nothing -> return Nothing 45 Nothing -> return Nothing
46 46
47akeyAccountActive :: Announcer -> Tox.NodeId{- our public tox key -} -> AnnounceKey
48akeyAccountActive announcer pubid = packAnnounceKey announcer $ "toxid:" ++ show pubid
47 49
48-- | 50-- |
49-- 51--
@@ -78,7 +80,7 @@ toxman announcer toxbkts tox presence = ToxManager
78 forM_ newlyActive $ \nearNodes -> do 80 forM_ newlyActive $ \nearNodes -> do
79 -- Schedule recurring announce. 81 -- Schedule recurring announce.
80 -- 82 --
81 let akey = packAnnounceKey announcer $ "toxid:" ++ show pubid 83 let akey = akeyAccountActive announcer pubid
82 scheduleAnnounce announcer 84 scheduleAnnounce announcer
83 akey 85 akey
84 (AnnounceMethod (toxQSearch tox) 86 (AnnounceMethod (toxQSearch tox)
@@ -101,33 +103,23 @@ toxman announcer toxbkts tox presence = ToxManager
101 macnt <- HashMap.lookup pubid <$> readTVar accounts 103 macnt <- HashMap.lookup pubid <$> readTVar accounts
102 rs <- fromMaybe Map.empty <$> mapM (readTVar . accountExtra) macnt 104 rs <- fromMaybe Map.empty <$> mapM (readTVar . accountExtra) macnt
103 forM_ macnt $ \acnt -> do 105 forM_ macnt $ \acnt -> do
106 -- Remove this xmpp client /k/ from the set holding this
107 -- account active.
104 modifyTVar' (accountExtra acnt) $ Map.delete k 108 modifyTVar' (accountExtra acnt) $ Map.delete k
105 return rs 109 return rs
106 if (Map.null $ Map.delete k refs) then do 110 if (Map.null $ Map.delete k refs) then do
107 -- TODO 111 let akey = akeyAccountActive announcer pubid
108 -- If this is the last reference to a non-connected contact:
109 -- Stop the recurring search for that contact
110 --
111 -- Stop recurring announce.
112 let akey = packAnnounceKey announcer ("toxid:" ++ show pubid)
113 fmap Just $ forM toxbkts $ \(nm,bkts) -> do 112 fmap Just $ forM toxbkts $ \(nm,bkts) -> do
114 return (akey,bkts) 113 return (akey,bkts)
115 else return Nothing 114 else return Nothing
116 forM_ bStopped $ \kbkts -> do 115 forM_ bStopped $ \kbkts -> do
117 dput XMan $ "toxman DECTIVATE (todo) 3 " ++ show pubname
118 let Just pubid = mpubid 116 let Just pubid = mpubid
119 pub = Tox.id2key pubid 117 pub = Tox.id2key pubid
118 -- Stop the announce-toxid task for this account. Note that other
119 -- announced tasks will be stopped by the forkAccountWatcher thread
120 -- when it terminates.
120 forM_ kbkts $ \(akey,bkts) -> do 121 forM_ kbkts $ \(akey,bkts) -> do
121 cancel announcer 122 cancel announcer akey
122 akey
123 {-
124 (AnnounceMethod (toxQSearch tox)
125 (Right $ toxAnnounceSendData tox)
126 bkts
127 pubid
128 toxAnnounceInterval)
129 pub
130 -}
131 123
132 , setToxConnectionPolicy = \me them p -> do 124 , setToxConnectionPolicy = \me them p -> do
133 let m = do meid <- readMaybe $ T.unpack $ T.take 43 me 125 let m = do meid <- readMaybe $ T.unpack $ T.take 43 me