diff options
author | Yuchen Pei <hi@ypei.me> | 2022-05-31 12:34:35 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-05-31 12:34:35 +1000 |
commit | c7976168e822f59e46ceb47befccc94d39db528a (patch) | |
tree | 2ef394dacd7c90d944994b8434ee89d5890b8432 /src/F2Md/Config.hs | |
parent | 08fc677a8db69259c3c91070b6a63ac46f93667e (diff) |
Adding support to multiple maildirs
Diffstat (limited to 'src/F2Md/Config.hs')
-rw-r--r-- | src/F2Md/Config.hs | 35 |
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 |