module MainHelper ( CallHistory(..) , newUniqueCallHistory ) where import qualified Data.Sequence as S import Data.Text.Lazy (Text) import Lib (boundedPushRight) -- in RAM call history for most recent 10 calls. data CallHistory = CallHistory { chTime :: Text , chClientIP :: Text , chUserAgent :: Text } deriving (Show, Eq) -- | insert a new unique call history, return a new unique call history Seq. newUniqueCallHistory :: S.Seq CallHistory -> Int -> CallHistory -> S.Seq CallHistory newUniqueCallHistory oldSeq historySize newEntry = case S.findIndexR (\entry -> chClientIP entry == chClientIP newEntry) oldSeq of Just index -> S.deleteAt index oldSeq S.|> newEntry Nothing -> boundedPushRight oldSeq historySize newEntry