module Fedi.Actor where import Data.Aeson qualified as A import Fedi.Types data Actor = Actor { id :: Url , name :: String , preferredUsername :: String , summary :: String , icon :: Url , publicKey :: PublicKey } deriving Show type ActorId = Url data ActorType = Person deriving Show data PublicKey = PublicKey { id :: Url , owner :: Url , publicKeyPem :: Pem } deriving Show makeActor :: UserDetails -> Actor makeActor details = let actor = actorUrl details in Actor { id = actor , name = details.name , preferredUsername = details.username , summary = details.summary , icon = details.icon , publicKey = PublicKey { id = actor <> "#main-key" , owner = actor , publicKeyPem = details.publicPem } } instance A.ToJSON Actor where toJSON actor = A.object [ "@context" A..= [ "https://www.w3.org/ns/activitystreams" :: String , "https://w3id.org/security/v1" ] , "id" A..= actor.id , "type" A..= Person , "name" A..= actor.name , "preferredUsername" A..= actor.preferredUsername , "summary" A..= actor.summary , "icon" A..= A.object [ "type" A..= ("Image" :: String) , "mediaType" A..= ("image/png" :: String) , "url" A..= actor.icon ] , "inbox" A..= (actor.id <> "/inbox") , "outbox" A..= (actor.id <> "/outbox") , "publicKey" A..= actor.publicKey ] instance A.ToJSON ActorType where toJSON Person = A.String "Person" instance A.ToJSON PublicKey where toJSON pk = A.object [ "id" A..= pk.id , "owner" A..= pk.owner , "publicKeyPem" A..= pk.publicKeyPem ]