diff options
author | Joey Hess <joey@kitenet.net> | 2012-11-02 21:23:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-11-02 21:23:58 -0400 |
commit | d08835e5eb42f39374308973aa6feb2e36b7c87f (patch) | |
tree | aca997b427182ed4f5752175ee8c0a132cbe5498 | |
parent | 98ae9cb53d3e16a4de24a5a8e6d0fb172f33f8a9 (diff) |
ignore our own client presence
-rw-r--r-- | Assistant/Threads/PushNotifier.hs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/Assistant/Threads/PushNotifier.hs b/Assistant/Threads/PushNotifier.hs index 8830d9459..bdb9e1e12 100644 --- a/Assistant/Threads/PushNotifier.hs +++ b/Assistant/Threads/PushNotifier.hs @@ -35,12 +35,11 @@ pushNotifierThread = NamedThread "PushNotifier" $ do ioupdatebuddies <- asIO1 $ \p -> do updateBuddyList (updateBuddies p) <<~ buddyList debug =<< map show <$> getBuddyList <<~ buddyList + ioemptybuddies <- asIO $ + updateBuddyList (const noBuddies) <<~ buddyList ioclient <- asIO $ - xmppClient iowaitpush iodebug iopull ioupdatebuddies + xmppClient iowaitpush iodebug iopull ioupdatebuddies ioemptybuddies forever $ do - {- The buddy list starts empty each time the client connects, - - so that stale info is not retained. -} - updateBuddyList (const noBuddies) <<~ buddyList tid <- liftIO $ forkIO ioclient waitRestart liftIO $ killThread tid @@ -50,8 +49,9 @@ xmppClient -> ([String] -> IO ()) -> ([UUID] -> IO ()) -> (Presence -> IO ()) + -> IO () -> Assistant () -xmppClient iowaitpush iodebug iopull ioupdatebuddies = do +xmppClient iowaitpush iodebug iopull ioupdatebuddies ioemptybuddies = do v <- liftAnnex getXMPPCreds case v of Nothing -> noop @@ -61,10 +61,13 @@ xmppClient iowaitpush iodebug iopull ioupdatebuddies = do void $ connectXMPP c $ \jid -> do fulljid <- bindJID jid liftIO $ iodebug ["XMPP connected", show fulljid] + {- The buddy list starts empty each time the client + - connects, so that stale info is not retained. -} + liftIO ioemptybuddies putStanza $ gitAnnexPresence gitAnnexSignature s <- getSession _ <- liftIO $ forkIO $ void $ runXMPP s $ - receivenotifications + receivenotifications fulljid sendnotifications now <- getCurrentTime if diffUTCTime now starttime > 300 @@ -78,16 +81,18 @@ xmppClient iowaitpush iodebug iopull ioupdatebuddies = do sendnotifications = forever $ do us <- liftIO iowaitpush putStanza $ gitAnnexPresence $ encodePushNotification us - receivenotifications = forever $ do + receivenotifications fulljid = forever $ do s <- getStanza liftIO $ iodebug ["received XMPP:", show s] case s of - ReceivedPresence p -> do - liftIO $ ioupdatebuddies p - when (isGitAnnexPresence p) $ - liftIO $ iopull $ concat $ catMaybes $ - map decodePushNotification $ - presencePayloads p + ReceivedPresence p@(Presence { presenceFrom = from }) + | from == Just fulljid -> noop + | otherwise -> do + liftIO $ ioupdatebuddies p + when (isGitAnnexPresence p) $ + liftIO $ iopull $ concat $ catMaybes $ + map decodePushNotification $ + presencePayloads p _ -> noop {- We only pull from one remote out of the set listed in the push |