-thread_sleep microseconds = do
- let seconds = microseconds * (10 ^ (6 :: Int))
- threadDelay seconds
-
-
-message_from_status :: Message -> Status -> Message
-message_from_status message status =
- message { subject = "Twat: " ++ (screen_name (user status)),
- body = (pretty_print status) }
-
-recurse :: String -> Integer -> (Maybe Message) -> IO ()
-recurse username latest_status_id maybe_message = do
- thread_sleep heartbeat
+thread_sleep seconds = do
+ let microseconds = seconds * (10 ^ (6 :: Int))
+ threadDelay microseconds
+
+
+-- |Given a 'Message', 'Status', and default date, update that
+-- message's body and subject with the information contained in the
+-- status. Adds a /Date: / header, and returns the updated message.
+message_from_status :: Message -> String -> Status -> Message
+message_from_status message default_date status =
+ message { subject = "Twat: " ++ (screen_name (user status)),
+ body = (pretty_print status),
+ headers = ((headers message) ++ ["Date: " ++ date])}
+ where
+ -- Use the Status' created_at date if it can be coerced into
+ -- RFC822 format.
+ date = case (created_at_to_rfc822 $ created_at status) of
+ Nothing -> default_date
+ Just c -> c
+
+-- |This is the main recursive loop. It takes a length of time to
+-- delay (in seconds), 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 :: Int -> String -> Integer -> (Maybe Message) -> IO ()
+recurse delay username latest_status_id maybe_message = do
+ thread_sleep delay