52 lines
1.2 KiB
Haskell
52 lines
1.2 KiB
Haskell
module Fedi.UserDetails (
|
|
module Fedi.UserDetails,
|
|
module Export,
|
|
) where
|
|
|
|
import Data.Aeson qualified as A
|
|
import Data.Foldable as Export
|
|
import Data.Maybe as Export (fromMaybe, listToMaybe, maybeToList)
|
|
import Data.String as Export (fromString)
|
|
import Data.Text as Export (Text)
|
|
import Data.ByteString as Export (ByteString)
|
|
import Data.Text qualified as T
|
|
import Data.Text.Encoding qualified as T
|
|
import Data.Time as Export (UTCTime)
|
|
import Data.Traversable as Export
|
|
import GHC.Generics as Export (Generic)
|
|
|
|
type Url = String
|
|
|
|
type Domain = String
|
|
|
|
type Username = String
|
|
|
|
newtype Pem = Pem T.Text
|
|
deriving (Show, Eq)
|
|
deriving (A.FromJSON) via T.Text
|
|
|
|
pemToBS :: Pem -> ByteString
|
|
pemToBS (Pem txt) = T.encodeUtf8 txt
|
|
|
|
instance A.ToJSON Pem where
|
|
toJSON (Pem pem) = A.String pem
|
|
|
|
data UserDetails
|
|
= UserDetails
|
|
{ domain :: Domain
|
|
, username :: String
|
|
, name :: String
|
|
, summary :: String
|
|
, icon :: Url
|
|
, image :: Url
|
|
, publicPem :: Pem
|
|
, privatePem :: FilePath
|
|
}
|
|
deriving (Show, Eq, Generic, A.FromJSON)
|
|
|
|
actorUrl :: UserDetails -> Url
|
|
actorUrl details =
|
|
"https://" <> details.domain <> "/" <> details.username
|
|
|
|
fullmention :: UserDetails -> String
|
|
fullmention details = "@" <> details.username <> "@" <> details.domain
|