From 0cd6528e5d87172429d3ea9969ebe2593dc47a5e Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 24 Jun 2018 19:17:44 -0400 Subject: xmpp: allow server to change it's name (important for tox peers). --- ToxManager.hs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'ToxManager.hs') 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 ni Nothing -> return Nothing +akeyAccountActive :: Announcer -> Tox.NodeId{- our public tox key -} -> AnnounceKey +akeyAccountActive announcer pubid = packAnnounceKey announcer $ "toxid:" ++ show pubid -- | -- @@ -78,7 +80,7 @@ toxman announcer toxbkts tox presence = ToxManager forM_ newlyActive $ \nearNodes -> do -- Schedule recurring announce. -- - let akey = packAnnounceKey announcer $ "toxid:" ++ show pubid + let akey = akeyAccountActive announcer pubid scheduleAnnounce announcer akey (AnnounceMethod (toxQSearch tox) @@ -101,33 +103,23 @@ toxman announcer toxbkts tox presence = ToxManager macnt <- HashMap.lookup pubid <$> readTVar accounts rs <- fromMaybe Map.empty <$> mapM (readTVar . accountExtra) macnt forM_ macnt $ \acnt -> do + -- Remove this xmpp client /k/ from the set holding this + -- account active. modifyTVar' (accountExtra acnt) $ Map.delete k return rs if (Map.null $ Map.delete k refs) then do - -- TODO - -- If this is the last reference to a non-connected contact: - -- Stop the recurring search for that contact - -- - -- Stop recurring announce. - let akey = packAnnounceKey announcer ("toxid:" ++ show pubid) + let akey = akeyAccountActive announcer pubid fmap Just $ forM toxbkts $ \(nm,bkts) -> do return (akey,bkts) else return Nothing forM_ bStopped $ \kbkts -> do - dput XMan $ "toxman DECTIVATE (todo) 3 " ++ show pubname let Just pubid = mpubid pub = Tox.id2key pubid + -- Stop the announce-toxid task for this account. Note that other + -- announced tasks will be stopped by the forkAccountWatcher thread + -- when it terminates. forM_ kbkts $ \(akey,bkts) -> do - cancel announcer - akey - {- - (AnnounceMethod (toxQSearch tox) - (Right $ toxAnnounceSendData tox) - bkts - pubid - toxAnnounceInterval) - pub - -} + cancel announcer akey , setToxConnectionPolicy = \me them p -> do let m = do meid <- readMaybe $ T.unpack $ T.take 43 me -- cgit v1.2.3