fedi/app/Routes/Inbox/Accept.hs
2024-11-08 00:26:40 +02:00

36 lines
1 KiB
Haskell

module Routes.Inbox.Accept where
import DB
import Fedi qualified as Fedi
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async qualified as Async
import Control.Logger.Simple qualified as Log
acceptRequest
:: Fedi.UserDetails
-> Fedi.Link
-> Fedi.AnyActivity
-> ((Int64 -> IO ()) -> IO a)
-> IO ()
acceptRequest details actor activity operation = do
_ <- liftIO $ Async.async do
Log.logDebug "Waiting 10 seconds before accepting follow..."
threadDelay 10000000 -- 10 seconds
let
callback =
( \(opid :: DB.Int64) -> do
result <- Fedi.sendPost
details
(actor.unwrap <> "/inbox")
( Fedi.makeAccept Fedi.MkAccept
{ Fedi.acceptId =
Fedi.actorUrl details <> "/accepts/requests/" <> show opid
, Fedi.acceptingActorUrl = Fedi.Link $ Fedi.actorUrl details
, Fedi.acceptedActivity = activity
}
)
Log.logDebug (Fedi.pShow result)
)
do
operation callback
pure ()