From c7976168e822f59e46ceb47befccc94d39db528a Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 31 May 2022 12:34:35 +1000 Subject: Adding support to multiple maildirs --- src/F2Md/Config.hs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'src/F2Md/Config.hs') 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 . 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 -- cgit v1.2.3