Add support for PGP keys on the h-card - can support an arbitrary number of keys, although I only have one

This commit is contained in:
Danielle McLean 2017-10-04 09:09:39 +11:00
parent 2b4822093a
commit 484609fb8b
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
4 changed files with 191 additions and 0 deletions

View file

@ -6,6 +6,7 @@ module Widget.Hcard (hcard) where
import Import
import Data.Maybe (fromJust)
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Network.Libravatar as L
entityToTuple :: Entity t -> (Key t, t)
@ -17,6 +18,13 @@ arrangeProfiles sites profiles = sortBy icon $ zip profileSites profiles
profileSites = findSite <$> profiles
icon = comparing $ siteIcon . fst
prettyPgp :: PgpKey -> Text
prettyPgp = T.unwords . T.chunksOf 4 . pgpKeyFingerprint
routeFromPgp :: PgpKey -> Route App
routeFromPgp PgpKey { pgpKeyFingerprint = f, pgpKeyHash = h } =
StaticR $ StaticRoute ["pgp", f, h, T.takeEnd 8 f ++ ".asc"] []
hcard :: Entity User -> Widget
hcard (Entity userId user) = do
maybeAvatar <- liftIO $ L.avatarUrl (L.Email $ userEmail user) def { L.optSecure = True, L.optSize = L.Size 512 }
@ -24,4 +32,5 @@ hcard (Entity userId user) = do
profiles <- map entityVal <$> selectList [ProfileUserId ==. userId] []
sites <- M.fromList . map entityToTuple <$> selectList [SiteId <-. (profileSiteId <$> profiles)] []
return $ arrangeProfiles sites profiles
pgpKeys <- handlerToWidget . runDB $ map entityVal <$> selectList [PgpKeyUserId ==. userId] []
$(widgetFile "hcard")