summaryrefslogtreecommitdiff
path: root/Assistant/Threads/PushNotifier.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-25 13:29:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-25 13:31:45 -0400
commit8a12e78e0bff680eb913ec2140da909da74040a0 (patch)
treedd6de1b2b52bdd4b6d05aae3cfb92d86b6ba849f /Assistant/Threads/PushNotifier.hs
parenta63dabefa9f4c6f104b9180e7cb5d26f6cefc782 (diff)
only use one push attribute
When pushing to multiple UUIDs, combine them all into a single push attribute.
Diffstat (limited to 'Assistant/Threads/PushNotifier.hs')
-rw-r--r--Assistant/Threads/PushNotifier.hs14
1 files changed, 11 insertions, 3 deletions
diff --git a/Assistant/Threads/PushNotifier.hs b/Assistant/Threads/PushNotifier.hs
index 872b18994..84fe4952a 100644
--- a/Assistant/Threads/PushNotifier.hs
+++ b/Assistant/Threads/PushNotifier.hs
@@ -57,8 +57,9 @@ pushNotifierThread st dstatus pushnotifier = NamedThread thisThread $ do
sendnotifications = forever $ do
us <- liftIO $ waitPush pushnotifier
let payload = [extendedAway, encodePushNotification us]
- putStanza $ (emptyPresence PresenceAvailable)
+ let notification = (emptyPresence PresenceAvailable)
{ presencePayloads = payload }
+ putStanza notification
receivenotifications = forever $ do
s <- getStanza
@@ -117,17 +118,24 @@ gitAnnexTagName = Name (T.pack "git-annex") (Just $ T.pack "git-annex") Nothing
pushAttr :: Name
pushAttr = Name (T.pack "push") Nothing Nothing
+uuidSep :: T.Text
+uuidSep = T.pack ","
+
{- git-annex tag with one push attribute per UUID pushed to. -}
encodePushNotification :: [UUID] -> Element
encodePushNotification us = Element gitAnnexTagName
- [(pushAttr, map (ContentText . T.pack . fromUUID) us)] []
+ [(pushAttr, [ContentText pushvalue])] []
+ where
+ pushvalue = T.intercalate uuidSep $
+ map (T.pack . fromUUID) us
decodePushNotification :: Element -> Maybe [UUID]
decodePushNotification (Element name attrs _nodes)
| name == gitAnnexTagName && not (null us) = Just us
| otherwise = Nothing
where
- us = concatMap (map (toUUID . T.unpack . fromContent) . snd) $
+ us = map (toUUID . T.unpack) $
+ concatMap (T.splitOn uuidSep . T.concat . map fromContent . snd) $
filter ispush attrs
ispush (k, _) = k == pushAttr
fromContent (ContentText t) = t