aboutsummaryrefslogtreecommitdiff
path: root/src/F2Md/Config.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/F2Md/Config.hs')
-rw-r--r--src/F2Md/Config.hs35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/F2Md/Config.hs b/src/F2Md/Config.hs
index c17a55f..5832981 100644
--- a/src/F2Md/Config.hs
+++ b/src/F2Md/Config.hs
@@ -23,6 +23,7 @@ License along with f2md. If not, see <https://www.gnu.org/licenses/>.
module F2Md.Config
( getUserdata
, FeedUserdata(..)
+ , ExtConf(..)
, updateLastUpdated
) where
@@ -50,21 +51,27 @@ data FeedUserdata = FeedUserdata
{ fuUrl :: Text
, fuLastUpdated :: Maybe ZonedTime } deriving (Show)
-getUserdata :: FilePath -> IO ([FeedUserdata], Maybe FilePath, Maybe FilePath)
-getUserdata file = do
- config <- decodeFileStrict =<< expandPath file
- case config of
- Nothing -> return ([], Nothing, Nothing)
- Just config' -> do
- feedData <- getUserdata' config'
- maildir' <- expandPath $ maildir config'
- dbPath' <- expandPath $ dbPath config'
- return (feedData, Just maildir', Just dbPath')
-
-getUserdata' :: Config -> IO [FeedUserdata]
-getUserdata' (Config dbPath _ feeds) = do
+data ExtConf = ExtConf
+ { eDbPath :: FilePath
+ , eMaildir :: FilePath
+ , eFeeds :: [FeedUserdata]
+ }
+
+getUserdata :: FilePath -> IO [ExtConf]
+getUserdata confPath = do
+ configs <- decodeFileStrict =<< expandPath confPath
+ case configs of
+ Nothing -> return []
+ Just configs' -> mapM getUserdata' configs'
+
+getUserdata' :: Config -> IO ExtConf
+getUserdata' (Config dbPath maildir feeds) = do
decoded <- getLastUpdatedMap dbPath
- return $ map (\url -> FeedUserdata url $ HM.lookup url decoded) feeds
+ dbPath' <- expandPath dbPath
+ maildir' <- expandPath maildir
+ return $
+ ExtConf dbPath' maildir'
+ (map (\url -> FeedUserdata url $ HM.lookup url decoded) feeds)
getLastUpdatedMap :: FilePath -> IO (HM.HashMap Text ZonedTime)
getLastUpdatedMap dbPath = do