By | Chris Done |
At | 2013-07-20 |
Title | More RSS tweaks. |
Description |
Edit file src/Hpaste/Model/Paste.hs 33188 → 33188
63 63 getLatestPastes :: Maybe ChannelId -> HPModel [Paste]
64 64 getLatestPastes channel =
65 65 query ["SELECT ",pasteFields
66 66 ,"FROM public_toplevel_paste"
67 67 ,"WHERE spamrating < ?"
- 68 ,"AND channel = ?"
+ 68 ,"AND channel = ? or ? is null"
69 69 ,"ORDER BY created DESC"
70 70 ,"LIMIT 20"]
- 71 (spamMinLevel,channel)
+ 71 (spamMinLevel,channel,channel)
72 72 73 73 -- | Get some paginated pastes.
74 74 getPaginatedPastes :: Maybe String -> Pagination -> HPModel (Pagination,[Paste])
75 75 getPaginatedPastes mauthor pn@Pagination{..} = do
76 76 total <- countPublicPastes mauthor
… … … … Add file src/Hpaste/Controller/Rss.hs 33188
+ 1 {-# LANGUAGE OverloadedStrings #-} + 2 {-# LANGUAGE RecordWildCards #-} + 3 + 4 -- | An RSS feed of recent pastes. + 5 + 6 module Hpaste.Controller.Rss where + 7 + 8 import Hpaste.Model.Paste + 9 import Hpaste.Model.Channel + 10 import Hpaste.Types + 11 + 12 import Control.Applicative + 13 import Control.Monad + 14 import Data.List + 15 import Data.Monoid + 16 import Data.String.ToString + 17 import qualified Data.Text as T + 18 import Data.Text.Encoding + 19 import Safe + 20 import Snap.App + 21 import Snap.App.RSS + 22 + 23 handle :: HPCtrl () + 24 handle = do + 25 cid <- getChannelId + 26 case cid of + 27 Nothing -> error "need a channel" + 28 Just cid' -> do + 29 pastes <- model $ getLatestPastes cid + 30 outputRSS "#haskell pastes" + 31 "http://lpaste.net/channel/haskell.rss" + 32 (map (\Paste{..} -> (pasteDate,pasteTitle,pastePaste, T.pack $ + 33 "http://lpaste.net/" ++ show pasteId)) + 34 pastes) + 35 + 36 getChannelId :: HPCtrl (Maybe ChannelId) + 37 getChannelId = do + 38 chname <- fmap (fmap decodeUtf8) $ getParam "channel" + 39 case chname of + 40 Nothing -> return Nothing + 41 Just chname -> do + 42 channels <- model $ getChannels + 43 case find ((==("#" <> chname)) . channelName) channels of + 44 Nothing -> return Nothing + 45 Just Channel{..} -> return (return channelId)