only use one push attribute

When pushing to multiple UUIDs, combine them all into a single push
attribute.
This commit is contained in:
Joey Hess 2012-10-25 13:29:18 -04:00
parent 91c0c7b9ef
commit 8c9c8e3110
2 changed files with 15 additions and 6 deletions

View file

@ -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