summaryrefslogtreecommitdiff
path: root/dht/Presence/Presence.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/Presence/Presence.hs')
-rw-r--r--dht/Presence/Presence.hs32
1 files changed, 18 insertions, 14 deletions
diff --git a/dht/Presence/Presence.hs b/dht/Presence/Presence.hs
index a09a517d..dcc76c5b 100644
--- a/dht/Presence/Presence.hs
+++ b/dht/Presence/Presence.hs
@@ -251,7 +251,11 @@ chooseResourceName state k (Remote addr) clientsNameForMe desired = do
251 flgs <- atomically $ newTVar 0 251 flgs <- atomically $ newTVar 0
252 profile <- fmap (fromMaybe ".") 252 profile <- fmap (fromMaybe ".")
253 $ forM ((,) <$> clientsNameForMe <*> toxManager state) $ \(wanted_profile0,toxman) -> 253 $ forM ((,) <$> clientsNameForMe <*> toxManager state) $ \(wanted_profile0,toxman) ->
254 case Text.splitAt 43 wanted_profile0 of 254 case splitLast4 wanted_profile0 of
255 ("*",".tox") -> do
256 dput XMisc $ "TODO: Match single tox key profile or generate first."
257 -- TODO: Match single tox key profile or generate first.
258 _todo
255 (pub,".tox") -> do 259 (pub,".tox") -> do
256 cdir <- ConfigFiles.configPath (L.fromChunks [Text.encodeUtf8 user]) "." "" 260 cdir <- ConfigFiles.configPath (L.fromChunks [Text.encodeUtf8 user]) "." ""
257#if !MIN_VERSION_directory(1,2,5) 261#if !MIN_VERSION_directory(1,2,5)
@@ -274,10 +278,6 @@ chooseResourceName state k (Remote addr) clientsNameForMe desired = do
274 -- fall back to the Unix account login. 278 -- fall back to the Unix account login.
275 dput XMisc "failed to find tox secret" 279 dput XMisc "failed to find tox secret"
276 return "." 280 return "."
277 ("*.tox","") -> do
278 dput XMisc $ "TODO: Match single tox key profile or generate first."
279 -- TODO: Match single tox key profile or generate first.
280 _todo
281 _ -> return "." 281 _ -> return "."
282 let client = ClientState { clientResource = maybe "fallback" id mtty 282 let client = ClientState { clientResource = maybe "fallback" id mtty
283 , clientUser = user 283 , clientUser = user
@@ -361,7 +361,7 @@ rosterGetStuff what state k = forClient state k (return [])
361 PresenceState { server = sv } -> do 361 PresenceState { server = sv } -> do
362 let conns = manager state $ clientProfile client 362 let conns = manager state $ clientProfile client
363 -- Grok peers to associate with from the roster: 363 -- Grok peers to associate with from the roster:
364 let isTox = do (me , ".tox") <- Just $ Text.splitAt 43 (clientProfile client) 364 let isTox = do (me , ".tox") <- Just $ splitLast4 (clientProfile client)
365 return me 365 return me
366 noToxUsers (u,h,r) 366 noToxUsers (u,h,r)
367 | Text.isSuffixOf ".tox" h = unsplitJID (Nothing,h,r) 367 | Text.isSuffixOf ".tox" h = unsplitJID (Nothing,h,r)
@@ -373,8 +373,8 @@ rosterGetStuff what state k = forClient state k (return [])
373 let policySetter = fromMaybe (Connection.setPolicy conns host) $ do 373 let policySetter = fromMaybe (Connection.setPolicy conns host) $ do
374 isTox 374 isTox
375 toxman <- toxManager state 375 toxman <- toxManager state
376 (them, ".tox") <- Just $ Text.splitAt 43 host 376 (them, ".tox") <- Just $ splitLast4 host
377 meid <- readMaybe $ Text.unpack $ Text.take 43 (clientProfile client) 377 meid <- readMaybe $ Text.unpack $ Text.dropEnd 4 (clientProfile client)
378 themid <- readMaybe $ Text.unpack them 378 themid <- readMaybe $ Text.unpack them
379 return $ Connection.setPolicy (toxConnections toxman) 379 return $ Connection.setPolicy (toxConnections toxman)
380 (ToxContact meid themid) 380 (ToxContact meid themid)
@@ -547,7 +547,7 @@ eofConn state saddr cdta = do
547 Right (k,_) -> do 547 Right (k,_) -> do
548 forClient state k (return ()) $ \client -> do 548 forClient state k (return ()) $ \client -> do
549 forM_ (toxManager state) $ \toxman -> do 549 forM_ (toxManager state) $ \toxman -> do
550 case Text.splitAt 43 (clientProfile client) of 550 case splitLast4 (clientProfile client) of
551 (pub,".tox") -> deactivateAccount toxman k (clientProfile client) 551 (pub,".tox") -> deactivateAccount toxman k (clientProfile client)
552 _ -> return () 552 _ -> return ()
553 stanza <- makePresenceStanza "jabber:server" Nothing Offline 553 stanza <- makePresenceStanza "jabber:server" Nothing Offline
@@ -665,12 +665,12 @@ deliverMessage state fail msg =
665 -- In case the client sends us a lower-cased version of the base64 665 -- In case the client sends us a lower-cased version of the base64
666 -- tox key hostname, we resolve it by comparing it with roster entries. 666 -- tox key hostname, we resolve it by comparing it with roster entries.
667 xs <- getBuddiesAndSolicited state (clientProfile client) $ \case 667 xs <- getBuddiesAndSolicited state (clientProfile client) $ \case
668 rh | (_,".tox") <- Text.splitAt 43 rh 668 rh | (_,".tox") <- splitLast4 rh
669 , Text.toLower rh == Text.toLower th 669 , Text.toLower rh == Text.toLower th
670 -> return True 670 -> return True
671 _ -> return False 671 _ -> return False
672 fmap join $ forM (listToMaybe xs) $ \(_,rmu,_,h) -> do 672 fmap join $ forM (listToMaybe xs) $ \(_,rmu,_,h) -> do
673 let (them,_) = Text.splitAt 43 h 673 let (them,_) = splitLast4 h
674 maddr <- resolveToxPeer toxman me them 674 maddr <- resolveToxPeer toxman me them
675 let to' = unsplitJID (mu,h,rsc) 675 let to' = unsplitJID (mu,h,rsc)
676 return $ fmap (to',) maddr 676 return $ fmap (to',) maddr
@@ -1168,17 +1168,21 @@ clientSubscriptionRequest state fail k stanza chan = do
1168 (connChan con) 1168 (connChan con)
1169 let policySetter = fromMaybe (Connection.setPolicy conns h) $ do 1169 let policySetter = fromMaybe (Connection.setPolicy conns h) $ do
1170 (toxman,_,_) <- weAreTox state client h 1170 (toxman,_,_) <- weAreTox state client h
1171 meid <- readMaybe $ Text.unpack $ Text.take 43 (clientProfile client) 1171 meid <- readMaybe $ Text.unpack $ case splitLast4 (clientProfile client) of
1172 (h,".tox") -> h
1173 _ -> clientProfile client
1172 themid <- readMaybe $ Text.unpack h 1174 themid <- readMaybe $ Text.unpack h
1173 Just $ Connection.setPolicy (toxConnections toxman) (ToxContact meid themid) 1175 Just $ Connection.setPolicy (toxConnections toxman) (ToxContact meid themid)
1174 -- Add peer if we are not already associated ... 1176 -- Add peer if we are not already associated ...
1175 policySetter Connection.TryingToConnect 1177 policySetter Connection.TryingToConnect
1176 1178
1179splitLast4 h = Text.splitAt (Text.length h - 4) h
1180
1177weAreTox :: PresenceState stat -> ClientState -> Text -> Maybe (ToxManager ClientAddress,Text{- me -},Text{- them -}) 1181weAreTox :: PresenceState stat -> ClientState -> Text -> Maybe (ToxManager ClientAddress,Text{- me -},Text{- them -})
1178weAreTox state client h = do 1182weAreTox state client h = do
1179 toxman <- toxManager state 1183 toxman <- toxManager state
1180 (me , ".tox") <- Just $ Text.splitAt 43 (clientProfile client) 1184 (me , ".tox") <- Just $ splitLast4 (clientProfile client)
1181 (them, ".tox") <- Just $ Text.splitAt 43 h 1185 (them, ".tox") <- Just $ splitLast4 h
1182 return (toxman,me,them) 1186 return (toxman,me,them)
1183 1187
1184resolvedFromRoster 1188resolvedFromRoster