fedi/app/Routes/Inbox/Accept.hs
2024-12-17 10:47:00 +02:00

38 lines
1.1 KiB
Haskell

module Routes.Inbox.Accept where
import Control.Concurrent (threadDelay)
import Control.Concurrent.Async qualified as Async
import Control.Logger.Simple qualified as Log
import DB
import Fedi qualified as Fedi
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 1 second before accepting follow..."
threadDelay 1000000 -- 1 second
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 ()