+-- | Display the number of skipped retweets if ignore_retweets is true
+-- and verbose is enabled.
+mention_retweets :: Cfg -> [Status] -> IO ()
+mention_retweets cfg ss = do
+ let retweets = filter retweet ss
+ when ((ignore_retweets cfg) && (verbose cfg)) $ do
+ let countstr = show $ length retweets
+ putStrLn $ "Ignoring " ++ countstr ++ " retweets."
+
+
+
+-- | Filter out replies/retweets based on the configuration.
+filter_statuses :: Cfg -> [Status] -> [Status]
+filter_statuses cfg ss =
+ good_statuses
+ where
+ replies = filter reply ss
+ retweets = filter retweet ss
+
+ good_statuses' = case (ignore_replies cfg) of
+ True -> ss \\ replies
+ False -> ss
+
+ good_statuses = case (ignore_retweets cfg) of
+ True -> good_statuses' \\ retweets
+ False -> good_statuses'
+
+
+
+-- | This is the main recursive loop. It takes a the configuration, a
+-- username, a latest_status_id, and optionally a 'Message' as
+-- arguments. The latest_status_id is the last status (that we know
+-- of) to be posted to username's Twitter account. If we find any
+-- newer statuses when we check, they are printed and optionally
+-- emailed (if a 'Message' was supplied). Then, the process repeats.
+recurse :: Cfg -> String -> Integer -> (Maybe Message) -> IO ()
+recurse cfg username latest_status_id maybe_message = do
+ thread_sleep (heartbeat cfg)
+ xmldata <- get_user_new_statuses username latest_status_id
+
+ -- Parsing an empty result can blow up. Just pretend there are
+ -- no new statuses in that case.
+ let new_statuses = case xmldata of
+ Just xml -> parse_statuses xml
+ Nothing -> []
+
+ case (length new_statuses) of
+ 0 ->
+ do_recurse latest_status_id
+ _ -> do
+
+ mention_replies cfg new_statuses
+ mention_retweets cfg new_statuses
+
+ let good_statuses = filter_statuses cfg new_statuses