summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ToxToXMPP.hs16
1 files changed, 12 insertions, 4 deletions
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index 5495f5ad..367e5bf7 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -103,12 +103,15 @@ key2jid nospam key = T.pack $ show $ NoSpamId nsp key
103type JabberClients = Map.Map ConnectionKey PerClient 103type JabberClients = Map.Map ConnectionKey PerClient
104 104
105data PerClient = PerClient 105data PerClient = PerClient
106 { 106 { pcDeliveredFRs :: TVar (Set.Set Tox.FriendRequest)
107 } 107 }
108 108
109initPerClient :: STM PerClient 109initPerClient :: STM PerClient
110initPerClient = do 110initPerClient = do
111 return PerClient {} 111 frs <- newTVar Set.empty
112 return PerClient
113 { pcDeliveredFRs = frs
114 }
112 115
113data ToxToXMPP = ToxToXMPP 116data ToxToXMPP = ToxToXMPP
114 { txAnnouncer :: Announcer 117 { txAnnouncer :: Announcer
@@ -130,7 +133,7 @@ dispatch tx (OnionRouted theirkey (OnionFriendRequest fr) ) = do
130 , txPresence = st } = tx 133 , txPresence = st } = tx
131 k2c <- atomically $ do 134 k2c <- atomically $ do
132 refs <- readTVar (accountExtra acnt) 135 refs <- readTVar (accountExtra acnt)
133 k2c <- Map.filterWithKey (\k _ -> isJust $ k `Map.lookup` refs) <$> readTVar (keyToChan st) 136 k2c <- Map.intersectionWith (,) refs <$> readTVar (keyToChan st)
134 clients <- readTVar (clients st) 137 clients <- readTVar (clients st)
135 return $ Map.intersectionWith (,) k2c clients 138 return $ Map.intersectionWith (,) k2c clients
136 -- TODO: Below we're using a hard coded default as their jabber user id. 139 -- TODO: Below we're using a hard coded default as their jabber user id.
@@ -139,7 +142,12 @@ dispatch tx (OnionRouted theirkey (OnionFriendRequest fr) ) = do
139 -- after a zero-termination, or as visible text (nospam:...). 142 -- after a zero-termination, or as visible text (nospam:...).
140 let default_nospam = 0x6a7a27fc -- big-endian base64: anon/A== 143 let default_nospam = 0x6a7a27fc -- big-endian base64: anon/A==
141 theirjid = key2jid default_nospam theirkey 144 theirjid = key2jid default_nospam theirkey
142 forM_ k2c $ \(conn,client) -> do 145 forM_ k2c $ \((PerClient{pcDeliveredFRs},conn),client) -> do
146 alreadyDelivered <- atomically $ do
147 frs <- readTVar pcDeliveredFRs
148 writeTVar pcDeliveredFRs $ Set.insert fr frs
149 return $ Set.member fr frs
150 when (not alreadyDelivered) $ do
143 self <- localJID (clientUser client) (clientProfile client) (clientResource client) 151 self <- localJID (clientUser client) (clientProfile client) (clientResource client)
144 ask <- presenceSolicitation theirjid self 152 ask <- presenceSolicitation theirjid self
145 -- TODO Send friend-request text as an instant message or at least 153 -- TODO Send friend-request text as an instant message or at least