diff --git a/src/Hash2Pub/PostService.hs b/src/Hash2Pub/PostService.hs index 99a9efb..797a9e6 100644 --- a/src/Hash2Pub/PostService.hs +++ b/src/Hash2Pub/PostService.hs @@ -19,6 +19,7 @@ import Control.Exception (Exception (..), try) import Control.Monad (foldM, forM, forM_, forever) import Control.Monad.IO.Class (liftIO) import Control.Monad.STM +import Data.Bifunctor import qualified Data.ByteString.Lazy.UTF8 as BSUL import qualified Data.ByteString.UTF8 as BSU import qualified Data.HashMap.Strict as HMap @@ -409,6 +410,20 @@ clientUnsubscribeFrom serv tag = do lookupResponse +-- | publish a new post to the inbox of a specified relay instance. This +-- instance will then be the originating instance of the post and will forward +-- the post to the responsible relays. +-- As the initial publishing isn't done by a specific relay (but *to* a specific relay +-- instead), the function does *not* take a PostService as argument. +clientPublishPost :: HTTP.Manager -- for better performance, a shared HTTP manager has to be provided + -> String -- hostname + -> Int -- port + -> PostContent -- post content + -> IO (Either String ()) -- error or success +clientPublishPost httpman hostname port postC = do + resp <- runClientM (postInboxClient postC) (mkClientEnv httpman (BaseUrl Http hostname port "")) + pure . bimap show (const ()) $ resp + -- currently this is unused code getClients :: String -> Int -> HTTP.Manager -> Client IO PostServiceAPI getClients hostname' port' httpMan = hoistClient clientAPI