fedi/src/Fedi/Routes/Follow.hs

44 lines
1.2 KiB
Haskell

module Fedi.Routes.Follow where
import Data.Aeson qualified as A
import Fedi.Helpers
import Fedi.Types
import Fedi.Types.Helpers
import Fedi.UserDetails
import Fedi.Routes.Helpers
import Web.Twain qualified as Twain
import Web.Twain.Types qualified as Twain
-- * Followers
matchFollowers :: UserDetails -> Twain.PathPattern
matchFollowers details =
fromString ("/" <> details.username <> "/followers")
handleFollowers :: UserDetails -> Twain.ResponderM b
handleFollowers details = do
let
collection :: Collection ()
collection =
emptyUnorderedCollection
{ id = Just $ ObjectId $ actorUrl details <> "/followers"
, summary = Just $ fromString $ details.username <> "'s followers"
}
Twain.send $ jsonLD (A.encode collection)
-- * Following
matchFollowing :: UserDetails -> Twain.PathPattern
matchFollowing details =
fromString ("/" <> details.username <> "/following")
handleFollowing :: UserDetails -> Twain.ResponderM b
handleFollowing details = do
let
collection :: Collection ()
collection =
emptyUnorderedCollection
{ id = Just $ ObjectId $ actorUrl details <> "/following"
, summary = Just $ fromString $ details.username <> " is following"
}
Twain.send $ jsonLD (A.encode collection)